Dockerfile
1 FROM rust:1.75 as base 2 3 ENV TZ=Europe/Stockholm 4 ENV DEBIAN_FRONTEND=noninteractive 5 RUN apt update && apt install -y tzdata 6 7 WORKDIR /app 8 9 # Install required tools 10 RUN cargo install sqlx-cli --version 0.7.3 11 RUN cargo install strip_cargo_version 12 13 # Install build-target for static linking 14 RUN rustup target add x86_64-unknown-linux-musl 15 16 # Required by `brotli-sys` and `openssl` 17 RUN apt-get update && apt-get install -y musl-tools pkg-config libssl-dev 18 19 20 21 FROM base as strip-version 22 23 # Strip version from Cargo.* 24 # This avoids cache invalidations (rebuilding all deps) when bumping the version number 25 COPY Cargo.toml Cargo.lock ./ 26 RUN strip_cargo_version 27 28 29 30 FROM base as build 31 32 # Create a dummy binary for pre-compiling dependencies (for caching) 33 RUN cargo init --bin 34 COPY --from=strip-version /app/Cargo.* ./ 35 RUN cargo build --release --target x86_64-unknown-linux-musl 36 37 # Copy the actual source files 38 COPY . . 39 40 # Compile the final binary 41 RUN rustup target add x86_64-unknown-linux-musl 42 RUN SQLX_OFFLINE=true cargo build --release --target x86_64-unknown-linux-musl 43 RUN strip target/x86_64-unknown-linux-musl/release/accounts_rs 44 45 FROM scratch 46 WORKDIR / 47 48 ENV PORT=8080 49 EXPOSE 8080 50 51 COPY --from=build /app/target/x86_64-unknown-linux-musl/release/accounts_rs ./accounts_rs 52 COPY --from=build /app/static ./static 53 COPY --from=build /app/templates ./templates 54 COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ 55 56 CMD ["./accounts_rs"]