mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 21:39:10 +00:00
Merge branch 'CNT-4259/check-for-images-before-release' into 'main'
Skip publishing of images if these already exist See merge request nvidia/container-toolkit/container-toolkit!385
This commit is contained in:
commit
1991138185
@ -245,6 +245,8 @@ test-packaging:
|
||||
.release:external:
|
||||
extends:
|
||||
- .release
|
||||
variables:
|
||||
FORCE_PUBLISH_IMAGES: "yes"
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
variables:
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
BUILD_MULTI_ARCH_IMAGES ?= false
|
||||
DOCKER ?= docker
|
||||
REGCTL ?= regctl
|
||||
|
||||
BUILDX =
|
||||
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
|
||||
@ -74,6 +75,14 @@ endif
|
||||
push-%: DIST = $(*)
|
||||
push-short: DIST = $(DEFAULT_PUSH_TARGET)
|
||||
|
||||
# Define the push targets
|
||||
$(PUSH_TARGETS): push-%:
|
||||
$(CURDIR)/scripts/publish-image.sh $(IMAGE) $(OUT_IMAGE)
|
||||
|
||||
push-short:
|
||||
$(CURDIR)/scripts/publish-image.sh $(IMAGE) $(OUT_IMAGE)
|
||||
|
||||
|
||||
build-%: DIST = $(*)
|
||||
build-%: DOCKERFILE = $(CURDIR)/build/container/Dockerfile.$(DOCKERFILE_SUFFIX)
|
||||
|
||||
|
@ -16,17 +16,6 @@ PUSH_ON_BUILD ?= false
|
||||
DOCKER_BUILD_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD)
|
||||
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64
|
||||
|
||||
REGCTL ?= regctl
|
||||
$(PUSH_TARGETS): push-%:
|
||||
$(REGCTL) \
|
||||
image copy \
|
||||
$(IMAGE) $(OUT_IMAGE)
|
||||
|
||||
push-short:
|
||||
$(REGCTL) \
|
||||
image copy \
|
||||
$(IMAGE) $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)
|
||||
|
||||
# We only have x86_64 packages for centos7
|
||||
build-centos7: DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
|
||||
|
||||
|
@ -13,11 +13,3 @@
|
||||
# limitations under the License.
|
||||
|
||||
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
|
||||
|
||||
$(PUSH_TARGETS): push-%:
|
||||
$(DOCKER) tag "$(IMAGE)" "$(OUT_IMAGE)"
|
||||
$(DOCKER) push "$(OUT_IMAGE)"
|
||||
|
||||
push-short:
|
||||
$(DOCKER) tag "$(IMAGE_NAME):$(VERSION)-$(DEFAULT_PUSH_TARGET)" "$(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)"
|
||||
$(DOCKER) push "$(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)"
|
||||
|
59
scripts/publish-image.sh
Executable file
59
scripts/publish-image.sh
Executable file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright (c) NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This script is used to publish images to a registry. It checks whether the image
|
||||
# already exists in the registry and skips publishing if it does. This can be overridden
|
||||
# using the FORCE_PUBLISH_IMAGES environment variable.
|
||||
|
||||
set -ex
|
||||
|
||||
: ${DOCKER=docker}
|
||||
: ${REGCTL=regctl}
|
||||
|
||||
INPUT_IMAGE=$1
|
||||
OUTPUT_IMAGE=$2
|
||||
|
||||
function publish_docker() {
|
||||
${DOCKER} tag ${1} ${2}
|
||||
${DOCKER} push ${2}
|
||||
}
|
||||
|
||||
function publish_regctl() {
|
||||
${REGCTL} image copy ${1} ${2}
|
||||
}
|
||||
|
||||
function publish() {
|
||||
if [[ x"${BUILD_MULTI_ARCH_IMAGES}" == x"true" || $(command -v ${REGCTL}) ]]; then
|
||||
publish_regctl $@
|
||||
else
|
||||
publish_docker $@
|
||||
fi
|
||||
}
|
||||
|
||||
# image_exists returns 0 if the image exists in a registry and a non-zero return
|
||||
# code if this is not the case.
|
||||
function image_exists() {
|
||||
local image=$1
|
||||
${DOCKER} manifest inspect ${image}
|
||||
}
|
||||
|
||||
if [[ -z ${FORCE_PUBLISH_IMAGES} && $(image_exists ${OUTPUT_IMAGE}) ]]; then
|
||||
echo "Skipping publishing of ${INPUT_IMAGE} as ${OUTPUT_IMAGE} already exists"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Publishing ${INPUT_IMAGE} as ${OUTPUT_IMAGE}"
|
||||
publish ${INPUT_IMAGE} ${OUTPUT_IMAGE}
|
Loading…
Reference in New Issue
Block a user