Skip to content

Commit

Permalink
build: Makefile support for DOCKER_IMAGE_SUFFIX, CI_BUILD, and KIND_LOAD
Browse files Browse the repository at this point in the history
DOCKER_IMAGE_SUFFIX, if defined, will be added to the end of th docker
image name, before the tag. For example:

$ DOCKER_IMAGE_SUFFIX=-ci make docker-cilium-image

will build `quay.io/cilium/cilium-ci:latest`

CI_BUILD, if defined, will define DOCKER_IMAGE_SUFFIX as "-ci", and
DOCKER_IMAGE_TAG as the git HEAD SHA, which will then replace the default
"latest" tag in the example above. This helps build local images with the
same image reference that real CI builds would use.

KIND_LOAD, if defined, will load the build image with "kind load" one
second after the build completes. The one second delay was required as
without it "kind load" sometimes reported that it can't find the image
that was just built.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
  • Loading branch information
jrajahalme authored and nbusseneau committed Nov 4, 2022
1 parent 7fbf0a0 commit 3fd3691
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ ifeq ($(DOCKER_DEV_ACCOUNT),)
DOCKER_DEV_ACCOUNT=cilium
endif

ifneq ($(CI_BUILD),)
DOCKER_IMAGE_SUFFIX=-ci
DOCKER_IMAGE_TAG=$(shell git rev-parse HEAD)
endif

# Set DOCKER_IMAGE_TAG with "latest" by default
ifeq ($(DOCKER_IMAGE_TAG),)
DOCKER_IMAGE_TAG=latest
Expand Down
11 changes: 8 additions & 3 deletions Makefile.docker
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ endif
--build-arg CILIUM_SHA=$(firstword $(GIT_VERSION)) \
--build-arg OPERATOR_VARIANT=$(IMAGE_NAME) \
--target $(5) \
-t $(IMAGE_REPOSITORY)/$(IMAGE_NAME)$${UNSTRIPPED}:$(4) .
ifeq ($(findstring --push,$(DOCKER_FLAGS)),)
@echo 'Define "DOCKER_FLAGS=--push" to push the build results.'
-t $(IMAGE_REPOSITORY)/$(IMAGE_NAME)$${UNSTRIPPED}$(DOCKER_IMAGE_SUFFIX):$(4) .
ifneq ($(KIND_LOAD),)
sleep 1
kind load docker-image $(IMAGE_REPOSITORY)/$(IMAGE_NAME)$${UNSTRIPPED}$(DOCKER_IMAGE_SUFFIX):$(4)
else
ifeq ($(findstring --push,$(DOCKER_FLAGS)),)
@echo 'Define "DOCKER_FLAGS=--push" to push the build results.'
else
$(CONTAINER_ENGINE) buildx imagetools inspect $(IMAGE_REPOSITORY)/$(IMAGE_NAME):$(4)
@echo '^^^ Images pushed, multi-arch manifest should be above. ^^^'
endif
endif

$(1)-unstripped: NOSTRIP=1
Expand Down

0 comments on commit 3fd3691

Please sign in to comment.