huellas/Dockerfile
2022-10-22 16:24:05 -03:00

68 lines
1.6 KiB
Docker

##### Builder ####
FROM rust:1.64-alpine as builder
RUN apk add --no-cache sqlite npm musl-dev
# Install Typescript
RUN npm install -g typescript
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
# 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/
# Install dependencies
RUN npm install
# Transpile
RUN tsc
# Delete the first line of jvascript ts-client
RUN sed -i '1d' build/client.js
################
##### Runtime
FROM alpine:3.16 AS Runtime
RUN apk add --no-cache sqlite
# Copy application binary from builder image
COPY --from=builder /usr/src/huellas/target/release/huellas /usr/local/bin
# Copy Rocket.toml
COPY Rocket.toml /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
# Run the application
WORKDIR /usr/local/bin
CMD ["/usr/local/bin/huellas"]