From 72eabae4613ce6f22e542a41c59ddf7214216a10 Mon Sep 17 00:00:00 2001 From: naudachu Date: Tue, 6 Jun 2023 18:21:37 +0500 Subject: [PATCH] - added builder to the Docker file; --- Dockerfile | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index b671804..a086aa0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ -FROM golang:1.20-alpine - +FROM golang:alpine as app-builder WORKDIR $GOPATH/src/ticket-creator/ - COPY . . +RUN apk add git +# Static build required so that we can safely copy the binary over. +# `-tags timetzdata` embeds zone info from the "time/tzdata" package. +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install -ldflags '-extldflags "-static"' -tags timetzdata cmd/main.go -RUN go mod download -RUN go mod verify - -RUN cd ./cmd - -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o /usr/local/bin/app cmd/main.go - -CMD ["app"] \ No newline at end of file +FROM scratch +# the test program: +COPY --from=app-builder /go/bin/main /ticket-creator +# the tls certificates: +# NB: this pulls directly from the upstream image, which already has ca-certificates: +COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +ENTRYPOINT ["/ticket-creator"] \ No newline at end of file