Skip to content

Commit 1dc73b2

Browse files
committed
[no-relnote] Support PUSH_ON_BUILD for native images
Signed-off-by: Evan Lezar <[email protected]>
1 parent c008105 commit 1dc73b2

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

deployments/container/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ DISTRIBUTIONS := ubuntu20.04 ubi8
4343

4444
META_TARGETS := packaging
4545

46+
IMAGE_TARGETS := $(patsubst %,image-%,$(DISTRIBUTIONS) $(META_TARGETS))
4647
BUILD_TARGETS := $(patsubst %,build-%,$(DISTRIBUTIONS) $(META_TARGETS))
4748
PUSH_TARGETS := $(patsubst %,push-%,$(DISTRIBUTIONS) $(META_TARGETS))
4849
TEST_TARGETS := $(patsubst %,test-%,$(DISTRIBUTIONS))
@@ -83,7 +84,7 @@ build-%: DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile.$(DOCKERFILE_SU
8384
ARTIFACTS_ROOT ?= $(shell realpath --relative-to=$(CURDIR) $(DIST_DIR))
8485

8586
# Use a generic build target to build the relevant images
86-
$(BUILD_TARGETS): build-%: $(ARTIFACTS_ROOT)
87+
$(IMAGE_TARGETS): image-%: $(ARTIFACTS_ROOT)
8788
DOCKER_BUILDKIT=1 \
8889
$(DOCKER) $(BUILDX) build --pull \
8990
--provenance=false --sbom=false \
@@ -113,6 +114,12 @@ build-packaging: DOCKERFILE_SUFFIX := packaging
113114
build-packaging: PACKAGE_ARCH := amd64
114115
build-packaging: PACKAGE_DIST = all
115116

117+
# Handle the default build target.
118+
.PHONY: build
119+
build: $(DEFAULT_PUSH_TARGET)
120+
$(DEFAULT_PUSH_TARGET): build-$(DEFAULT_PUSH_TARGET)
121+
$(DEFAULT_PUSH_TARGET): DIST = $(DEFAULT_PUSH_TARGET)
122+
116123
# Test targets
117124
test-%: DIST = $(*)
118125

deployments/container/multi-arch.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ 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-
# We only generate amd64 image for ubuntu18.04
20-
build-ubuntu18.04: DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
19+
$(BUILD_TARGETS): build-%: image-%
2120

2221
# We only generate a single image for packaging targets
2322
build-packaging: DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64

deployments/container/native-only.mk

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,21 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
15+
PUSH_ON_BUILD ?= false
16+
ARCH ?= $(shell uname -m)
17+
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/$(ARCH)
18+
19+
ifeq ($(PUSH_ON_BUILD),true)
20+
$(BUILD_TARGETS): build-%: image-%
21+
$(DOCKER) push "$(IMAGE)"
22+
else
23+
$(BUILD_TARGETS): build-%: image-%
24+
endif
25+
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)