# Build stage FROM docker.io/rust:1-alpine AS builder # Install build dependencies RUN apk add --no-cache musl-dev WORKDIR /app # Copy manifests COPY Cargo.toml ./ # Create dummy main.rs for dependency caching RUN mkdir src && echo "fn main() {}" > src/main.rs # Build dependencies RUN cargo build --release RUN rm -rf src # Copy source code COPY src ./src # Touch main.rs to ensure rebuild RUN touch src/main.rs # Build the application RUN cargo build --release # Runtime stage FROM docker.io/alpine:latest # Install runtime dependencies RUN apk add --no-cache ca-certificates # Create non-root user RUN adduser -D -u 1000 naas WORKDIR /app # Copy binary from builder COPY --from=builder /app/target/release/naas /app/naas RUN chmod +x /app/naas # Change ownership RUN chown -R naas:naas /app USER naas # Expose port EXPOSE 8080 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1 # Run the application CMD ["./naas"]