Skip to content

Commit 469493d

Browse files
authored
Merge pull request #20 from BSWANG/main
reduce agent image size
2 parents e986c50 + f0342ea commit 469493d

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

Dockerfile

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,37 @@ ARG TARGETOS
44
ARG TARGETARCH
55

66
WORKDIR /workspace
7-
# Copy the Go Modules manifests
7+
8+
# Copy the Go Modules manifests and cache dependencies
89
COPY go.mod go.mod
910
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
1211
RUN go mod download
1312

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/
1817

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
2722

2823
# 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
3125
WORKDIR /
3226
COPY --from=builder /workspace/manager .
3327
USER 65532:65532
3428

3529
ENTRYPOINT ["/manager"]
3630

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
3933
COPY --from=builder /workspace/smcr_init /usr/local/bin/smcr_init
4034
ENTRYPOINT ["/usr/local/bin/smcr_init"]
4135

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
4438
COPY --from=builder /workspace/agent /usr/local/bin/agent
4539
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

Comments
 (0)