-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile.agent
49 lines (41 loc) · 1.44 KB
/
Dockerfile.agent
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
# Build the manager binary
FROM golang:1.22 as builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /workspace
# Copy the go source
COPY go.mod go.mod
COPY go.sum go.sum
COPY main.go main.go
COPY cmd/agent/ cmd/agent/
COPY api/ api/
COPY internal/ internal/
COPY pkg/ pkg/
COPY vendor/ vendor/
ARG TAG=v0.0.0
ARG COMMIT=""
ARG COMMITDATE=""
# Build agent binary
RUN CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build \
-ldflags "-w -s \
-X github.com/rancher-sandbox/cluster-api-provider-elemental/internal/version.Version=$TAG \
-X github.com/rancher-sandbox/cluster-api-provider-elemental/internal/version.Commit=$COMMIT \
-X github.com/rancher-sandbox/cluster-api-provider-elemental/internal/version.CommitDate=$COMMITDATE" \
-a -o elemental-agent main.go
# Build elemental-toolkit plugin
RUN CGO_ENABLED=1 go build \
-buildmode=plugin \
-o elemental.so internal/agent/plugin/elemental/elemental.go
# Build dummy plugin
RUN CGO_ENABLED=1 go build \
-buildmode=plugin \
-o dummy.so internal/agent/plugin/dummy/dummy.go
# 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/elemental-agent /elemental-agent
COPY --from=builder /workspace/elemental.so /elemental.so
COPY --from=builder /workspace/dummy.so /dummy.so
USER 65532:65532
ENTRYPOINT ["/"]