# Build stage FROM golang:1.24-alpine AS builder WORKDIR /app # Install build dependencies if needed (e.g., for CGO, though we disable it) RUN apk add --no-cache git # Copy go mod and sum files COPY go.mod go.sum ./ # Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed RUN go mod download # Copy the source from the current directory to the Working Directory inside the container COPY . . # Build the Go app RUN CGO_ENABLED=0 GOOS=linux go build -o api cmd/api/main.go # Start a new stage from scratch FROM alpine:latest WORKDIR /app # Install ca-certificates (useful for making HTTPS requests) RUN apk --no-cache add ca-certificates # Copy the Pre-built binary file from the previous stage COPY --from=builder /app/api . # Expose port (default 8080, but can be overridden) EXPOSE 8080 # Command to run the executable CMD ["./api"]