exercises

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

Dockerfile (1266B)


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