-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (36 loc) · 1.37 KB
/
Copy pathDockerfile
File metadata and controls
47 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Instructions coming from
# https://github.com/LukeMathWalker/cargo-chef?tab=readme-ov-file#without-the-pre-built-image
FROM rust:1.85 AS chef
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
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
ARG FEATURES=logging
RUN cargo build --release --bin flagpole --features=$FEATURES
# We do not need the Rust toolchain to run the binary!
FROM debian:stable-slim@sha256:4448d44b91bf4a13cb1b4e02d9d5f87ed40621d6e33f0ae7b6ddf71d57e29364 AS runtime
# Create non-root user and group
RUN groupadd -r flagpole && \
useradd -r -g flagpole -s /sbin/nologin flagpole
WORKDIR /app
# Copy binary with appropriate ownership
COPY --from=builder --chown=flagpole:flagpole /app/target/release/flagpole /usr/local/bin/flagpole
# Add metadata labels
LABEL org.opencontainers.image.source="https://github.com/mantono/flagpole"
LABEL org.opencontainers.image.description="Flagpole - Feature flag service"
LABEL org.opencontainers.image.vendor="mantono"
ENV HOST=0.0.0.0
ENV PORT=3000
ENV LOG_LEVEL=INFO
# Document the port the service uses
EXPOSE 3000
# Switch to non-root user
USER flagpole
ENTRYPOINT ["/usr/local/bin/flagpole"]