diff --git a/Dockerfile.template b/Dockerfile.template index d5d1665..dd5c543 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -1,38 +1,34 @@ # Build stage -FROM rust:1.79-slim AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -# Install build dependencies -RUN apt-get update && apt-get install -y \ - pkg-config \ - libsqlite3-dev \ - && rm -rf /var/lib/apt/lists/* +# Install build dependencies and musl target +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && \ + rustup target add x86_64-unknown-linux-musl # Copy manifests -COPY Cargo.toml ./ +COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -# Build the application (release mode for smaller binary) -RUN cargo build --release --bin ${BIN_NAME} +# Build static binary with musl target +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin ${BIN_NAME} --target x86_64-unknown-linux-musl -# Runtime stage -FROM debian:trixie-slim AS runtime +# Runtime stage - minimal Alpine +FROM alpine:latest AS runtime -# Install runtime dependencies -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libsqlite3-0 \ - && rm -rf /var/lib/apt/lists/* +# Install CA certificates only +RUN apk add --no-cache ca-certificates # Create app user -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -# Copy binary from builder -COPY --from=builder /usr/src/app/target/release/${BIN_NAME} ./${BIN_NAME} +# Copy static binary from builder +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/${BIN_NAME} ./${BIN_NAME} # Switch to non-root user USER appuser diff --git a/apps/catering_services/Dockerfile b/apps/catering_services/Dockerfile index acbdead..f14e077 100644 --- a/apps/catering_services/Dockerfile +++ b/apps/catering_services/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin catering_services +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin catering_services --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/catering_services ./catering_services +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/catering_services ./catering_services USER appuser diff --git a/apps/companies/Dockerfile b/apps/companies/Dockerfile index 8c2a8ed..021d781 100644 --- a/apps/companies/Dockerfile +++ b/apps/companies/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin companies +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin companies --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/companies ./companies +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/companies ./companies USER appuser diff --git a/apps/cron/Dockerfile b/apps/cron/Dockerfile index 7e8e179..33d97f5 100644 --- a/apps/cron/Dockerfile +++ b/apps/cron/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin cron +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin cron --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/cron ./cron +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/cron ./cron USER appuser diff --git a/apps/customers/Dockerfile b/apps/customers/Dockerfile index a3e27be..6e12467 100644 --- a/apps/customers/Dockerfile +++ b/apps/customers/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin customers +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin customers --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/customers ./customers +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/customers ./customers USER appuser diff --git a/apps/developers/Dockerfile b/apps/developers/Dockerfile index cbcbd3b..b95377b 100644 --- a/apps/developers/Dockerfile +++ b/apps/developers/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin developers +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin developers --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/developers ./developers +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/developers ./developers USER appuser diff --git a/apps/employees/Dockerfile b/apps/employees/Dockerfile index 722e655..fe72116 100644 --- a/apps/employees/Dockerfile +++ b/apps/employees/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin employees +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin employees --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/employees ./employees +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/employees ./employees USER appuser diff --git a/apps/fitness_trainers/Dockerfile b/apps/fitness_trainers/Dockerfile index 6ede508..29ff79f 100644 --- a/apps/fitness_trainers/Dockerfile +++ b/apps/fitness_trainers/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin fitness_trainers +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin fitness_trainers --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/fitness_trainers ./fitness_trainers +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/fitness_trainers ./fitness_trainers USER appuser diff --git a/apps/gateway/Dockerfile b/apps/gateway/Dockerfile index ba508f5..2aaf0a5 100644 --- a/apps/gateway/Dockerfile +++ b/apps/gateway/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin gateway +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin gateway --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/gateway ./gateway +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/gateway ./gateway USER appuser diff --git a/apps/graphic_designers/Dockerfile b/apps/graphic_designers/Dockerfile index 730070f..3d9d4c2 100644 --- a/apps/graphic_designers/Dockerfile +++ b/apps/graphic_designers/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin graphic_designers +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin graphic_designers --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/graphic_designers ./graphic_designers +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/graphic_designers ./graphic_designers USER appuser diff --git a/apps/job_seekers/Dockerfile b/apps/job_seekers/Dockerfile index dc03e45..d62b7c7 100644 --- a/apps/job_seekers/Dockerfile +++ b/apps/job_seekers/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin job_seekers +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin job_seekers --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/job_seekers ./job_seekers +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/job_seekers ./job_seekers USER appuser diff --git a/apps/makeup_artists/Dockerfile b/apps/makeup_artists/Dockerfile index 288a8f8..451a7b5 100644 --- a/apps/makeup_artists/Dockerfile +++ b/apps/makeup_artists/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin makeup_artists +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin makeup_artists --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/makeup_artists ./makeup_artists +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/makeup_artists ./makeup_artists USER appuser diff --git a/apps/payments/Dockerfile b/apps/payments/Dockerfile index 39c6f9d..5ce8379 100644 --- a/apps/payments/Dockerfile +++ b/apps/payments/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin payments +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin payments --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/payments ./payments +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/payments ./payments USER appuser diff --git a/apps/photographers/Dockerfile b/apps/photographers/Dockerfile index 548deec..5962afb 100644 --- a/apps/photographers/Dockerfile +++ b/apps/photographers/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin photographers +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin photographers --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/photographers ./photographers +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/photographers ./photographers USER appuser diff --git a/apps/social_media_managers/Dockerfile b/apps/social_media_managers/Dockerfile index 8232de7..974ece1 100644 --- a/apps/social_media_managers/Dockerfile +++ b/apps/social_media_managers/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin social_media_managers +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin social_media_managers --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/social_media_managers ./social_media_managers +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/social_media_managers ./social_media_managers USER appuser diff --git a/apps/tutors/Dockerfile b/apps/tutors/Dockerfile index fc0441d..c5063d1 100644 --- a/apps/tutors/Dockerfile +++ b/apps/tutors/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin tutors +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin tutors --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/tutors ./tutors +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/tutors ./tutors USER appuser diff --git a/apps/ugc_content_creators/Dockerfile b/apps/ugc_content_creators/Dockerfile index 1e8a8b0..7e30ad9 100644 --- a/apps/ugc_content_creators/Dockerfile +++ b/apps/ugc_content_creators/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin ugc_content_creators +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin ugc_content_creators --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/ugc_content_creators ./ugc_content_creators +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/ugc_content_creators ./ugc_content_creators USER appuser diff --git a/apps/users/Dockerfile b/apps/users/Dockerfile index a8c2889..ddcda6b 100644 --- a/apps/users/Dockerfile +++ b/apps/users/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin users +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin users --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/users ./users +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/users ./users USER appuser diff --git a/apps/video_editors/Dockerfile b/apps/video_editors/Dockerfile index 95bf5dd..3a0beb7 100644 --- a/apps/video_editors/Dockerfile +++ b/apps/video_editors/Dockerfile @@ -1,30 +1,24 @@ -FROM rust:latest AS builder +FROM rust:alpine AS builder WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y \ - pkg-config \ - libssl-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache musl-dev pkgconfig openssl-dev && rustup target add x86_64-unknown-linux-musl COPY Cargo.toml Cargo.lock ./ COPY crates ./crates COPY apps ./apps -ENV CARGO_BUILD_JOBS=2 -RUN cargo build --release --bin video_editors +ENV RUSTFLAGS='-C target-feature=+crt-static' +RUN cargo build --release --bin video_editors --target x86_64-unknown-linux-musl -FROM debian:trixie-slim AS runtime +FROM alpine:latest AS runtime -RUN apt-get update && apt-get install -y \ - ca-certificates \ - libssl3 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates -RUN useradd -m -u 1000 appuser +RUN adduser -D -u 1000 appuser WORKDIR /app -COPY --from=builder /usr/src/app/target/release/video_editors ./video_editors +COPY --from=builder /usr/src/app/target/x86_64-unknown-linux-musl/release/video_editors ./video_editors USER appuser