diff --git a/Makefile b/Makefile index cf30cbf1d..b0c874558 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,10 @@ ifndef GOARCH GOARCH := $(shell go env GOARCH) endif +ifdef BASE_IMAGE +BASE_IMAGE_ARG = --build-arg BASE_IMAGE=$(BASE_IMAGE) +endif + SELINUX := $(shell getenforce 2>/dev/null) ifeq ($(SELINUX),Enforcing) SELINUX_VOL_FLAG = :z @@ -93,7 +97,7 @@ containerized-test: .test-container-id $(CONTAINER_CMD) inspect -f '{{.Id}}' $(CSI_IMAGE_NAME):test > .test-container-id image-cephcsi: - $(CONTAINER_CMD) build -t $(CSI_IMAGE) -f deploy/cephcsi/image/Dockerfile . --build-arg GOLANG_VERSION=1.13.8 --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) + $(CONTAINER_CMD) build -t $(CSI_IMAGE) -f deploy/cephcsi/image/Dockerfile . --build-arg GOLANG_VERSION=1.13.8 --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) push-image-cephcsi: image-cephcsi $(CONTAINER_CMD) tag $(CSI_IMAGE) $(CSI_IMAGE)-$(GOARCH) diff --git a/build-multi-arch-image.sh b/build-multi-arch-image.sh index 72dc64888..1edf57880 100755 --- a/build-multi-arch-image.sh +++ b/build-multi-arch-image.sh @@ -26,6 +26,6 @@ for ARCH in amd64 arm64; do IFS= digest=$(awk -v ARCH=${ARCH} '{if (archfound) {print $NF; exit 0}}; {archfound=($0 ~ "arch.*"ARCH)}' <<<"${manifests}") IFS=$ifs - sed -i "s|\(^FROM.*\)${baseimg}.*$|\1${baseimg}@${digest}|" "${dockerfile}" - GOARCH=${ARCH} make image-cephcsi + base_img=${baseimg}@${digest} + GOARCH=${ARCH} BASE_IMAGE=${base_img} make image-cephcsi done diff --git a/deploy.sh b/deploy.sh index 1965dc332..49bf129e4 100755 --- a/deploy.sh +++ b/deploy.sh @@ -67,8 +67,8 @@ build_push_images() { IFS= digest=$(awk -v ARCH=${ARCH} '{if (archfound) {print $NF; exit 0}}; {archfound=($0 ~ "arch.*"ARCH)}' <<<"${manifests}") IFS=$ifs - sed -i "s|\(^FROM.*\)${baseimg}.*$|\1${baseimg}@${digest}|" "${dockerfile}" - GOARCH=${ARCH} make push-image-cephcsi + base_image=${baseimg}@${digest} + GOARCH=${ARCH} BASE_IMAGE=${base_image} make push-image-cephcsi done } diff --git a/deploy/cephcsi/image/Dockerfile b/deploy/cephcsi/image/Dockerfile index f73e85542..03b2adf12 100644 --- a/deploy/cephcsi/image/Dockerfile +++ b/deploy/cephcsi/image/Dockerfile @@ -1,6 +1,8 @@ ARG SRC_DIR="/go/src/github.com/ceph/ceph-csi/" ARG GO_ARCH -FROM ceph/ceph:v15 +ARG BASE_IMAGE=ceph/ceph:v15 + +FROM ${BASE_IMAGE} as builder LABEL stage="build" @@ -35,7 +37,7 @@ COPY . ${SRC_DIR} RUN make cephcsi #-- Final container -FROM ceph/ceph:v15 +FROM ${BASE_IMAGE} ARG SRC_DIR @@ -44,6 +46,6 @@ LABEL maintainers="Ceph-CSI Authors" \ architecture=${GO_ARCH} \ description="Ceph-CSI Plugin" -COPY --from=0 ${SRC_DIR}/_output/cephcsi /usr/local/bin/cephcsi +COPY --from=builder ${SRC_DIR}/_output/cephcsi /usr/local/bin/cephcsi ENTRYPOINT ["/usr/local/bin/cephcsi"]