2022-08-01 21:55:03 -04:00
|
|
|
##### Builder ####
|
2023-11-10 00:05:47 -03:00
|
|
|
FROM rust:1.73-alpine as builder
|
2022-08-01 21:55:03 -04:00
|
|
|
|
2023-05-22 22:59:58 -04:00
|
|
|
# Install dependencies
|
|
|
|
|
RUN apk add --no-cache sqlite npm musl-dev fd minify && npm install -g typescript
|
2022-08-01 21:55:03 -04:00
|
|
|
|
|
|
|
|
WORKDIR /usr/src
|
|
|
|
|
|
|
|
|
|
# Create blank project
|
2022-08-02 16:14:56 -04:00
|
|
|
RUN USER=root cargo new --bin huellas
|
2022-08-01 21:55:03 -04:00
|
|
|
|
|
|
|
|
# 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.
|
2022-08-02 16:14:56 -04:00
|
|
|
RUN cargo build --release
|
2022-08-01 21:55:03 -04:00
|
|
|
|
|
|
|
|
# Now copy in the rest of the sources
|
|
|
|
|
COPY src /usr/src/huellas/src/
|
2022-08-02 16:14:56 -04:00
|
|
|
COPY migrations /usr/src/huellas/migrations/
|
|
|
|
|
COPY db /usr/src/huellas/db/
|
2023-05-22 22:59:58 -04:00
|
|
|
COPY .env /usr/src/huellas/
|
2022-08-01 21:55:03 -04:00
|
|
|
|
2023-11-10 00:05:47 -03:00
|
|
|
## Touch main.rs to prevent cached release build and then build
|
|
|
|
|
RUN touch /usr/src/huellas/src/main.rs && cargo build --release
|
2022-08-01 21:55:03 -04:00
|
|
|
|
|
|
|
|
# Now TS client
|
|
|
|
|
COPY ts-client /usr/src/huellas/ts-client/
|
|
|
|
|
|
|
|
|
|
# Set the working directory
|
|
|
|
|
WORKDIR /usr/src/huellas/ts-client/
|
|
|
|
|
|
2022-08-03 22:58:18 -04:00
|
|
|
# Install dependencies
|
2023-11-10 00:05:47 -03:00
|
|
|
RUN npm ci
|
2022-08-01 21:55:03 -04:00
|
|
|
|
2023-11-10 00:05:47 -03:00
|
|
|
# Transpile and delete the first line of jvascript ts-client
|
2023-11-10 15:05:09 -03:00
|
|
|
RUN tsc && sed -i '1d' build/client.js
|
2022-10-22 16:24:05 -03:00
|
|
|
|
2023-02-28 01:25:34 -03:00
|
|
|
# Minify static files
|
|
|
|
|
COPY static /usr/src/huellas/static/
|
2023-11-10 00:05:47 -03:00
|
|
|
RUN fd -e html . '/usr/src/huellas/static/' -x minify -r -o {} {} \
|
|
|
|
|
&& fd -e js . '/usr/src/huellas/ts-client/build/' -x minify -r -o {} {}
|
2023-02-28 01:25:34 -03:00
|
|
|
|
2022-08-01 21:55:03 -04:00
|
|
|
################
|
|
|
|
|
##### Runtime
|
2023-11-10 00:05:47 -03:00
|
|
|
FROM alpine:3.18 AS Runtime
|
2022-10-22 16:24:05 -03:00
|
|
|
|
|
|
|
|
RUN apk add --no-cache sqlite
|
2022-08-01 21:55:03 -04:00
|
|
|
|
|
|
|
|
# Copy application binary from builder image
|
2022-08-02 16:14:56 -04:00
|
|
|
COPY --from=builder /usr/src/huellas/target/release/huellas /usr/local/bin
|
2023-06-08 22:06:05 -04:00
|
|
|
# Copy .env
|
|
|
|
|
COPY .env /usr/local/bin
|
2022-08-01 21:55:03 -04:00
|
|
|
# Copy static files
|
2023-02-28 01:25:34 -03:00
|
|
|
COPY --from=builder /usr/src/huellas/static /usr/local/bin/static/
|
2022-08-01 21:55:03 -04:00
|
|
|
# Copy javascript client
|
|
|
|
|
COPY --from=builder /usr/src/huellas/ts-client/build/client.js /usr/local/bin/static
|
|
|
|
|
|
|
|
|
|
# Run the application
|
2022-08-03 22:52:30 -04:00
|
|
|
WORKDIR /usr/local/bin
|
2022-08-01 21:55:03 -04:00
|
|
|
CMD ["/usr/local/bin/huellas"]
|