# Built following https://medium.com/@chemidy/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324 # STEP 1 build executable binary FROM golang:alpine as builder # BUILD_DATE and VCS_REF are immaterial, since this is a 2-stage build, but our build # hook won't work unless we specify the args ARG BUILD_DATE ARG VCS_REF # Install SSL ca certificates RUN apk update && apk add git && apk add ca-certificates # Create appuser RUN adduser -D -g '' appuser COPY . $GOPATH/src/mypackage/myapp/ WORKDIR $GOPATH/src/mypackage/myapp/ #get dependancies RUN go get -d -v #build the binary RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/alertmanager-discord # STEP 2 build a small image # start from scratch FROM scratch # Now we DO need these, for the auto-labeling of the image ARG BUILD_DATE ARG VCS_REF # Good docker practice, plus we get microbadger badges LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.vcs-url="https://github.com/funkypenguin/alertmanager-discord.git" \ org.label-schema.vcs-ref=$VCS_REF \ org.label-schema.schema-version="2.2-r1" COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /etc/passwd /etc/passwd # Copy our static executable COPY --from=builder /go/bin/alertmanager-discord /go/bin/alertmanager-discord EXPOSE 9094 USER appuser ENTRYPOINT ["/go/bin/alertmanager-discord"]