forked from enix/kube-image-keeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
58 lines (45 loc) · 1.85 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
48
49
50
51
52
53
54
55
56
57
58
# Build the manager binary
FROM --platform=${BUILDPLATFORM} golang:1.20-alpine3.17 AS builder
WORKDIR /workspace
RUN go install sigs.k8s.io/controller-tools/cmd/[email protected]
# 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 main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY cmd/ cmd/
COPY internal/ internal/
# Copy the makefile
COPY Makefile Makefile
ARG TARGETOS
ARG TARGETARCH
ENV CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH}
ARG VERSION
ARG REVISION
ENV LD_FLAGS="\
-X 'github.com/enix/kube-image-keeper/internal/metrics.Version=${VERSION}' \
-X 'github.com/enix/kube-image-keeper/internal/metrics.Revision=${REVISION}' \
-X 'github.com/enix/kube-image-keeper/internal/metrics.BuildDateTime=BUILD_DATE_TIME'"
RUN BUILD_DATE_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S") && \
LD_FLAGS=$(/bin/ash -c "set -o pipefail && echo $LD_FLAGS | sed -e \"s/BUILD_DATE_TIME/$BUILD_DATE_TIME/g\"") && \
controller-gen object paths="./..." && \
go build -a -ldflags="$LD_FLAGS" -o manager cmd/cache/main.go && \
go build -a -ldflags="$LD_FLAGS" -o registry-proxy cmd/proxy/main.go
FROM alpine:3.17 AS alpine
COPY --from=builder /workspace/manager /usr/local/bin/
COPY --from=builder /workspace/registry-proxy /usr/local/bin/
USER 65532:65532
ENTRYPOINT ["manager"]
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager /usr/local/bin/
COPY --from=builder /workspace/registry-proxy /usr/local/bin/
USER 65532:65532
ENTRYPOINT ["manager"]