FROM golang:1.23-alpine AS builder WORKDIR /app # Copy go.mod and go.sum files COPY go.mod go.sum ./ # Download dependencies RUN go mod download # Copy the source code COPY . . # Build the application RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server main.go # Use a small alpine image for the final stage FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /app # Copy the binary from the builder stage COPY --from=builder /app/server . # Expose the application port EXPOSE 8080 # Set environment variables ENV PORT=8080 ENV GIN_MODE=release # Run the application CMD ["./server"]