github.com/pluralsh/plural-cli@v0.9.5/Dockerfile (about) 1 FROM ubuntu:22.10 as user 2 3 # Create a nonroot user for final image 4 RUN useradd -u 10001 nonroot 5 6 FROM golang:1.22-alpine3.19 AS builder 7 8 WORKDIR /workspace 9 10 # Copy the Go Modules manifests 11 COPY go.mod go.mod 12 COPY go.sum go.sum 13 # cache deps before building and copying source so that we don't need to re-download as much 14 # and so that source changes don't invalidate our downloaded layer 15 RUN go mod download 16 17 # Copy the go source 18 COPY main.go main.go 19 COPY cmd/ cmd/ 20 COPY pkg/ pkg/ 21 22 # Build 23 ARG APP_VSN 24 ARG APP_COMMIT 25 ARG APP_DATE 26 ARG TARGETARCH 27 28 RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \ 29 go build -ldflags '-s -w \ 30 -X "github.com/pluralsh/plural-cli/cmd/plural.Version=${APP_VSN}" \ 31 -X "github.com/pluralsh/plural-cli/cmd/plural.Commit=${APP_COMMIT}" \ 32 -X "github.com/pluralsh/plural-cli/cmd/plural.Date=${APP_DATE}"' \ 33 -o plural . 34 35 FROM golang:1.20-alpine3.17 36 37 WORKDIR / 38 39 RUN apk update && apk add --no-cache git build-base 40 41 # Copy nonroot user and switch to it 42 COPY --from=user /etc/passwd /etc/passwd 43 USER nonroot 44 45 COPY --chown=nonroot --from=builder /workspace/plural /go/bin/ 46 RUN chmod a+x /go/bin/plural 47 48 ENTRYPOINT ["/go/bin/plural"]