# Build stage FROM golang:1.21-alpine AS builder WORKDIR /app # Install build dependencies RUN apk add --no-cache git ca-certificates # Copy go mod files COPY go.mod go.sum ./ RUN go mod download # Copy source code COPY . . # Build binaries RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o mycrib-api ./cmd/api RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o mycrib-worker ./cmd/worker # Runtime stage FROM alpine:3.19 WORKDIR /app # Install runtime dependencies RUN apk add --no-cache ca-certificates tzdata # Copy binaries from builder COPY --from=builder /app/mycrib-api . COPY --from=builder /app/mycrib-worker . # Copy templates if needed COPY --from=builder /app/templates ./templates # Create non-root user RUN adduser -D -g '' appuser USER appuser # Expose port EXPOSE 8000 # Default command (API server) CMD ["./mycrib-api"]