2022-03-25 19:14:02 +00:00
|
|
|
ARG GO_VERSION=1.18
|
|
|
|
|
|
|
|
# STAGE 1: building the executable
|
|
|
|
FROM golang:${GO_VERSION}-alpine AS build
|
|
|
|
RUN apk add --no-cache git
|
|
|
|
RUN apk --no-cache add ca-certificates
|
|
|
|
|
|
|
|
# add a user here because addgroup and adduser are not available in scratch
|
|
|
|
RUN addgroup -S myapp \
|
|
|
|
&& adduser -S -u 10000 -g myapp myapp
|
|
|
|
|
|
|
|
WORKDIR /src
|
|
|
|
COPY ./go.mod ./go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
COPY ./ ./
|
|
|
|
|
|
|
|
# Build the executable
|
|
|
|
RUN CGO_ENABLED=0 go build \
|
|
|
|
-installsuffix 'static' \
|
|
|
|
-o /app .
|
|
|
|
|
|
|
|
# STAGE 2: build the container to run
|
2022-03-25 19:47:12 +00:00
|
|
|
FROM gcr.io/distroless/static AS final
|
2022-03-25 19:14:02 +00:00
|
|
|
|
2022-03-25 19:47:12 +00:00
|
|
|
LABEL maintainer="gbaeke"
|
|
|
|
USER nonroot:nonroot
|
2022-03-25 19:14:02 +00:00
|
|
|
|
2022-03-25 19:47:12 +00:00
|
|
|
# copy compiled app
|
|
|
|
COPY --from=build --chown=nonroot:nonroot /app /app
|
2022-03-24 11:47:37 +00:00
|
|
|
|
2022-03-25 19:47:12 +00:00
|
|
|
# run binary; use vector form
|
2022-03-24 11:47:37 +00:00
|
|
|
ENTRYPOINT ["/app"]
|