Dockerfile (1221B)
1 # Multi-stage Dockerfile for Orders Service 2 # Build from app directory: docker build -t orders-service -f orders/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 orders ./orders 16 COPY products ./products 17 COPY otelmart ./otelmart 18 COPY inventory ./inventory 19 20 # Build the application 21 WORKDIR /build/orders 22 RUN cargo build --release --bin orders 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 orders && \ 32 adduser -D -u 1000 -G orders orders 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/orders /app/orders 39 40 # Copy configuration (use docker config) 41 COPY --from=builder /build/orders/config.docker.toml /app/config.toml 42 43 # Change ownership 44 RUN chown -R orders:orders /app 45 46 # Switch to non-root user 47 USER orders 48 49 # Expose port 50 EXPOSE 3003 51 52 # Run the application 53 CMD ["/app/orders"]