make buildx: use multi-stage to make tagged image smaller
The build-stage would still be in the local cache (and can be cleaned up with `docker system prune`) but the tagged image (which usually wouldn't be removed) will take up less space now. Note that - the binary is not statically linked, so we cannot use a "from scratch" image - in cases where the binary is cross-compiled (e.g. on a non-linux machine), the image itself is not really useful (we may want to consider not tagging the image in that situation) Before: REPOSITORY TAG IMAGE ID CREATED SIZE moby-buildx latest c9b2af465baf 7 minutes ago 1.71GB After: REPOSITORY TAG IMAGE ID CREATED SIZE moby-buildx latest 345501e2df0a 2 minutes ago 820MB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
a602ecf8fb
commit
b6ae3c2058
1 changed files with 4 additions and 1 deletions
|
@ -2,7 +2,7 @@ ARG GO_VERSION=1.12.10
|
|||
ARG BUILDX_COMMIT=v0.3.0
|
||||
ARG BUILDX_REPO=https://github.com/docker/buildx.git
|
||||
|
||||
FROM golang:${GO_VERSION}-stretch
|
||||
FROM golang:${GO_VERSION}-stretch AS build
|
||||
ARG BUILDX_REPO
|
||||
RUN git clone "${BUILDX_REPO}" /buildx
|
||||
WORKDIR /buildx
|
||||
|
@ -21,4 +21,7 @@ RUN GOOS="${GOOS}" GOARCH="${GOARCH}" BUILDX_COMMIT="${BUILDX_COMMIT}"; \
|
|||
-X \"${pkg}/version.Package=buildx\" \
|
||||
"; \
|
||||
go build -ldflags "${ldflags}" -o /usr/bin/buildx ./cmd/buildx
|
||||
|
||||
FROM golang:${GO_VERSION}-stretch
|
||||
COPY --from=build /usr/bin/buildx /usr/bin/buildx
|
||||
ENTRYPOINT ["/usr/bin/buildx"]
|
||||
|
|
Loading…
Reference in a new issue