Skip to content

Commit 9441bc6

Browse files
committed
build: compress SDK with zstd
Rather than implicitly using BuildKit underneath `docker build`, switch to explicitly using it via `docker buildx build` with a custom builder. The default builder loads builds into Docker after they finish, which causes certain options - like zstd compression - to be ignored when pushing to a registry. `docker buildx build` doesn't really distinguish between "build" and "push" steps; a "push" is just a build where the output is sent to a registry rather than written to a tar archive or loaded into Docker. This breaks one of the main assumptions of the `publish-sdk` script, which expects the build to be done already. Rather than wiring up the build arguments as additional arguments to `publish-sdk`, replace it with `docker buildx imagetools create` as the tool for creating and replacing remote manifests. Signed-off-by: Ben Cressey <[email protected]>
1 parent 3afb4fd commit 9441bc6

File tree

2 files changed

+56
-155
lines changed

2 files changed

+56
-155
lines changed

Makefile

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,69 @@ TOP := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
22

33
HOST_ARCH ?= $(shell uname -m)
44
DOCKER_ARCH ?= $(lastword $(subst :, ,$(filter $(HOST_ARCH):%,x86_64:amd64 aarch64:arm64)))
5+
DOCKER_ALT_ARCH ?= $(lastword $(subst :, ,$(filter $(HOST_ARCH):%,x86_64:arm64 aarch64:amd64)))
56
UPSTREAM_SOURCE_FALLBACK ?= false
67

78
VERSION := $(shell cat $(TOP)VERSION)
89
SHORT_SHA := $(shell git rev-parse --short=8 HEAD)
910

10-
IMAGE_NAME ?= bottlerocket-sdk:$(VERSION)-$(SHORT_SHA)-$(DOCKER_ARCH)
11+
REGISTRY ?=
12+
REPOSITORY ?= bottlerocket-sdk
13+
IMAGE_NAME ?= $(REPOSITORY):$(VERSION)-$(SHORT_SHA)-$(DOCKER_ARCH)
14+
IMAGE_ALT_NAME ?= $(REPOSITORY):$(VERSION)-$(SHORT_SHA)-$(DOCKER_ALT_ARCH)
15+
MANIFEST ?= $(REPOSITORY):$(VERSION)
1116

12-
all: sdk
17+
BUILDX_BUILDER ?= sdk-builder
1318

14-
sdk:
15-
@DOCKER_BUILDKIT=1 docker build . \
16-
--tag $(IMAGE_NAME) \
17-
--target sdk-golden \
18-
--build-arg HOST_ARCH=$(HOST_ARCH) \
19-
--build-arg UPSTREAM_SOURCE_FALLBACK=$(UPSTREAM_SOURCE_FALLBACK)
19+
BUILDX_BUILD_ARGS = $\
20+
--build-arg HOST_ARCH=$(HOST_ARCH) $\
21+
--build-arg UPSTREAM_SOURCE_FALLBACK=$(UPSTREAM_SOURCE_FALLBACK) $\
22+
--target sdk-golden $\
23+
--provenance=false $\
24+
--sbom=false $\
25+
--builder $(BUILDX_BUILDER)
2026

21-
publish:
27+
BUILDX_LOAD_ARGS = $\
28+
--tag $(IMAGE_NAME) \
29+
--load
30+
31+
BUILDX_PUSH_ARGS = $\
32+
--output $\
33+
type=registry,name=$(REGISTRY)/$(IMAGE_NAME),$\
34+
compression=zstd,compression-level=22,force-compression=true,$\
35+
oci-mediatypes=true,platform=linux/$(DOCKER_ARCH)
36+
37+
all: build
38+
39+
builder:
40+
@docker buildx create \
41+
--name $(BUILDX_BUILDER) \
42+
--driver docker-container \
43+
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=-1 \
44+
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=-1 \
45+
--node $(BUILDX_BUILDER)0
46+
47+
build: builder
48+
@docker buildx build . \
49+
$(BUILDX_BUILD_ARGS) \
50+
$(BUILDX_LOAD_ARGS)
51+
52+
build-push: builder
2253
@test $${REGISTRY?not set!}
23-
@test $${REPOSITORY?not set!}
24-
$(TOP)publish-sdk --registry=$(REGISTRY) --repository=$(REPOSITORY) --tag=$(VERSION) --short-sha=$(SHORT_SHA)
54+
@docker buildx build . \
55+
$(BUILDX_BUILD_ARGS) \
56+
$(BUILDX_PUSH_ARGS)
57+
58+
publish: build-push
59+
@if docker buildx imagetools inspect $(REGISTRY)/$(IMAGE_ALT_NAME) >/dev/null 2>&1 ; then \
60+
docker buildx imagetools create \
61+
--tag $(REGISTRY)/$(MANIFEST) \
62+
$(REGISTRY)/$(IMAGE_NAME) \
63+
$(REGISTRY)/$(IMAGE_ALT_NAME) ; \
64+
else \
65+
docker buildx imagetools create \
66+
--tag $(REGISTRY)/$(MANIFEST) \
67+
$(REGISTRY)/$(IMAGE_NAME) ; \
68+
fi
2569

26-
.PHONY: all sdk publish
70+
.PHONY: all builder build build-push publish

publish-sdk

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)