diff --git a/Makefile b/Makefile index 9a5c0de1d..c18013a1a 100644 --- a/Makefile +++ b/Makefile @@ -43,9 +43,7 @@ ifndef GOARCH GOARCH := $(shell go env GOARCH 2>/dev/null) endif -ifdef BASE_IMAGE -BASE_IMAGE_ARG = --build-arg BASE_IMAGE=$(BASE_IMAGE) -endif +BASE_IMAGE ?= $(shell . $(CURDIR)/build.env ; echo $${BASE_IMAGE}) # passing TARGET=static-check on the 'make containerized-test' or 'make # containerized-build' commandline will run the selected target instead of @@ -133,7 +131,7 @@ containerized-test: .test-container-id # create a (cached) container image with dependencied for building cephcsi .devel-container-id: scripts/Dockerfile.devel [ ! -f .devel-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):devel - $(CONTAINER_CMD) build $(CPUSET) -t $(CSI_IMAGE_NAME):devel -f ./scripts/Dockerfile.devel . + $(CONTAINER_CMD) build $(CPUSET) --build-arg BASE_IMAGE=$(BASE_IMAGE) -t $(CSI_IMAGE_NAME):devel -f ./scripts/Dockerfile.devel . $(CONTAINER_CMD) inspect -f '{{.Id}}' $(CSI_IMAGE_NAME):devel > .devel-container-id # create a (cached) container image with dependencied for testing cephcsi @@ -143,7 +141,7 @@ containerized-test: .test-container-id $(CONTAINER_CMD) inspect -f '{{.Id}}' $(CSI_IMAGE_NAME):test > .test-container-id image-cephcsi: - $(CONTAINER_CMD) build $(CPUSET) -t $(CSI_IMAGE) -f deploy/cephcsi/image/Dockerfile . --build-arg CSI_IMAGE_NAME=$(CSI_IMAGE_NAME) --build-arg CSI_IMAGE_VERSION=$(CSI_IMAGE_VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg GO_ARCH=$(GOARCH) $(BASE_IMAGE_ARG) + $(CONTAINER_CMD) build $(CPUSET) -t $(CSI_IMAGE) -f deploy/cephcsi/image/Dockerfile . --build-arg CSI_IMAGE_NAME=$(CSI_IMAGE_NAME) --build-arg CSI_IMAGE_VERSION=$(CSI_IMAGE_VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg GO_ARCH=$(GOARCH) --build-arg BASE_IMAGE=$(BASE_IMAGE) push-image-cephcsi: image-cephcsi $(CONTAINER_CMD) tag $(CSI_IMAGE) $(CSI_IMAGE)-$(GOARCH) diff --git a/build.env b/build.env index 6156754bb..ecce0c471 100644 --- a/build.env +++ b/build.env @@ -9,6 +9,9 @@ # get proporly expanded. # +# Ceph version to use +BASE_IMAGE=ceph/ceph:v15 + # standard Golang options GOLANG_VERSION=1.13.9 GO111MODULE=on diff --git a/deploy.sh b/deploy.sh index b4ba8c723..07e8b47e7 100755 --- a/deploy.sh +++ b/deploy.sh @@ -40,7 +40,7 @@ push_helm_charts() { } # Build and push images. Steps as below: -# 1. get base image from original Dockerfile (FROM ceph/ceph:v14.2) +# 1. get base image from ./build.env (BASE_IMAGE=ceph/ceph:v14.2) # 2. parse manifest to get image digest per arch (sha256:XXX, sha256:YYY) # 3. patch Dockerfile with amd64 base image (FROM ceph/ceph:v14.2@sha256:XXX) # 4. build and push amd64 image @@ -50,8 +50,8 @@ build_push_images() { # "docker manifest" requires experimental feature enabled export DOCKER_CLI_EXPERIMENTAL=enabled - dockerfile="deploy/cephcsi/image/Dockerfile" - baseimg=$(awk -F = '/^ARG BASE_IMAGE=/ {print $NF}' "${dockerfile}") + build_env="build.env" + baseimg=$(awk -F = '/^BASE_IMAGE=/ {print $NF}' "${build_env}") # get image digest per architecture # { diff --git a/deploy/cephcsi/image/Dockerfile b/deploy/cephcsi/image/Dockerfile index c8438f768..3f9842cbe 100644 --- a/deploy/cephcsi/image/Dockerfile +++ b/deploy/cephcsi/image/Dockerfile @@ -1,6 +1,6 @@ ARG SRC_DIR="/go/src/github.com/ceph/ceph-csi/" ARG GO_ARCH -ARG BASE_IMAGE=ceph/ceph:v15 +ARG BASE_IMAGE FROM ${BASE_IMAGE} as builder diff --git a/scripts/Dockerfile.devel b/scripts/Dockerfile.devel index 0c1494ae4..d4d81f98b 100644 --- a/scripts/Dockerfile.devel +++ b/scripts/Dockerfile.devel @@ -1,4 +1,5 @@ -FROM ceph/ceph:v15 +ARG BASE_IMAGE +FROM ${BASE_IMAGE} ARG GOROOT=/usr/local/go diff --git a/scripts/build-multi-arch-image.sh b/scripts/build-multi-arch-image.sh index 08656d1b4..38d138c78 100755 --- a/scripts/build-multi-arch-image.sh +++ b/scripts/build-multi-arch-image.sh @@ -10,8 +10,8 @@ export DOCKER_CLI_EXPERIMENTAL=enabled cd "$(dirname "${0}")/.." # ceph base image used for building multi architecture images -dockerfile="deploy/cephcsi/image/Dockerfile" -baseimg=$(awk -F = '/^ARG BASE_IMAGE=/ {print $NF}' "${dockerfile}") +build_env="build.env" +baseimg=$(awk -F = '/^BASE_IMAGE=/ {print $NF}' "${build_env}") # get image digest per architecture # {