FROM golang:1.22 as builder WORKDIR /app # Copy go module files and download dependencies COPY go.mod go.sum ./ RUN go mod download # Copy the rest of the application COPY . . # Build the Go application RUN go build -o main ./... # Stage 2: Create a minimal production image FROM alpine:latest WORKDIR /app # Copy the built application from the builder stage COPY --from=builder /app/main . # Copy the .env file (if exists) COPY .env .env # Expose the necessary port (change as needed) EXPOSE 8080 # Run the application CMD ["./main"] # Healthcheck to ensure the app is running HEALTHCHECK --interval=30s --timeout=5s --retries=3 \ CMD curl -f http://localhost:8080/health || exit 1