Skip to content

Commit 5119527

Browse files
committed
Improve image publishing
Signed-off-by: Evan Lezar <[email protected]>
1 parent 99e6ed6 commit 5119527

File tree

6 files changed

+91
-69
lines changed

6 files changed

+91
-69
lines changed

.common-ci.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ stages:
6161
variables:
6262
SAMPLE: vectorAdd
6363
LOWER_CASE_SAMPLE: vectoradd
64-
PUSH_SAMPLE_ONLY_TAG: "false"
6564

6665
.sample-nbody:
6766
variables:
@@ -73,39 +72,35 @@ stages:
7372
variables:
7473
SAMPLE: deviceQuery
7574
LOWER_CASE_SAMPLE: devicequery
76-
PUSH_SAMPLE_ONLY_TAG: "true"
7775

7876
.sample-simple-multi-gpu:
7977
variables:
8078
SAMPLE: simpleMultiGPU
8179
LOWER_CASE_SAMPLE: simplemultigpu
82-
PUSH_SAMPLE_ONLY_TAG: "true"
8380

8481
# Define the sample targets
8582
.sample-vulkan:
8683
variables:
8784
SAMPLE: vulkan
8885
LOWER_CASE_SAMPLE: vulkan
89-
PUSH_SAMPLE_ONLY_TAG: "true"
9086

9187
.sample-nvbandwidth:
9288
variables:
9389
SAMPLE: nvbandwidth
9490
LOWER_CASE_SAMPLE: nvbandwidth
95-
PUSH_SAMPLE_ONLY_TAG: "true"
9691

9792
# Make buildx available as a docker CLI plugin
9893
.buildx-setup:
9994
before_script:
100-
- export BUILDX_VERSION=v0.6.3
101-
- apk add --no-cache curl
102-
- mkdir -p ~/.docker/cli-plugins
103-
- curl -sSLo ~/.docker/cli-plugins/docker-buildx "https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-amd64"
104-
- chmod a+x ~/.docker/cli-plugins/docker-buildx
95+
- export BUILDX_VERSION=v0.6.3
96+
- apk add --no-cache curl
97+
- mkdir -p ~/.docker/cli-plugins
98+
- curl -sSLo ~/.docker/cli-plugins/docker-buildx "https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-amd64"
99+
- chmod a+x ~/.docker/cli-plugins/docker-buildx
105100

106-
- docker buildx create --use --platform=linux/amd64,linux/arm64
101+
- docker buildx create --use --platform=linux/amd64,linux/arm64
107102

108-
- '[[ -n "${SKIP_QEMU_SETUP}" ]] || docker run --rm --privileged multiarch/qemu-user-static --reset -p yes'
103+
- '[[ -n "${SKIP_QEMU_SETUP}" ]] || docker run --rm --privileged multiarch/qemu-user-static --reset -p yes'
109104

110105
# Download the regctl binary for use in the release steps
111106
.regctl-setup:
@@ -121,8 +116,7 @@ stages:
121116
# This is extended with the version to be deployed (e.g. the SHA or TAG) and the
122117
# target os.
123118
.release:
124-
stage:
125-
release
119+
stage: release
126120
variables:
127121
# Define the source image for the release
128122
IMAGE_NAME: "${CI_REGISTRY_IMAGE}/cuda-samples"

.nvidia-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
include:
16-
- local: '.common-ci.yml'
16+
- local: ".common-ci.yml"
1717

1818
default:
1919
tags:
@@ -47,7 +47,6 @@ variables:
4747
OUT_REGISTRY: "${CI_REGISTRY}"
4848
OUT_IMAGE_NAME: ${CI_REGISTRY_IMAGE}/cuda-samples
4949
OUT_VERSION: ${LOWER_CASE_SAMPLE}-${CI_COMMIT_SHORT_SHA}
50-
PUSH_MULTIPLE_TAGS: "false"
5150
# We delay the job start to allow the public pipeline to generate the required images.
5251
when: delayed
5352
start_in: 30 minutes
@@ -64,7 +63,8 @@ variables:
6463
regctl manifest get ${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} --list > /dev/null && echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST}" || ( echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} does not exist" && sleep infinity )
6564
script:
6665
- regctl registry login "${OUT_REGISTRY}" -u "${OUT_REGISTRY_USER}" -p "${OUT_REGISTRY_TOKEN}"
67-
- make -f deployments/container/Makefile IMAGE=${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} OUT_IMAGE=${OUT_IMAGE_NAME}:${OUT_VERSION}-${DIST} push-${DIST}
66+
# We use the publish-images.sh script to pull the images from IN_REGISTRY into the CI_REGISTRY.
67+
- ./hack/publish-images.sh ${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} ${OUT_IMAGE_NAME}:${OUT_VERSION}-${DIST}
6868

6969
image-vectoradd-ubuntu22.04:
7070
extends:

deployments/container/Makefile

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ include $(CURDIR)/versions.mk
2121

2222
# The Makefile describes the build process for a single CUDA sample: e.g. `vectorAdd`
2323
ifeq ($(SAMPLE),)
24-
# Use vectorAdd as the default sample
25-
SAMPLE := vectorAdd
24+
$(error "SAMPLE is unset")
2625
endif
2726
LOWER_CASE_SAMPLE := $(shell echo $(SAMPLE) | tr '[:upper:]' '[:lower:]')
2827

@@ -76,24 +75,11 @@ include $(CURDIR)/deployments/container/multi-arch.mk
7675
endif
7776

7877
push-%: DIST = $(*)
79-
push-short: DIST = $(DEFAULT_PUSH_TARGET)
80-
push-sample: DIST = $(DEFAULT_PUSH_TARGET)
81-
82-
# For the default push target we also push a short tag equal to the version.
83-
# We skip this for the development release
84-
DEVEL_RELEASE_IMAGE_VERSION ?= devel
85-
PUSH_MULTIPLE_TAGS ?= true
86-
PUSH_SAMPLE_ONLY_TAG ?= false
87-
ifeq ($(strip $(OUT_IMAGE_VERSION)),$(DEVEL_RELEASE_IMAGE_VERSION))
88-
PUSH_MULTIPLE_TAGS = false
89-
endif
90-
ifeq ($(PUSH_MULTIPLE_TAGS),true)
91-
push-$(DEFAULT_PUSH_TARGET): push-short
92-
# If required we retag and push the image tagged only with the sample name
93-
ifeq ($(PUSH_SAMPLE_ONLY_TAG),true)
94-
push-$(DEFAULT_PUSH_TARGET): push-sample
95-
endif
96-
endif
78+
79+
# For the default push target we also push a short tag equal to the sample and version.
80+
SHORT_IMAGE_TAG = $(LOWER_CASE_SAMPLE)-$(OUT_IMAGE_VERSION)
81+
SAMPLE_ONLY_IMAGE_TAG = $(LOWER_CASE_SAMPLE)
82+
push-$(DEFAULT_PUSH_TARGET): OUT_IMAGE_ALIASES = $(patsubst %,$(OUT_IMAGE_NAME):%,$(SHORT_IMAGE_TAG) $(SAMPLE_ONLY_IMAGE_TAG))
9783

9884
build-%: DIST = $(*)
9985
# For the following samples, we use specific Dockerfiles:
@@ -120,19 +106,11 @@ $(IMAGE_TARGETS): image-%:
120106
-f $(DOCKERFILE) \
121107
$(CURDIR)
122108

123-
# Handle the default build target.
124-
.PHONY: build
125-
build: $(DEFAULT_PUSH_TARGET)
126-
$(DEFAULT_PUSH_TARGET): build-$(DEFAULT_PUSH_TARGET)
127-
$(DEFAULT_PUSH_TARGET): DIST = $(DEFAULT_PUSH_TARGET)
128-
129-
REGCTL ?= regctl
130-
$(PUSH_TARGETS): push-%:
131-
$(REGCTL) \
132-
image copy \
133-
$(IMAGE) $(OUT_IMAGE)
134-
135-
push-short:
136-
$(REGCTL) \
137-
image copy \
138-
$(IMAGE) $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)
109+
110+
# If PUSH_ON_BUILD is set
111+
ifeq ($(PUSH_ON_BUILD),true)
112+
$(BUILD_TARGETS): build-%: image-%
113+
$(CURDIR)/hack/publish-images.sh $(IMAGE) $(OUT_IMAGE) $(OUT_IMAGE_ALIASES)
114+
else
115+
$(BUILD_TARGETS): build-%: image-%
116+
endif

deployments/container/multi-arch.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ PUSH_ON_BUILD ?= false
1616
DOCKER_BUILD_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD)
1717
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64
1818

19-
$(BUILD_TARGETS): build-%: image-%
19+
# If we're using --putput=type=image,push=true we need
20+
# to skip the first image in the list of images passed to either
21+
# publish-images.sh script.
22+
# TODO: Is there a more "stable" way to handle this.
23+
SKIP_FIRST_IMAGE_ON_PUBLISH = $(PUSH_ON_BUILD)

deployments/container/native-only.mk

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,3 @@
1515
PUSH_ON_BUILD ?= false
1616
ARCH ?= $(shell uname -m)
1717
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/$(ARCH)
18-
19-
ifeq ($(PUSH_ON_BUILD),true)
20-
$(BUILD_TARGETS): build-%: image-%
21-
$(DOCKER) push "$(IMAGE)"
22-
else
23-
$(BUILD_TARGETS): build-%: image-%
24-
endif
25-
26-
# For the default distribution we also retag the image.
27-
# Note: This needs to be updated for multi-arch images.
28-
ifeq ($(IMAGE_TAG),$(VERSION)-$(DIST))
29-
$(DEFAULT_PUSH_TARGET):
30-
$(DOCKER) image inspect $(IMAGE) > /dev/null || $(DOCKER) pull $(IMAGE)
31-
$(DOCKER) tag $(IMAGE) $(subst :$(IMAGE_TAG),:$(VERSION),$(IMAGE))
32-
endif

hack/publish-images.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# This script is used to publish images to a registry. It checks whether the image
19+
# already exists in the registry and skips publishing if it does. This can be overridden
20+
# using the FORCE_PUBLISH_IMAGES environment variable.
21+
22+
set -ex
23+
24+
: ${DOCKER=docker}
25+
: ${REGCTL=regctl}
26+
27+
# publish_docker uses docker to publish an image.
28+
# In this case, the image is first retagged (if required) and then pushed.
29+
function publish_docker() {
30+
if [[ "${1}" != "${2}" ]]; then
31+
${DOCKER} tag ${1} ${2}
32+
fi
33+
${DOCKER} push ${2}
34+
}
35+
36+
# publish_regctl uses regctl to copy an image from one registry to another.
37+
# If the two images are the same, this is a no-op.
38+
function publish_regctl() {
39+
if [[ "${1}" != "${2}" ]]; then
40+
${REGCTL} image copy ${1} ${2}
41+
fi
42+
}
43+
44+
function publish() {
45+
if [[ $(command -v ${REGCTL}) || x"${BUILD_MULTI_ARCH_IMAGES}" == x"true" ]]; then
46+
publish_regctl $@
47+
else
48+
publish_docker $@
49+
fi
50+
}
51+
52+
INPUT_IMAGE=$1
53+
shift
54+
if [[ x"${SKIP_FIRST_IMAGE_ON_PUBLISH}" == x"true" ]]; then
55+
shift
56+
fi
57+
58+
for OUTPUT_IMAGE in "${@}"; do
59+
echo "Publishing ${INPUT_IMAGE} as ${OUTPUT_IMAGE}"
60+
publish ${INPUT_IMAGE} ${OUTPUT_IMAGE}
61+
done

0 commit comments

Comments
 (0)