docs/code-samples/eventing/helloworld/helloworld-go/Dockerfile

32 lines
991 B
Docker

# Use the official Golang image to create a build artifact.
# This is based on Debian and sets the GOPATH to /go.
# https://hub.docker.com/_/golang
FROM golang:latest AS builder
ARG TARGETOS
ARG TARGETARCH
# Copy local code to the container image.
WORKDIR /app
# Copy local code to the container image.
COPY . ./
# Install dependencies and tidy up the go.mod and go.sum files.
RUN go mod tidy
# Build the binary.
# -mod=readonly ensures immutable go.mod and go.sum in container builds.
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -mod=readonly -v -o helloworld
# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM alpine:3
RUN apk add --no-cache ca-certificates
# Copy the binary to the production image from the builder stage.
COPY --from=builder /app/helloworld /helloworld
# Run the web service on container startup.
CMD ["/helloworld"]