@@ -18,22 +18,31 @@ RUN sed -i '/^toolchain/d' go.mod && GOTOOLCHAIN=${GOTOOLCHAIN} go mod download
1818COPY cmd/ cmd/
1919COPY pkg/ pkg/
2020
21- # Build the ENI Controller
22- RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOTOOLCHAIN=${GOTOOLCHAIN} go build -a -o manager cmd/main.go
21+ # Build the ENI Controller with optimizations for size
22+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOTOOLCHAIN=${GOTOOLCHAIN} \
23+ go build -a -ldflags="-s -w" -trimpath -o manager cmd/main.go
2324
24- # Build the ENI Manager
25- RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOTOOLCHAIN=${GOTOOLCHAIN} go build -a -o eni-manager cmd/eni-manager/main.go
25+ # Build the ENI Manager with optimizations for size
26+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOTOOLCHAIN=${GOTOOLCHAIN} \
27+ go build -a -ldflags="-s -w" -trimpath -o eni-manager cmd/eni-manager/main.go
28+
29+ # Use UPX to compress the binaries
30+ FROM alpine:3.19 AS compressor
31+ RUN apk --no-cache add upx
32+ COPY --from=builder /workspace/manager /manager
33+ COPY --from=builder /workspace/eni-manager /eni-manager
34+ RUN upx --best --lzma /manager /eni-manager
2635
2736# Use a minimal base image for the final image
2837FROM alpine:3.19
2938
30- # Install iproute2 for the ip command (used as fallback by ENI Manager)
31- RUN apk --no-cache add iproute2
39+ # Install only the necessary packages
40+ RUN apk --no-cache add iproute2 --no-scripts
3241
33- # Copy the binaries from the builder stage
42+ # Copy the compressed binaries from the compressor stage
3443WORKDIR /
35- COPY --from=builder /workspace /manager .
36- COPY --from=builder /workspace /eni-manager .
44+ COPY --from=compressor /manager .
45+ COPY --from=compressor /eni-manager .
3746COPY build/entrypoint.sh /entrypoint.sh
3847
3948# Make the entrypoint script executable
0 commit comments