Added multi stage builds for OCI containers #2

Open
wymiller wants to merge 1 commits from multi-stage-dockerfiles into master
2 changed files with 31 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
FROM rust:1.88.0 # Build stage
FROM rust:1.88.0 AS builder
WORKDIR /app WORKDIR /app
@@ -7,6 +8,16 @@ COPY ./cache ./cache
RUN cargo build --release --manifest-path ./public/Cargo.toml RUN cargo build --release --manifest-path ./public/Cargo.toml
# Runtime stage with Alpine
FROM alpine:latest
WORKDIR /app
RUN apk add --no-cache ca-certificates libgcc
COPY --from=builder /app/public/target/release/public /app/public
COPY --from=builder /app/cache ./cache
EXPOSE 3000 EXPOSE 3000
CMD ["/app/public/target/release/public"] CMD ["/app/public"]

View File

@@ -1,4 +1,5 @@
FROM rust:1.88.0 # Build stage
FROM rust:1.88.0 AS builder
WORKDIR /app WORKDIR /app
@@ -6,9 +7,23 @@ COPY ./task ./task
COPY ./cache ./cache COPY ./cache ./cache
COPY ./storage ./storage COPY ./storage ./storage
RUN mkdir /app/posts
RUN cargo build --release --manifest-path ./task/Cargo.toml RUN cargo build --release --manifest-path ./task/Cargo.toml
# Runtime stage
FROM debian:bookworm-slim
WORKDIR /app
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /app/posts
COPY --from=builder /app/task/target/release/task /app/task
COPY --from=builder /app/cache ./cache
COPY --from=builder /app/storage ./storage
EXPOSE 3000 EXPOSE 3000
CMD ["/app/task/target/release/task"] CMD ["/app/task"]