From 254035eb8a8f0b3eabc98c5c07d47a9c657e35fc Mon Sep 17 00:00:00 2001 From: Sai Kiran <110003254+opcoder0@users.noreply.github.com> Date: Fri, 25 Oct 2024 21:11:41 +1100 Subject: [PATCH] [docker-ptf]: CI change to publish docker-ptf image to the docker registry (#20528) Why I did it Changes to docker-ptf Dockerfile don't get automatically published to the docker registry accessed by the community. This PR addresses the issue. Work item tracking Microsoft ADO (number only): 29869315 How I did it Modified the postSteps phase in azure-pipelines-image-template.yml to invoke the script to push docker-ptf image to the docker registry. The push is applicable to build branches (master, 202305, 202311 etc.) and not feature branches. How to verify it TBD Tested branch (Please provide the tested image version) Not applicable. Description for the changelog [docker-ptf]: CI change to publish docker-ptf image to the public/community docker registry Change pipeline YAML to publish docker-ptf image to docker registry Publish only docker-ptf image for main or release branches only and not feature branch Link to config_db schema for YANG module changes Not applicable --- .../azure-pipelines-image-template.yml | 21 ++++++++++++++++++- .azure-pipelines/official-build.yml | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.azure-pipelines/azure-pipelines-image-template.yml b/.azure-pipelines/azure-pipelines-image-template.yml index 0b480638c..2273b66cd 100644 --- a/.azure-pipelines/azure-pipelines-image-template.yml +++ b/.azure-pipelines/azure-pipelines-image-template.yml @@ -53,9 +53,28 @@ jobs: displayName: 'Make configure' postSteps: - script: | + BUILD_REASON=$(Build.Reason) + echo "Build.Reason = $BUILD_REASON" + echo "Build.DefinitionName = $BUILD_DEFINITIONNAME" + if [[ "$BUILD_REASON" != "PullRequest" && "$BUILD_DEFINITIONNAME" == "Azure.sonic-buildimage.official.vs" ]] + then + PORT=443 + DOCKERS=$(ls target/docker-ptf.gz) + BRANCH=$(Build.SourceBranchName) + echo "Branch = $BRANCH" + LABELS="$BRANCH" + [[ "$BRANCH" == "master" ]] && LABELS="$LABELS latest" + for f in $DOCKERS; do + echo $f + echo "Labels = $LABELS" + ./push_docker.sh $f $(REGISTRY_SERVER_PUBLIC) $PORT $(REGISTRY_USERNAME) "$REGISTRY_PASSWD" "$LABELS" + done + fi mkdir -p $(Build.ArtifactStagingDirectory)/target mv target/* $(Build.ArtifactStagingDirectory)/target/ - displayName: Copy Artifacts + env: + REGISTRY_PASSWD: $(REGISTRY_PASSWD) + displayName: Publish to Docker Registry and Copy Artifacts condition: always() - publish: $(Build.ArtifactStagingDirectory) artifact: 'sonic-buildimage.$(GROUP_NAME)$(GROUP_EXTNAME)' diff --git a/.azure-pipelines/official-build.yml b/.azure-pipelines/official-build.yml index ecc9bd89c..a228529b4 100644 --- a/.azure-pipelines/official-build.yml +++ b/.azure-pipelines/official-build.yml @@ -36,6 +36,7 @@ stages: - stage: Build pool: sonicbld-1es variables: + - group: Container-Registry - name: CACHE_MODE value: wcache - template: .azure-pipelines/azure-pipelines-repd-build-variables.yml@buildimage