24 lines
623 B
Docker
24 lines
623 B
Docker
# Use the official Golang image to create a build artifact.
|
|
# https://hub.docker.com/_/golang
|
|
FROM golang:1.22 as builder
|
|
|
|
# Create and change to the app directory.
|
|
WORKDIR /app
|
|
|
|
# Retrieve application dependencies.
|
|
# This allows the container build to reuse cached dependencies.
|
|
# Expecting a go.mod file to be present.
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy local code to the container image.
|
|
COPY . .
|
|
|
|
# Build the binary.
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -o /go/bin/app .
|
|
|
|
# Use a slim distribution for a small image.
|
|
FROM gcr.io/distroless/static-debian11
|
|
COPY --from=builder /go/bin/app /
|
|
CMD ["/app"]
|