FROM golang:alpine as builder WORKDIR /src COPY go.* ./ RUN go mod download RUN go get -v ./... RUN go mod vendor COPY build . RUN apk update && apk add upx ca-certificates openssl && update-ca-certificates RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o /bin/api-binary ./main.go RUN upx -9 /bin/api-binary FROM gcr.io/distroless/static:nonroot WORKDIR /src/ COPY --from=builder /bin/api-binary /bin/api-binary COPY --from=builder --chown=nonroot /src/config /src/config ENTRYPOINT ["/bin/api-binary"]