Skip to content

Commit a786a6d

Browse files
authored
Merge pull request #1181 from elezar/integrate-ngc-automation
Integrate ngc automation
2 parents 3dc52a6 + 051fe94 commit a786a6d

File tree

2 files changed

+76
-134
lines changed

2 files changed

+76
-134
lines changed

.common-ci.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

.nvidia-ci.yml

Lines changed: 76 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
include:
16-
- local: '.common-ci.yml'
17-
1815
default:
16+
image: docker
17+
services:
18+
- name: docker:dind
19+
command: ["--experimental"]
1920
tags:
2021
- cnt
2122
- container-dev
@@ -25,6 +26,8 @@ default:
2526
- type/docker
2627

2728
variables:
29+
GIT_SUBMODULE_STRATEGY: recursive
30+
2831
DOCKER_DRIVER: overlay2
2932
DOCKER_TLS_CERTDIR: "/certs"
3033
# Release "devel"-tagged images off the main branch
@@ -39,6 +42,40 @@ variables:
3942
KITMAKER_RELEASE_FOLDER: "kitmaker"
4043
PACKAGE_ARCHIVE_RELEASE_FOLDER: "releases"
4144

45+
stages:
46+
- pull
47+
- scan
48+
- release
49+
- ngc-publish
50+
51+
.pipeline-trigger-rules:
52+
rules:
53+
# We trigger the pipeline if started manually
54+
- if: $CI_PIPELINE_SOURCE == "web"
55+
# We trigger the pipeline on the main branch
56+
- if: $CI_COMMIT_BRANCH == "main"
57+
# We trigger the pipeline on the release- branches
58+
- if: $CI_COMMIT_BRANCH =~ /^release-.*$/
59+
# We trigger the pipeline on tags
60+
- if: $CI_COMMIT_TAG && $CI_COMMIT_TAG != ""
61+
62+
workflow:
63+
rules:
64+
# We trigger the pipeline on a merge request
65+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
66+
# We then add all the regular triggers
67+
- !reference [.pipeline-trigger-rules, rules]
68+
69+
# Download the regctl binary for use in the release steps
70+
.regctl-setup:
71+
before_script:
72+
- export REGCTL_VERSION=v0.4.5
73+
- apk add --no-cache curl
74+
- mkdir -p bin
75+
- curl -sSLo bin/regctl https://github.com/regclient/regclient/releases/download/${REGCTL_VERSION}/regctl-linux-amd64
76+
- chmod a+x bin/regctl
77+
- export PATH=$(pwd)/bin:${PATH}
78+
4279
# .copy-images copies the required application and packaging images from the
4380
# IN_IMAGE="${IN_IMAGE_NAME}:${IN_IMAGE_TAG}${TAG_SUFFIX}"
4481
# to
@@ -195,98 +232,59 @@ push-images-to-staging:
195232
OUT_IMAGE_NAME: "${NGC_STAGING_REGISTRY}/container-toolkit"
196233
OUT_IMAGE_TAG: "${CI_COMMIT_SHORT_SHA}"
197234

198-
.release-images:
199-
extends:
200-
- .copy-images
201-
stage: release
235+
.publish-images:
236+
stage: ngc-publish
202237
needs:
203238
- scan-images
204239
- push-images-to-staging
240+
image:
241+
name: "${CNT_NGC_PUBLISH_IMAGE}"
242+
pull_policy: always
205243
variables:
206-
IN_REGISTRY: "${CI_REGISTRY}"
207-
IN_REGISTRY_USER: "${CI_REGISTRY_USER}"
208-
IN_REGISTRY_TOKEN: "${CI_REGISTRY_PASSWORD}"
209-
IN_IMAGE_NAME: "${CI_REGISTRY_IMAGE}/container-toolkit"
210-
IN_IMAGE_TAG: "${CI_COMMIT_SHORT_SHA}"
211-
212-
OUT_REGISTRY: "${NGC_REGISTRY}"
213-
OUT_REGISTRY_USER: "${NGC_REGISTRY_USER}"
214-
OUT_REGISTRY_TOKEN: "${NGC_REGISTRY_TOKEN}"
215-
OUT_IMAGE_NAME: "${NGC_REGISTRY_IMAGE}"
216-
OUT_IMAGE_TAG: "${CI_COMMIT_TAG}"
217-
218-
release-images-to-ngc:
219-
extends:
220-
- .release-images
221-
rules:
222-
- if: $CI_COMMIT_TAG
223-
224-
release-images-dummy:
225-
extends:
226-
- .release-images
227-
variables:
228-
REGCTL: "echo [DUMMY] regctl"
229-
rules:
230-
- if: $CI_COMMIT_TAG == null || $CI_COMMIT_TAG == ""
231244

232-
# .sign-images forms the base of the jobs which sign images in the NGC registry.
233-
.sign-images:
234-
stage: sign
235-
image: ubuntu:latest
236-
parallel:
237-
matrix:
238-
- TAG_SUFFIX: ["", "-packaging"]
239245
variables:
240-
IMAGE_NAME: "${NGC_REGISTRY_IMAGE}"
241-
IMAGE_TAG: "${CI_COMMIT_TAG}"
242-
NGC_CLI: "ngc-cli/ngc"
243-
before_script:
244-
- !reference [.ngccli-setup, before_script]
245-
script:
246-
- |
247-
# We ensure that the IMAGE_NAME and IMAGE_TAG is set
248-
echo Image Name: ${IMAGE_NAME} && [[ -n "${IMAGE_NAME}" ]] || exit 1
249-
echo Image Tag: ${IMAGE_TAG} && [[ -n "${IMAGE_TAG}" ]] || exit 1
246+
GITLAB_ACCESS_TOKEN: "${CNT_GITLAB_TOKEN}"
250247

251-
export IMAGE=${IMAGE_NAME}:${IMAGE_TAG}${TAG_SUFFIX}
252-
echo "Signing the image ${IMAGE}"
253-
${NGC_CLI} registry image publish --source ${IMAGE} ${IMAGE} --public --discoverable --allow-guest --sign --org nvidia
248+
OUT_IMAGE_TAG: "${CI_COMMIT_TAG}"
254249

255-
# Define the external image signing steps for NGC
256-
# Download the ngc cli binary for use in the sign steps
257-
.ngccli-setup:
250+
VERSION_FILE: "build-info-${CI_PIPELINE_ID}.txt"
251+
PROJECT_NAME: "nvidia-container-toolkit"
258252
before_script:
259-
- apt-get update && apt-get install -y curl unzip jq
260253
- |
261-
if [ -z "${NGCCLI_VERSION}" ]; then
262-
NGC_VERSION_URL="https://api.ngc.nvidia.com/v2/resources/nvidia/ngc-apps/ngc_cli/versions"
263-
# Extract the latest version from the JSON data using jq
264-
export NGCCLI_VERSION=$(curl -s $NGC_VERSION_URL | jq -r '.recipe.latestVersionIdStr')
254+
if [ -z "$NGC_PUBLISHING_PROJECT_PATH" ]; then
255+
echo "NGC_PUBLISHING_PROJECT_PATH not set"
256+
exit 1
257+
else
258+
echo "publishing to ${NGC_PUBLISHING_PROJECT_PATH}"
265259
fi
266-
echo "NGCCLI_VERSION ${NGCCLI_VERSION}"
267-
- curl -sSLo ngccli_linux.zip https://api.ngc.nvidia.com/v2/resources/nvidia/ngc-apps/ngc_cli/versions/${NGCCLI_VERSION}/files/ngccli_linux.zip
268-
- unzip ngccli_linux.zip
269-
- chmod u+x ngc-cli/ngc
270260
271-
sign-ngc-images:
261+
rm -f ${VERSION_FILE}
262+
echo "${IN_IMAGE_TAG} ${OUT_IMAGE_TAG}" >> ${VERSION_FILE}
263+
echo "${IN_IMAGE_TAG}-packaging ${OUT_IMAGE_TAG}-packaging" >> ${VERSION_FILE}"
264+
cat ${VERSION_FILE}
265+
script:
266+
- cnt-ngc-publish render --project-name "${PROJECT_NAME}" --versions-file "${VERSION_FILE}" --output "${PROJECT_NAME}".yaml
267+
- cnt-ngc-publish merge-request --files "${PROJECT_NAME}.yaml"
268+
artifacts:
269+
paths:
270+
- "${VERSION_FILE}"
271+
- "${PROJECT_NAME}.yaml"
272+
273+
274+
publish-images-to-ngc:
272275
extends:
273-
- .sign-images
274-
needs:
275-
- release-images-to-ngc
276+
- .publish-images
276277
rules:
277278
- if: $CI_COMMIT_TAG
278-
variables:
279-
NGC_CLI_API_KEY: "${NGC_REGISTRY_TOKEN}"
280-
retry:
281-
max: 2
282279

283-
sign-images-dummy:
280+
# We create a dummy MR that exercises the publishing logic.
281+
# TODO: This MR should be closed automatically.
282+
publish-images-dummy:
284283
extends:
285-
- .sign-images
286-
needs:
287-
- release-images-dummy
284+
- .publish-images
288285
variables:
289-
NGC_CLI: "echo [DUMMY] ngc-cli/ngc"
290-
IMAGE_TAG: "${CI_COMMIT_SHORT_SHA}"
286+
NGC_PUBLISHING_PROJECT_PATH: dl/container-dev/ngc-automation
287+
OUT_IMAGE_TAG: "${CI_COMMIT_SHORT_SHA}"
291288
rules:
292289
- if: $CI_COMMIT_TAG == null || $CI_COMMIT_TAG == ""
290+

0 commit comments

Comments
 (0)