70 lines
1.8 KiB
Docker
70 lines
1.8 KiB
Docker
##### Builder ####
|
|
FROM rust:1.62-slim-bullseye as builder
|
|
|
|
RUN apt-get update && apt-get -y upgrade
|
|
RUN apt-get -y install --no-install-recommends sqlite3 libsqlite3-dev npm && rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /usr/src
|
|
|
|
# Create blank project
|
|
RUN USER=root cargo new --bin huellas
|
|
|
|
# We want dependencies cached, so copy those first.
|
|
COPY Cargo.toml Cargo.lock /usr/src/huellas/
|
|
|
|
# Set the working directory
|
|
WORKDIR /usr/src/huellas
|
|
|
|
# This is an empty build to get the dependencies cached.
|
|
RUN cargo build --release
|
|
|
|
# Install typescript dependencies
|
|
WORKDIR /usr/src/huellas/ts-client/
|
|
RUN npm install
|
|
|
|
# Install Typescript
|
|
RUN npm install -g typescript
|
|
|
|
# Set the working directory
|
|
WORKDIR /usr/src/huellas
|
|
|
|
# Now copy in the rest of the sources
|
|
COPY src /usr/src/huellas/src/
|
|
COPY migrations /usr/src/huellas/migrations/
|
|
COPY db /usr/src/huellas/db/
|
|
COPY .env sqlx-data.json Rocket.toml /usr/src/huellas/
|
|
|
|
## Touch main.rs to prevent cached release build
|
|
RUN touch /usr/src/huellas/src/main.rs
|
|
|
|
# This is the actual application build.
|
|
RUN cargo build --release
|
|
|
|
# Now TS client
|
|
COPY ts-client /usr/src/huellas/ts-client/
|
|
|
|
# Set the working directory
|
|
WORKDIR /usr/src/huellas/ts-client/
|
|
|
|
# Transpile
|
|
RUN tsc
|
|
|
|
################
|
|
##### Runtime
|
|
FROM debian:bullseye-slim AS runtime
|
|
|
|
RUN apt-get update && apt-get -y upgrade
|
|
RUN apt-get -y install --no-install-recommends sqlite3 && rm -rf /var/lib/apt/lists/*
|
|
# Copy application binary from builder image
|
|
COPY --from=builder /usr/src/huellas/target/release/huellas /usr/local/bin
|
|
|
|
# Copy static files
|
|
COPY static /usr/local/bin/static/
|
|
# Copy javascript client
|
|
COPY --from=builder /usr/src/huellas/ts-client/build/client.js /usr/local/bin/static
|
|
# Delete the first line of jvascript ts-client
|
|
RUN sed -i '1d' /usr/local/bin/static/client.js
|
|
|
|
# Run the application
|
|
WORKDIR /usr/local/bin
|
|
CMD ["/usr/local/bin/huellas"]
|