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