# Use a smaller base image for the build stage FROM golang:1.20.0-alpine AS builder # Set the working directory WORKDIR /workspace # Copy only the necessary files for dependency resolution COPY go.mod go.sum ./ # Download dependencies RUN go mod download # Copy the entire application source COPY . . # Build the Go application with optimizations enabled RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -tags prod -o /bin/app ./servers/ # Use a smaller base image for the final stage FROM alpine:3.20 # Set the working directory WORKDIR /application # Copy the built binary from the builder stage COPY --from=builder /bin/app /application/ # Copy the configs folder from the local machine to the image COPY ./configs/ /application/configs # Set the entry point for the container ENTRYPOINT ["/application/app"]