-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize Dockerfile for multi-arch (#1052)
Signed-off-by: FillZpp <[email protected]>
- Loading branch information
Showing
3 changed files
with
37 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Build the manager and daemon binaries | ||
FROM --platform=$BUILDPLATFORM golang:1.17 as builder | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
|
||
# Copy the go source | ||
COPY main.go main.go | ||
COPY apis/ apis/ | ||
COPY cmd/ cmd/ | ||
COPY pkg/ pkg/ | ||
COPY vendor/ vendor/ | ||
|
||
# Build | ||
ARG TARGETOS TARGETARCH | ||
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 GO111MODULE=on go build -mod=vendor -a -o manager main.go \ | ||
&& GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 GO111MODULE=on go build -mod=vendor -a -o daemon ./cmd/daemon/main.go | ||
|
||
# Use Ubuntu 20.04 LTS as base image to package the binaries | ||
FROM --platform=$TARGETPLATFORM ubuntu:focal | ||
# This is required by daemon connnecting with CRI | ||
RUN ln -s /usr/bin/* /usr/sbin/ && apt-get update -y \ | ||
&& apt-get install --no-install-recommends -y ca-certificates \ | ||
&& apt-get clean && rm -rf /var/log/*log /var/lib/apt/lists/* /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old | ||
|
||
WORKDIR / | ||
COPY --from=builder /workspace/manager . | ||
COPY --from=builder /workspace/daemon ./kruise-daemon | ||
ENTRYPOINT ["/manager"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters