mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-24 21:14:00 +00:00
Skip publishing of images if these already exist
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
731c99b52c
commit
7a1f23e2e4
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
BUILD_MULTI_ARCH_IMAGES ?= false
|
BUILD_MULTI_ARCH_IMAGES ?= false
|
||||||
DOCKER ?= docker
|
DOCKER ?= docker
|
||||||
|
REGCTL ?= regctl
|
||||||
|
|
||||||
BUILDX =
|
BUILDX =
|
||||||
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
|
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
|
||||||
@ -74,6 +75,14 @@ endif
|
|||||||
push-%: DIST = $(*)
|
push-%: DIST = $(*)
|
||||||
push-short: DIST = $(DEFAULT_PUSH_TARGET)
|
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-%: DIST = $(*)
|
||||||
build-%: DOCKERFILE = $(CURDIR)/build/container/Dockerfile.$(DOCKERFILE_SUFFIX)
|
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_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD)
|
||||||
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64
|
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
|
# We only have x86_64 packages for centos7
|
||||||
build-centos7: DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
|
build-centos7: DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
|
||||||
|
|
||||||
|
@ -13,11 +13,3 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
|
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