@@ -4,43 +4,37 @@ ARG TARGETOS
4
4
ARG TARGETARCH
5
5
6
6
WORKDIR /workspace
7
- # Copy the Go Modules manifests
7
+
8
+ # Copy the Go Modules manifests and cache dependencies
8
9
COPY go.mod go.mod
9
10
COPY go.sum go.sum
10
- # cache deps before building and copying source so that we don't need to re-download as much
11
- # and so that source changes don't invalidate our downloaded layer
12
11
RUN go mod download
13
12
14
- # Copy the go source
15
- COPY cmd/ cmd/
16
- COPY api/ api/
17
- COPY internal/ internal/
13
+ # Copy the Go source code and build the binaries
14
+ COPY cmd/ ./ cmd/
15
+ COPY api/ ./ api/
16
+ COPY internal/ ./ internal/
18
17
19
- # Build
20
- # the GOARCH has not a default value to allow the binary be built according to the host where the command
21
- # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22
- # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23
- # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24
- RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/controller/main.go
25
- RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o agent cmd/agent/main.go
26
- RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o smcr_init cmd/smcr_init/main.go
18
+ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \
19
+ go build -a -o manager ./cmd/controller/main.go && \
20
+ go build -a -o agent ./cmd/agent/main.go && \
21
+ go build -a -o smcr_init ./cmd/smcr_init/main.go
27
22
28
23
# Use distroless as minimal base image to package the manager binary
29
- # Refer to https://github.com/GoogleContainerTools/distroless for more details
30
- FROM gcr.io/distroless/static:nonroot as controller
24
+ FROM gcr.io/distroless/static:nonroot AS controller
31
25
WORKDIR /
32
26
COPY --from=builder /workspace/manager .
33
27
USER 65532:65532
34
28
35
29
ENTRYPOINT ["/manager" ]
36
30
37
- FROM --platform=$TARGETPLATFORM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3 as smcr_init
38
- RUN yum install -y smc-tools
31
+ FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3 AS smcr_init
32
+ RUN sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g' /etc/ yum.repos.d/*; yum install -y smc-tools && yum clean all && rm -rf /var/cache/* /var/lib/dnf/history* /var/lib/rpm/rpm.sqlite
39
33
COPY --from=builder /workspace/smcr_init /usr/local/bin/smcr_init
40
34
ENTRYPOINT ["/usr/local/bin/smcr_init" ]
41
35
42
- FROM --platform=$TARGETPLATFORM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3 as agent
43
- RUN yum install -y smc-tools procps-ng
36
+ FROM alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3 AS agent
37
+ RUN sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g' /etc/ yum.repos.d/*; yum install -y smc-tools procps-ng && yum clean all && rm -rf /var/cache/* /var/lib/dnf/history* /var/lib/rpm/rpm.sqlite
44
38
COPY --from=builder /workspace/agent /usr/local/bin/agent
45
39
COPY --from=builder /workspace/smcr_init /usr/local/bin/smcr_init
46
- ENTRYPOINT ["/usr/local/bin/agent" ]
40
+ ENTRYPOINT ["/usr/local/bin/agent" ]
0 commit comments