github.com/cilium/cilium@v1.16.2/Makefile.docker (about)

     1  # Copyright Authors of Cilium
     2  # SPDX-License-Identifier: Apache-2.0
     3  
     4  DOCKER_BUILDER := default
     5  
     6  # Export with value expected by docker
     7  export DOCKER_BUILDKIT=1
     8  
     9  # Docker Buildx support. If ARCH is defined, a builder instance 'cross'
    10  # on the local node is configured for amd64 and arm64 platform targets.
    11  # Otherwise build on the current (typically default) builder for the host
    12  # platform only.
    13  ifdef ARCH
    14    # Default to multi-arch builds, always create the builder for all the platforms we support
    15    DOCKER_PLATFORMS := linux/arm64,linux/amd64
    16    DOCKER_BUILDER := $(shell docker buildx ls | grep -E -e "[a-zA-Z0-9-]+ \*" | cut -d ' ' -f1)
    17    ifneq (,$(filter $(DOCKER_BUILDER),default desktop-linux))
    18      DOCKER_BUILDKIT_DRIVER :=
    19      ifdef DOCKER_BUILDKIT_IMAGE
    20        DOCKER_BUILDKIT_DRIVER := --driver docker-container --driver-opt image=$(DOCKER_BUILDKIT_IMAGE)
    21      endif
    22      BUILDER_SETUP := $(shell docker buildx create --platform $(DOCKER_PLATFORMS) $(DOCKER_BUILDKIT_DRIVER) --use)
    23    endif
    24    # Override default for a single platform
    25    ifneq ($(ARCH),multi)
    26      DOCKER_PLATFORMS := linux/$(ARCH)
    27    endif
    28    DOCKER_FLAGS += --push --platform $(DOCKER_PLATFORMS)
    29  else
    30    ifeq ($(findstring --output,$(DOCKER_FLAGS)),)
    31      ifeq ($(findstring --push,$(DOCKER_FLAGS)),)
    32        # ARCH, --output, and --push are not specified, build for the host platform without pushing, mimicking regular docker build
    33        DOCKER_FLAGS += --load
    34      endif
    35    endif
    36  endif
    37  DOCKER_EXISTS := $(shell command -v docker 2>/dev/null)
    38  ifdef DOCKER_EXISTS
    39  DOCKER_BUILDER := $(shell docker buildx ls | grep -E -e "[a-zA-Z0-9-]+ \*" | cut -d ' ' -f1)
    40  endif
    41  
    42  ##@ Docker Images
    43  .PHONY: builder-info
    44  builder-info: ## Print information about the docker builder that will be used for building images.
    45  	@echo "Using Docker Buildx builder \"$(DOCKER_BUILDER)\" with build flags \"$(DOCKER_FLAGS)\"."
    46  
    47  # Generic rule for augmented .dockerignore files.
    48  GIT_IGNORE_FILES := $(shell find . -not -path "./vendor*" -name .gitignore -print)
    49  .PRECIOUS: %.dockerignore
    50  %.dockerignore: $(GIT_IGNORE_FILES) Makefile.docker
    51  	@-mkdir -p $(dir $@)
    52  	@echo "/hack" > $@
    53  	@echo ".git" >> $@
    54  	@echo "/Makefile.docker" >> $@
    55  	@echo $(dir $(GIT_IGNORE_FILES)) | tr ' ' '\n' | xargs -P1 -I {DIR} -n1 sed \
    56  		-e '# Remove lines with white space, comments and files that must be passed to docker, "$$" due to make. #' \
    57  			-e '/^[[:space:]]*$$/d' -e '/^#/d' -e '/GIT_VERSION/d' \
    58  		-e '# Apply pattern in all directories if it contains no "/", keep "!" up front. #' \
    59  			-e '/^[^!/][^/]*$$/s<^<**/<' -e '/^![^/]*$$/s<^!<!**/<' \
    60  		-e '# Prepend with the directory name, keep "!" up front. #' \
    61  			-e '/^[^!]/s<^<{DIR}<' -e '/^!/s<^!<!{DIR}<'\
    62  		-e '# Remove leading "./", keep "!" up front. #' \
    63  			-e 's<^\./<<' -e 's<^!\./<!<' \
    64  		-e '# Append newline to the last line if missing. GNU sed does not do this automatically. #' \
    65  			-e '$$a\' \
    66  		{DIR}.gitignore >> $@
    67  
    68  DOCKER_REGISTRY ?= quay.io
    69  ifeq ($(findstring /,$(DOCKER_DEV_ACCOUNT)),/)
    70      # DOCKER_DEV_ACCOUNT already contains '/', assume it specifies a registry
    71      IMAGE_REPOSITORY := $(DOCKER_DEV_ACCOUNT)
    72  else
    73      IMAGE_REPOSITORY := $(DOCKER_REGISTRY)/$(DOCKER_DEV_ACCOUNT)
    74  endif
    75  
    76  #
    77  # Template for Docker images. Paramaters are:
    78  # $(1) image target name
    79  # $(2) Dockerfile path
    80  # $(3) image name stem (e.g., cilium, cilium-operator, etc)
    81  # $(4) image tag
    82  # $(5) target
    83  #
    84  define DOCKER_IMAGE_TEMPLATE
    85  .PHONY: $(1)
    86  $(1): GIT_VERSION $(2) $(2).dockerignore GIT_VERSION builder-info
    87  	$(ECHO_DOCKER)$(2) $(IMAGE_REPOSITORY)/$(IMAGE_NAME)$${UNSTRIPPED}:$(4)
    88  	$(eval IMAGE_NAME := $(subst %,$$$$*,$(3)))
    89  ifeq ($(5),debug)
    90  	@export NOSTRIP=1
    91  endif
    92  	$(QUIET) $(CONTAINER_ENGINE) buildx build -f $(subst %,$$*,$(2)) \
    93  		$(DOCKER_BUILD_FLAGS) $(DOCKER_FLAGS) \
    94  		$(if $(BASE_IMAGE),--build-arg BASE_IMAGE=$(BASE_IMAGE),) \
    95  		--build-arg MODIFIERS="NOSTRIP=$${NOSTRIP} NOOPT=${NOOPT} LOCKDEBUG=${LOCKDEBUG} RACE=${RACE} V=${V} LIBNETWORK_PLUGIN=${LIBNETWORK_PLUGIN} ${ADDITIONAL_MODIFIERS}" \
    96  		--build-arg CILIUM_SHA=$(firstword $(GIT_VERSION)) \
    97  		--build-arg OPERATOR_VARIANT=$(IMAGE_NAME) \
    98  		--build-arg DEBUG_HOLD=$(DEBUG_HOLD) \
    99  		--target $(5) \
   100  		-t $(IMAGE_REPOSITORY)/$(IMAGE_NAME)$${UNSTRIPPED}$(DOCKER_IMAGE_SUFFIX):$(4) .
   101  ifneq ($(KIND_LOAD),)
   102  	sleep 1
   103  	kind load docker-image $(IMAGE_REPOSITORY)/$(IMAGE_NAME)$${UNSTRIPPED}$(DOCKER_IMAGE_SUFFIX):$(4)
   104  else
   105      ifeq ($(findstring --push,$(DOCKER_FLAGS)),)
   106  	@echo 'Define "DOCKER_FLAGS=--push" to push the build results.'
   107      else
   108  	$(CONTAINER_ENGINE) buildx imagetools inspect $(IMAGE_REPOSITORY)/$(IMAGE_NAME)$${UNSTRIPPED}$(DOCKER_IMAGE_SUFFIX):$(4)
   109  	@echo '^^^ Images pushed, multi-arch manifest should be above. ^^^'
   110      endif
   111  endif
   112  
   113  $(1)-unstripped: NOSTRIP=1
   114  $(1)-unstripped: UNSTRIPPED=-unstripped
   115  $(1)-unstripped: $(1)
   116  	@echo
   117  endef
   118  
   119  # docker-cilium-image
   120  $(eval $(call DOCKER_IMAGE_TEMPLATE,docker-cilium-image,images/cilium/Dockerfile,cilium,$(DOCKER_IMAGE_TAG),release))
   121  
   122  # dev-docker-image
   123  $(eval $(call DOCKER_IMAGE_TEMPLATE,dev-docker-image,images/cilium/Dockerfile,cilium-dev,$(DOCKER_IMAGE_TAG),release))
   124  
   125  # dev-docker-image-debug
   126  $(eval $(call DOCKER_IMAGE_TEMPLATE,dev-docker-image-debug,images/cilium/Dockerfile,cilium-dev,$(DOCKER_IMAGE_TAG),debug))
   127  
   128  # docker-plugin-image
   129  $(eval $(call DOCKER_IMAGE_TEMPLATE,docker-plugin-image,images/cilium-docker-plugin/Dockerfile,docker-plugin,$(DOCKER_IMAGE_TAG),release))
   130  
   131  # docker-hubble-relay-image
   132  $(eval $(call DOCKER_IMAGE_TEMPLATE,docker-hubble-relay-image,images/hubble-relay/Dockerfile,hubble-relay,$(DOCKER_IMAGE_TAG),release))
   133  
   134  # docker-clustermesh-apiserver-image
   135  $(eval $(call DOCKER_IMAGE_TEMPLATE,docker-clustermesh-apiserver-image,images/clustermesh-apiserver/Dockerfile,clustermesh-apiserver,$(DOCKER_IMAGE_TAG),release))
   136  
   137  # docker-operator-images.
   138  # We eat the ending of "operator" in to the stem ('%') to allow this pattern
   139  # to build also 'docker-operator-image', where the stem would be empty otherwise.
   140  $(eval $(call DOCKER_IMAGE_TEMPLATE,docker-opera%-image,images/operator/Dockerfile,opera%,$(DOCKER_IMAGE_TAG),release))
   141  $(eval $(call DOCKER_IMAGE_TEMPLATE,dev-docker-opera%-image,images/operator/Dockerfile,opera%,$(DOCKER_IMAGE_TAG),release))
   142  $(eval $(call DOCKER_IMAGE_TEMPLATE,dev-docker-opera%-image-debug,images/operator/Dockerfile,opera%,$(DOCKER_IMAGE_TAG),debug))
   143  
   144  #
   145  # docker-*-all targets are mainly used from the CI
   146  #
   147  docker-images-all: docker-cilium-image docker-plugin-image docker-hubble-relay-image docker-clustermesh-apiserver-image docker-operator-images-all ## Build all Cilium related docker images.
   148  
   149  docker-images-all-unstripped: docker-cilium-image-unstripped docker-plugin-image-unstripped docker-hubble-relay-image-unstripped docker-clustermesh-apiserver-image-unstripped docker-operator-images-all-unstripped ## Build all Cilium related unstripped docker images.
   150  
   151  docker-operator-images-all: docker-operator-image docker-operator-aws-image docker-operator-azure-image docker-operator-alibabacloud-image docker-operator-generic-image ## Build all variants of cilium-operator images.
   152  
   153  docker-operator-images-all-unstripped: docker-operator-image-unstripped docker-operator-aws-image-unstripped docker-operator-azure-image-unstripped docker-operator-alibabacloud-image-unstripped docker-operator-generic-image-unstripped ## Build all variants of unstripped cilium-operator images.