Dockerfile (2343B)
1 # ============================================================ 2 # Multi-stage Dockerfile for OtelMart Service + Angular Client 3 # ============================================================ 4 5 # Stage 1: Build Angular Client 6 FROM node:20-alpine AS client-builder 7 8 WORKDIR /app/client 9 10 # Copy client package files 11 COPY client/package*.json ./ 12 13 # Install dependencies 14 RUN npm ci 15 16 # Copy client source 17 COPY client/ ./ 18 19 # Build Angular app for production 20 RUN npm run build --configuration=production && \ 21 ls -la dist/ || echo "No dist directory" && \ 22 ls -la dist/*/browser || echo "No browser directory found" 23 24 # Stage 2: Build Rust OtelMart Service 25 FROM rust:1-bookworm AS rust-builder 26 27 WORKDIR /app 28 29 # Install build dependencies 30 RUN apt-get update && \ 31 apt-get install -y pkg-config libssl-dev && \ 32 rm -rf /var/lib/apt/lists/* 33 34 # Copy workspace Cargo files 35 COPY Cargo.toml Cargo.lock ./ 36 37 # Copy otelmart service 38 COPY otelmart/Cargo.toml ./otelmart/ 39 COPY otelmart/src ./otelmart/src/ 40 COPY otelmart/config.toml ./otelmart/ 41 COPY otelmart/config.docker.toml ./otelmart/ 42 43 # Copy products (required by workspace) 44 COPY products/Cargo.toml ./products/ 45 COPY products/src ./products/src/ 46 47 # Copy inventory (required by workspace) 48 COPY inventory/Cargo.toml ./inventory/ 49 COPY inventory/src ./inventory/src/ 50 51 # Copy orders (required by workspace) 52 COPY orders/Cargo.toml ./orders/ 53 COPY orders/src ./orders/src/ 54 55 # Build the service (release mode) 56 WORKDIR /app 57 RUN cargo build --release 58 59 # Stage 3: Runtime image 60 FROM debian:bookworm-slim 61 62 WORKDIR /app 63 64 # Install runtime dependencies 65 RUN apt-get update && \ 66 apt-get install -y ca-certificates libssl3 curl && \ 67 rm -rf /var/lib/apt/lists/* 68 69 # Copy built binary from rust-builder 70 COPY --from=rust-builder /app/target/release/otelmart /app/otelmart 71 72 # Copy config file (use docker config) 73 COPY --from=rust-builder /app/otelmart/config.docker.toml /app/config.toml 74 75 # Copy built Angular app from client-builder 76 COPY --from=client-builder /app/client/dist /app/dist 77 78 # Create non-root user 79 RUN useradd -m -u 1000 appuser && \ 80 chown -R appuser:appuser /app 81 USER appuser 82 83 # Expose port 84 EXPOSE 4200 85 86 # Health check 87 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ 88 CMD ["/usr/bin/curl", "-f", "http://localhost:4200/health"] 89 90 # Run the service 91 CMD ["/app/otelmart"]