github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/Makefile.buildx.mk (about)

     1  # Copyright 2018-2020 The OpenEBS Authors. All rights reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  # ==============================================================================
    16  # Build Options
    17  
    18  ifeq (${TAG}, )
    19    export TAG=ci
    20  endif
    21  
    22  # default list of platforms for which multiarch image is built
    23  ifeq (${PLATFORMS}, )
    24  	export PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le"
    25  endif
    26  
    27  # if IMG_RESULT is unspecified, by default the image will be pushed to registry
    28  ifeq (${IMG_RESULT}, load)
    29  	export PUSH_ARG="--load"
    30      # if load is specified, image will be built only for the build machine architecture.
    31      export PLATFORMS="local"
    32  else ifeq (${IMG_RESULT}, cache)
    33  	# if cache is specified, image will only be available in the build cache, it won't be pushed or loaded
    34  	# therefore no PUSH_ARG will be specified
    35  else
    36  	export PUSH_ARG="--push"
    37  endif
    38  
    39  # Name of the multiarch image for NDM DaemoneSet
    40  DOCKERX_IMAGE_NDM:=${IMAGE_ORG}/node-disk-manager:${TAG}
    41  
    42  # Name of the multiarch image for ndm operator
    43  DOCKERX_IMAGE_NDO:=${IMAGE_ORG}/node-disk-operator:${TAG}
    44  
    45  # Name of the multiarch image for ndm exporter
    46  DOCKERX_IMAGE_EXPORTER:=${IMAGE_ORG}/node-disk-exporter:${TAG}
    47  
    48  # Build ndm docker image with buildx
    49  # Experimental docker feature to build cross platform multi-architecture docker images
    50  # https://docs.docker.com/buildx/working-with-buildx/
    51  
    52  .PHONY: docker.buildx
    53  docker.buildx:
    54  	export DOCKER_CLI_EXPERIMENTAL=enabled
    55  	@if ! docker buildx ls | grep -q container-builder; then\
    56  		docker buildx create --platform ${PLATFORMS} --name container-builder --use;\
    57  	fi
    58  	@docker buildx build --platform ${PLATFORMS} \
    59  		-t "$(DOCKERX_IMAGE_NAME)" ${DBUILD_ARGS} -f $(PWD)/build/$(COMPONENT)/Dockerfile \
    60  		. ${PUSH_ARG}
    61  	@echo "--> Build docker image: $(DOCKERX_IMAGE_NAME)"
    62  	@echo
    63  
    64  # Install dependencies if NODEPINSTALL arg not passed during invocation
    65  ifndef NODEPINSTALL
    66  buildx.ndm buildx.ndo buildx.exporter: install-dep-nonsudo
    67  endif
    68  
    69  .PHONY: buildx.ndm
    70  buildx.ndm: bootstrap clean build.common
    71  	@echo '--> Building node-disk-manager binary...'
    72  	@pwd
    73  	@CTLNAME=${NODE_DISK_MANAGER} BUILDPATH=${BUILD_PATH_NDM} BUILDX=true sh -c "'$(PWD)/build/build.sh'"
    74  	@echo '--> Built binary.'
    75  	@echo
    76  
    77  .PHONY: docker.buildx.ndm
    78  docker.buildx.ndm: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_NDM)
    79  docker.buildx.ndm: COMPONENT=ndm-daemonset
    80  docker.buildx.ndm: docker.buildx
    81  
    82  .PHONY: buildx.ndo
    83  buildx.ndo: bootstrap clean build.common
    84  	@echo '--> Building node-disk-operator binary...'
    85  	@pwd
    86  	@CTLNAME=${NODE_DISK_OPERATOR} BUILDPATH=${BUILD_PATH_NDO} BUILDX=true sh -c "'$(PWD)/build/build.sh'"
    87  	@echo '--> Built binary.'
    88  	@echo
    89  
    90  .PHONY: docker.buildx.ndo
    91  docker.buildx.ndo: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_NDO)
    92  docker.buildx.ndo: COMPONENT=ndm-operator
    93  docker.buildx.ndo: docker.buildx
    94  
    95  .PHONY: buildx.exporter
    96  buildx.exporter: bootstrap clean build.common
    97  	@echo '--> Building node-disk-exporter binary...'
    98  	@pwd
    99  	@CTLNAME=${NODE_DISK_EXPORTER} BUILDPATH=${BUILD_PATH_EXPORTER} BUILDX=true sh -c "'$(PWD)/build/build.sh'"
   100  	@echo '--> Built binary.'
   101  	@echo
   102  
   103  .PHONY: docker.buildx.exporter
   104  docker.buildx.exporter: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_EXPORTER)
   105  docker.buildx.exporter: COMPONENT=ndm-exporter
   106  docker.buildx.exporter: docker.buildx
   107  
   108  .PHONY: install-dep-nonsudo
   109  install-dep-nonsudo:
   110  	@echo "--> Installing external dependencies for building node-disk-manager"
   111  	$(PWD)/build/install-dep.sh
   112  
   113  .PHONY: buildx.push.ndm
   114  buildx.push.ndm:
   115  	BUILDX=true DIMAGE=${IMAGE_ORG}/node-disk-manager ./build/push
   116  
   117  .PHONY: buildx.push.exporter
   118  buildx.push.exporter:
   119  	BUILDX=true DIMAGE=${IMAGE_ORG}/node-disk-exporter ./build/push
   120  
   121  .PHONY: buildx.push.ndo
   122  buildx.push.ndo:
   123  	BUILDX=true DIMAGE=${IMAGE_ORG}/node-disk-operator ./build/push