Skip to content

Commit 38c01b5

Browse files
committed
Fix single-arch image push
Signed-off-by: Evan Lezar <[email protected]>
1 parent 3df6fd5 commit 38c01b5

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

deployments/container/Makefile

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
BUILD_MULTI_ARCH_IMAGES ?= false
1616
DOCKER ?= docker
17-
BUILDX =
18-
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
19-
BUILDX = buildx
20-
endif
17+
BUILDX =
2118
MKDIR ?= mkdir
2219

2320
include $(CURDIR)/versions.mk
@@ -42,9 +39,10 @@ OUT_IMAGE = $(OUT_IMAGE_NAME):$(OUT_IMAGE_TAG)
4239
DEFAULT_PUSH_TARGET := ubuntu22.04
4340
DISTRIBUTIONS := ubuntu22.04 ubi9
4441

45-
BUILD_TARGETS := $(patsubst %,build-%, $(DISTRIBUTIONS))
46-
PUSH_TARGETS := $(patsubst %,push-%, $(DISTRIBUTIONS))
47-
TEST_TARGETS := $(patsubst %,test-%, $(DISTRIBUTIONS))
42+
IMAGE_TARGETS := $(patsubst %,image-%,$(DISTRIBUTIONS))
43+
BUILD_TARGETS := $(patsubst %,build-%,$(DISTRIBUTIONS))
44+
PUSH_TARGETS := $(patsubst %,push-%,$(DISTRIBUTIONS))
45+
TEST_TARGETS := $(patsubst %,test-%,$(DISTRIBUTIONS))
4846

4947
.PHONY: $(DISTRIBUTIONS) $(PUSH_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS)
5048

@@ -66,6 +64,11 @@ ARCH = arm64
6664
endif
6765
endif
6866

67+
# If BUILD_MULTI_ARCH_IMAGES is still true for a given set of samples, we enable buildx.
68+
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
69+
BUILDX = buildx
70+
endif
71+
6972
ifneq ($(BUILD_MULTI_ARCH_IMAGES),true)
7073
include $(CURDIR)/deployments/container/native-only.mk
7174
else
@@ -105,7 +108,7 @@ build-ubuntu%: DOCKERFILE_SUFFIX = ubuntu
105108
build-ubi9: DOCKERFILE_SUFFIX = ubi9
106109

107110
# Use a generic build target to build the relevant images
108-
$(BUILD_TARGETS): build-%:
111+
$(IMAGE_TARGETS): image-%:
109112
DOCKER_BUILDKIT=1 \
110113
$(DOCKER) $(BUILDX) build --pull \
111114
--provenance=false --sbom=false \
@@ -116,3 +119,20 @@ $(BUILD_TARGETS): build-%:
116119
--build-arg SAMPLE_NAME=$(SAMPLE) \
117120
-f $(DOCKERFILE) \
118121
$(CURDIR)
122+
123+
# Handle the default build target.
124+
.PHONY: build
125+
build: $(DEFAULT_PUSH_TARGET)
126+
$(DEFAULT_PUSH_TARGET): build-$(DEFAULT_PUSH_TARGET)
127+
$(DEFAULT_PUSH_TARGET): DIST = $(DEFAULT_PUSH_TARGET)
128+
129+
REGCTL ?= regctl
130+
$(PUSH_TARGETS): push-%:
131+
$(REGCTL) \
132+
image copy \
133+
$(IMAGE) $(OUT_IMAGE)
134+
135+
push-short:
136+
$(REGCTL) \
137+
image copy \
138+
$(IMAGE) $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)

deployments/container/multi-arch.mk

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,4 @@ PUSH_ON_BUILD ?= false
1616
DOCKER_BUILD_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD)
1717
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64
1818

19-
REGCTL ?= regctl
20-
$(PUSH_TARGETS): push-%:
21-
$(REGCTL) \
22-
image copy \
23-
$(IMAGE) $(OUT_IMAGE)
24-
25-
push-short:
26-
$(REGCTL) \
27-
image copy \
28-
$(IMAGE) $(OUT_IMAGE_NAME):${LOWER_CASE_SAMPLE}-$(OUT_IMAGE_VERSION)
29-
30-
push-sample:
31-
$(REGCTL) \
32-
image copy \
33-
$(IMAGE) $(OUT_IMAGE_NAME):$(LOWER_CASE_SAMPLE)
19+
$(BUILD_TARGETS): build-%: image-%

deployments/container/native-only.mk

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ PUSH_ON_BUILD ?= false
1616
ARCH ?= $(shell uname -m)
1717
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/$(ARCH)
1818

19-
$(PUSH_TARGETS): push-%:
20-
$(DOCKER) tag "$(IMAGE)" "$(OUT_IMAGE)"
21-
$(DOCKER) push "$(OUT_IMAGE)"
19+
ifeq ($(PUSH_ON_BUILD),true)
20+
$(BUILD_TARGETS): build-%: image-%
21+
$(DOCKER) push "$(IMAGE)"
22+
else
23+
$(BUILD_TARGETS): build-%: image-%
24+
endif
2225

23-
push-short:
24-
$(DOCKER) tag $(IMAGE) $(OUT_IMAGE_NAME):${LOWER_CASE_SAMPLE}-$(OUT_IMAGE_VERSION)
25-
$(DOCKER) push $(OUT_IMAGE_NAME):${LOWER_CASE_SAMPLE}-$(OUT_IMAGE_VERSION)
26-
27-
push-sample:
28-
$(DOCKER) tag $(IMAGE) $(OUT_IMAGE_NAME):$(LOWER_CASE_SAMPLE)
29-
$(DOCKER) push $(OUT_IMAGE_NAME):$(LOWER_CASE_SAMPLE)
26+
# For the default distribution we also retag the image.
27+
# Note: This needs to be updated for multi-arch images.
28+
ifeq ($(IMAGE_TAG),$(VERSION)-$(DIST))
29+
$(DEFAULT_PUSH_TARGET):
30+
$(DOCKER) image inspect $(IMAGE) > /dev/null || $(DOCKER) pull $(IMAGE)
31+
$(DOCKER) tag $(IMAGE) $(subst :$(IMAGE_TAG),:$(VERSION),$(IMAGE))
32+
endif

0 commit comments

Comments
 (0)