1b300865d9
- Create multi-stage Dockerfile with cargo-chef optimization - Add .dockerignore to exclude unnecessary files from build context - Include protobuf compiler and development dependencies in builder stage - Set up proper user permissions and health check - Configure release build with strip for smaller image size - Add curl dependency for health check functionality
40 lines
1.0 KiB
Docker
40 lines
1.0 KiB
Docker
FROM rust:1.96-bookworm AS chef
|
|
RUN apt-get update && \
|
|
apt-get install -y --no-install-recommends \
|
|
protobuf-compiler libprotobuf-dev mold clang && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
RUN cargo install cargo-chef
|
|
WORKDIR /app
|
|
|
|
FROM chef AS planner
|
|
COPY . .
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
FROM chef AS builder
|
|
COPY --from=planner /app/recipe.json recipe.json
|
|
RUN cargo chef cook --release --recipe-path recipe.json
|
|
COPY . .
|
|
RUN cargo build --release --bin imks && \
|
|
strip target/release/imks
|
|
|
|
FROM ubuntu:26.04
|
|
|
|
RUN apt-get update && \
|
|
apt-get install -y --no-install-recommends ca-certificates curl && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY --from=builder /app/target/release/imks /usr/local/bin/imks
|
|
COPY --from=builder /app/migrate/ /app/migrate/
|
|
|
|
WORKDIR /app
|
|
|
|
RUN useradd -m -u 1000 imks && chown -R imks:imks /app
|
|
USER imks
|
|
|
|
EXPOSE 3000
|
|
|
|
HEALTHCHECK --interval=15s --timeout=3s --start-period=10s --retries=3 \
|
|
CMD curl -sf http://localhost:3000/health || exit 1
|
|
|
|
ENTRYPOINT ["imks"]
|