|
| 1 | + |
| 2 | +# Copyright 2020 The OpenEBS Authors. All rights reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# Build lvm-driver docker images with buildx |
| 17 | +# Experimental docker feature to build cross platform multi-architecture docker images |
| 18 | +# https://docs.docker.com/buildx/working-with-buildx/ |
| 19 | + |
| 20 | +ifeq (${TAG}, ) |
| 21 | + export TAG=ci |
| 22 | +endif |
| 23 | + |
| 24 | +# default list of platforms for which multiarch image is built |
| 25 | +ifeq (${PLATFORMS}, ) |
| 26 | + export PLATFORMS="linux/amd64,linux/arm64" |
| 27 | +endif |
| 28 | + |
| 29 | +# if IMG_RESULT is unspecified, by default the image will be pushed to registry |
| 30 | +ifeq (${IMG_RESULT}, load) |
| 31 | + export PUSH_ARG="--load" |
| 32 | + # if load is specified, image will be built only for the build machine architecture. |
| 33 | + export PLATFORMS="local" |
| 34 | +else ifeq (${IMG_RESULT}, cache) |
| 35 | + # if cache is specified, image will only be available in the build cache, it won't be pushed or loaded |
| 36 | + # therefore no PUSH_ARG will be specified |
| 37 | +else |
| 38 | + export PUSH_ARG="--push" |
| 39 | +endif |
| 40 | + |
| 41 | +# Name of the multiarch image for csi-driver |
| 42 | +DOCKERX_IMAGE_CSI_DRIVER:=${IMAGE_ORG}/lvm-driver:${TAG} |
| 43 | + |
| 44 | +.PHONY: docker.buildx |
| 45 | +docker.buildx: |
| 46 | + export DOCKER_CLI_EXPERIMENTAL=enabled |
| 47 | + @if ! docker buildx ls | grep -q container-builder; then\ |
| 48 | + docker buildx create --platform ${PLATFORMS} --name container-builder --use;\ |
| 49 | + fi |
| 50 | + @docker buildx build --platform "${PLATFORMS}" \ |
| 51 | + -t "$(DOCKERX_IMAGE_NAME)" ${BUILD_ARGS} \ |
| 52 | + -f $(PWD)/buildscripts/$(COMPONENT)/Dockerfile.buildx \ |
| 53 | + . ${PUSH_ARG} |
| 54 | + @echo "--> Build docker image: $(DOCKERX_IMAGE_NAME)" |
| 55 | + @echo |
| 56 | + |
| 57 | +.PHONY: buildx.csi-driver |
| 58 | +buildx.csi-driver: |
| 59 | + @echo '--> Building csi-driver binary...' |
| 60 | + @pwd |
| 61 | + @PNAME=${CSI_DRIVER} CTLNAME=${CSI_DRIVER} BUILDX=true sh -c "'$(PWD)/buildscripts/build.sh'" |
| 62 | + @echo '--> Built binary.' |
| 63 | + @echo |
| 64 | + |
| 65 | +.PHONY: docker.buildx.csi-driver |
| 66 | +docker.buildx.csi-driver: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_CSI_DRIVER) |
| 67 | +docker.buildx.csi-driver: COMPONENT=$(CSI_DRIVER) |
| 68 | +docker.buildx.csi-driver: BUILD_ARGS=$(DBUILD_ARGS) |
| 69 | +docker.buildx.csi-driver: docker.buildx |
| 70 | + |
| 71 | + |
| 72 | +.PHONY: buildx.push.csi-driver |
| 73 | +buildx.push.csi-driver: |
| 74 | + BUILDX=true DIMAGE=${IMAGE_ORG}/lvm-driver ./buildscripts/push |
0 commit comments