|
| 1 | +# Copyright 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 | +# IMAGE_ORG can be used to customize the organization |
| 16 | +# under which images should be pushed. |
| 17 | +# By default the organization name is `openebs`. |
| 18 | + |
| 19 | +ifeq (${IMAGE_ORG}, ) |
| 20 | + IMAGE_ORG = openebs |
| 21 | + export IMAGE_ORG |
| 22 | +endif |
| 23 | + |
| 24 | +# Specify the date of build |
| 25 | +DBUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 26 | + |
| 27 | +# Specify the docker arg for repository url |
| 28 | +ifeq (${DBUILD_REPO_URL}, ) |
| 29 | + DBUILD_REPO_URL="https://github.com/openebs/istgt" |
| 30 | + export DBUILD_REPO_URL |
| 31 | +endif |
| 32 | + |
| 33 | +# Specify the docker arg for website url |
| 34 | +ifeq (${DBUILD_SITE_URL}, ) |
| 35 | + DBUILD_SITE_URL="https://openebs.io" |
| 36 | + export DBUILD_SITE_URL |
| 37 | +endif |
| 38 | + |
| 39 | +# ============================================================================== |
| 40 | +# Build Options |
| 41 | + |
| 42 | +export DBUILD_ARGS=--build-arg DBUILD_DATE=${DBUILD_DATE} --build-arg DBUILD_REPO_URL=${DBUILD_REPO_URL} --build-arg DBUILD_SITE_URL=${DBUILD_SITE_URL} |
| 43 | + |
| 44 | +ifeq (${TAG}, ) |
| 45 | + export TAG=ci |
| 46 | +endif |
| 47 | + |
| 48 | + |
| 49 | +# Build istgt docker image with buildx |
| 50 | +# Experimental docker feature to build cross platform multi-architecture docker images |
| 51 | +# https://docs.docker.com/buildx/working-with-buildx/ |
| 52 | + |
| 53 | +# default list of platforms for which multiarch image is built |
| 54 | +ifeq (${PLATFORMS}, ) |
| 55 | + export PLATFORMS="linux/amd64,linux/arm64,linux/ppc64le" |
| 56 | +endif |
| 57 | + |
| 58 | +# if IMG_RESULT is unspecified, by default the image will be pushed to registry |
| 59 | +ifeq (${IMG_RESULT}, load) |
| 60 | + export PUSH_ARG="--load" |
| 61 | + # if load is specified, image will be built only for the build machine architecture. |
| 62 | + export PLATFORMS="local" |
| 63 | +else ifeq (${IMG_RESULT}, cache) |
| 64 | + # if cache is specified, image will only be available in the build cache, it won't be pushed or loaded |
| 65 | + # therefore no PUSH_ARG will be specified |
| 66 | +else |
| 67 | + export PUSH_ARG="--push" |
| 68 | +endif |
| 69 | + |
| 70 | +# Name of the multiarch image for istgt |
| 71 | +DOCKERX_IMAGE_ISTGT:=${IMAGE_ORG}/cstor-istgt:${TAG} |
| 72 | + |
| 73 | +# COMPONENT names for image builds |
| 74 | +ISTGT:=istgt |
| 75 | + |
| 76 | +.PHONY: docker.buildx |
| 77 | +docker.buildx: |
| 78 | + export DOCKER_CLI_EXPERIMENTAL=enabled |
| 79 | + @if ! docker buildx ls | grep -q container-builder; then\ |
| 80 | + docker buildx create --platform ${PLATFORMS} --name container-builder --use;\ |
| 81 | + fi |
| 82 | + @docker buildx build --platform ${PLATFORMS} \ |
| 83 | + -t "$(DOCKERX_IMAGE_NAME)" ${DBUILD_ARGS} -f $(PWD)/docker/$(COMPONENT).Dockerfile \ |
| 84 | + . ${PUSH_ARG} |
| 85 | + @echo "--> Build docker image: $(DOCKERX_IMAGE_NAME)" |
| 86 | + @echo |
| 87 | + |
| 88 | +.PHONY: docker.buildx.istgt |
| 89 | +docker.buildx.istgt: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_ISTGT) |
| 90 | +docker.buildx.istgt: COMPONENT=$(ISTGT) |
| 91 | +docker.buildx.istgt: docker.buildx |
| 92 | + |
| 93 | +.PHONY: buildx.push.istgt |
| 94 | +buildx.push.istgt: |
| 95 | + BUILDX=true DIMAGE=${IMAGE_ORG}/istgt ./docker/buildxpush.sh |
0 commit comments