forked from mtougeron/k8s-pvc-tagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
45 lines (33 loc) · 1.09 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
FROM golang:1.22-alpine AS builder
ARG VERSION=0.0.1
ARG TARGETARCH
ENV APP_NAME=k8s-pvc-tagger \
GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=$TARGETARCH
# Move to working directory /build
WORKDIR /build
# Copy and download dependency using go mod
COPY go.mod go.sum ./
RUN go mod download
# Copy the code into the container
COPY . .
ENV APP_VERSION=$VERSION
# Build the application
RUN date +%s > buildtime
RUN APP_BUILD_TIME=$(cat buildtime); \
go build -ldflags="-X 'main.buildTime=${APP_BUILD_TIME}' -X 'main.buildVersion=${APP_VERSION}'" -o ${APP_NAME} .
# Move to /dist directory as the place for resulting binary folder
WORKDIR /app
# Copy binary from build to main folder
RUN cp /build/${APP_NAME} .
RUN addgroup -S k8s-pvc-tagger && adduser -S k8s-pvc-tagger -G k8s-pvc-tagger
# Build a small image
FROM scratch
COPY --from=builder /etc/passwd /etc/passwd
USER k8s-pvc-tagger
# https://github.com/aws/aws-sdk-go/issues/2322
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/${APP_NAME} /
ENTRYPOINT ["/k8s-pvc-tagger"]