Dockerfile (1251B)
1 # Multi-stage Dockerfile for Products Service 2 # Build from app directory: docker build -t products-service -f products/Dockerfile . 3 4 # Stage 1: Build stage 5 FROM rust:alpine AS builder 6 7 # Install build dependencies 8 RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static pkgconfig 9 10 # Set working directory 11 WORKDIR /build 12 13 # Copy workspace files 14 COPY Cargo.toml Cargo.lock ./ 15 COPY products ./products 16 COPY otelmart ./otelmart 17 COPY inventory ./inventory 18 COPY orders ./orders 19 20 # Build the application 21 WORKDIR /build/products 22 RUN cargo build --release --bin products 23 24 # Stage 2: Runtime stage 25 FROM alpine:latest 26 27 # Install runtime dependencies 28 RUN apk add --no-cache ca-certificates libgcc wget 29 30 # Create non-root user 31 RUN addgroup -g 1000 products && \ 32 adduser -D -u 1000 -G products products 33 34 # Set working directory 35 WORKDIR /app 36 37 # Copy binary from builder (workspace builds to /build/target) 38 COPY --from=builder /build/target/release/products /app/products 39 40 # Copy configuration (use docker config) 41 COPY --from=builder /build/products/config.docker.toml /app/config.toml 42 43 # Change ownership 44 RUN chown -R products:products /app 45 46 # Switch to non-root user 47 USER products 48 49 # Expose port 50 EXPOSE 3001 51 52 # Run the application 53 CMD ["/app/products"]