11# syntax=docker/dockerfile:1
22
3- # ###############################################################################
4- # Create a stage for building the application.
5-
6- ARG RUST_VERSION=latest
3+ ARG RUST_VERSION=1.84
74ARG APP_NAME=rsomhap
85
6+ # ###############################################################################
7+ # Build stage
8+
99FROM rust:${RUST_VERSION} AS builder
1010ARG APP_NAME
11-
1211WORKDIR /usr/src/app
1312
14- # Build the application.
15- # Leverage a cache mount to /usr/local/cargo/registry/
16- # for downloaded dependencies and a cache mount to /app/target/ for
17- # compiled dependencies which will speed up subsequent builds.
18- # Once built, copy the executable to an output directory before
19- # the cache mounted /app/target is unmounted.
20- COPY Cargo.toml ./
13+ COPY Cargo.toml Cargo.lock ./
2114COPY src ./src
15+
2216RUN --mount=type=cache,target=/usr/src/app/target \
2317 --mount=type=cache,target=/usr/local/cargo/registry \
24- cargo build --release --bin ${APP_NAME} && cp ./target/release/${APP_NAME} ./${APP_NAME}
18+ cargo build --release --locked --bin ${APP_NAME} \
19+ && cp ./target/release/${APP_NAME} ./${APP_NAME}
2520
2621# ###############################################################################
27- # Create a new stage for running the application that contains the minimal
28- # runtime dependencies for the application. This often uses a different base
29- # image from the build stage where the necessary files are copied from the build
30- # stage.
22+ # Runtime stage
3123
3224FROM debian:bookworm-slim AS final
3325ARG APP_NAME
3426
27+ RUN apt-get update \
28+ && apt-get install -y --no-install-recommends ca-certificates curl \
29+ && rm -rf /var/lib/apt/lists/*
30+
3531WORKDIR /usr/src/app
3632
37- # Create a non-privileged user that the app will run under.
38- # See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
3933ARG UID=10001
4034RUN adduser \
4135 --disabled-password \
@@ -45,18 +39,17 @@ RUN adduser \
4539 --no-create-home \
4640 --uid "${UID}" \
4741 appuser
48- USER appuser
4942
50- # Copy the executable from the " build" stage.
51- COPY --from=builder /usr/src/app/${APP_NAME} .
43+ # Copy the executable from the build stage.
44+ COPY --from=builder --chown=appuser:appuser /usr/src/app/${APP_NAME} .
5245
5346# Copy the necessary files.
54- COPY templates ./templates
55- COPY static ./static
56- COPY config.toml ./
47+ COPY --chown=appuser:appuser templates ./templates
48+ COPY --chown=appuser:appuser static ./static
49+ COPY --chown=appuser:appuser config.toml ./
50+
51+ USER appuser
5752
58- # Expose the port that the application listens on.
5953EXPOSE 5299
6054
61- # What the container should run when it is started.
6255CMD ["./rsomhap" ]
0 commit comments