From f80898c9f30f22c23076c832e6efc57ff0bdeb06 Mon Sep 17 00:00:00 2001 From: Matthew Crymble Date: Fri, 28 Jul 2023 13:17:34 -0500 Subject: [PATCH] ci: select docker image repo directly at container endpoint definitions This fixes issues caused by e22a2a7395d10f795f5938724ce8aed5424d3ce8. That commit tried to consolidate the selection of the endpoint based on branch name in a single shared location. But due to the order that azure pipelines evaluates things, the endpoints were being authenticated before the stage variables were evaluated. From azure docs: "Resources are authorized before a stage can start running, so stage- and job-level variables aren't available. Pipeline-level variables can be used, but only those variables explicitly included in the pipeline." --- .../job-gnuradio-grettus-build-src.yml | 5 ++- .ci/templates/job-uhd-build-installer.yml | 5 ++- .ci/templates/job-uhd-build-src.yml | 5 ++- .ci/templates/job-uhd-package-src.yml | 5 ++- .ci/uhd-build-docker-container.yml | 37 ++++++++++++++++--- .ci/uhd-pipeline-vars.yml | 20 ---------- 6 files changed, 47 insertions(+), 30 deletions(-) diff --git a/.ci/templates/job-gnuradio-grettus-build-src.yml b/.ci/templates/job-gnuradio-grettus-build-src.yml index cf92c2496..b7fdb0251 100644 --- a/.ci/templates/job-gnuradio-grettus-build-src.yml +++ b/.ci/templates/job-gnuradio-grettus-build-src.yml @@ -49,7 +49,10 @@ jobs: ${{ if ne(parameters.toolset, 'make_homebrew_macos') }}: container: image: '$(dockerImagePrefix)$(DockerImageName):$(dockerBuildNumber)' - endpoint: ${{ variables.dockerRegistryReadOnly }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + endpoint: rnd-docker-niartifacts-ci-readonly + ${{ else }}: + endpoint: rnd-docker-niartifacts-pre-readonly steps: - checkout: self clean: true diff --git a/.ci/templates/job-uhd-build-installer.yml b/.ci/templates/job-uhd-build-installer.yml index 332b3bf16..0c716bfd9 100644 --- a/.ci/templates/job-uhd-build-installer.yml +++ b/.ci/templates/job-uhd-build-installer.yml @@ -64,7 +64,10 @@ jobs: matrix: $[ variables.dockerImageMatrixFedoraRpm ] container: image: '$(dockerImagePrefix)$(DockerImageName):$(dockerBuildNumber)' - endpoint: ${{ variables.dockerRegistryReadOnly }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + endpoint: rnd-docker-niartifacts-ci-readonly + ${{ else }}: + endpoint: rnd-docker-niartifacts-pre-readonly ${{ if eq(parameters.toolset, 'ubuntu_deb') }}: #pbuilder requires access to /proc options: --privileged diff --git a/.ci/templates/job-uhd-build-src.yml b/.ci/templates/job-uhd-build-src.yml index 588c11651..83f14ff60 100644 --- a/.ci/templates/job-uhd-build-src.yml +++ b/.ci/templates/job-uhd-build-src.yml @@ -63,7 +63,10 @@ jobs: ${{ if ne(parameters.toolset, 'make_homebrew_macos') }}: container: image: '$(dockerImagePrefix)$(DockerImageName):$(dockerBuildNumber)' - endpoint: ${{ variables.dockerRegistryReadOnly }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + endpoint: rnd-docker-niartifacts-ci-readonly + ${{ else }}: + endpoint: rnd-docker-niartifacts-pre-readonly steps: - checkout: self clean: true diff --git a/.ci/templates/job-uhd-package-src.yml b/.ci/templates/job-uhd-package-src.yml index f20474deb..28770cc23 100644 --- a/.ci/templates/job-uhd-package-src.yml +++ b/.ci/templates/job-uhd-package-src.yml @@ -34,7 +34,10 @@ jobs: clean: all container: image: '$(dockerImagePrefix)$(DockerImageName):$(dockerBuildNumber)' - endpoint: ${{ variables.dockerRegistryReadOnly }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + endpoint: rnd-docker-niartifacts-ci-readonly + ${{ else }}: + endpoint: rnd-docker-niartifacts-pre-readonly steps: - checkout: self clean: true diff --git a/.ci/uhd-build-docker-container.yml b/.ci/uhd-build-docker-container.yml index 86aadd692..2af14d215 100644 --- a/.ci/uhd-build-docker-container.yml +++ b/.ci/uhd-build-docker-container.yml @@ -71,6 +71,13 @@ variables: value: "{'VS2019-x64-builder':{'buildOSName':'win-vs19-v142-x64','dockerImageName':'uhd-builder-vs2019-v142-x64','cmakeCompiler':'Visual Studio 16 2019','cmakeArch':'x64','vsArch':'x64','vsYear':'2019'}}" +- ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + - name: dockerImagePrefix + value: 'rnd-docker-ci/ni/rfsdr/' +- ${{ else }}: + - name: dockerImagePrefix + value: 'rnd-docker-pre/ni/rfsdr/' + jobs: - job: build_image_linux displayName: Build Docker Image @@ -89,7 +96,10 @@ jobs: inputs: command: 'build' Dockerfile: '$(Build.SourcesDirectory)/.ci/docker/$(dockerImageName).Dockerfile' - containerRegistry: ${{ variables.dockerRegistryPublish }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + containerRegistry: rnd-docker-niartifacts-sdr-ci-publish + ${{ else }}: + containerRegistry: rnd-docker-niartifacts-pre-publish repository: '$(dockerImagePrefix)$(dockerImageName)' tags: $(Build.BuildNumber) arguments: --no-cache --pull @@ -97,7 +107,10 @@ jobs: displayName: Push Image inputs: command: 'push' - containerRegistry: ${{ variables.dockerRegistryPublish }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + containerRegistry: rnd-docker-niartifacts-sdr-ci-publish + ${{ else }}: + containerRegistry: rnd-docker-niartifacts-pre-publish repository: '$(dockerImagePrefix)$(dockerImageName)' tags: $(Build.BuildNumber) @@ -113,7 +126,10 @@ jobs: matrix: $[ variables.linuxDockerImages ] container: image: '$(dockerImagePrefix)$(dockerImageName):$(Build.BuildNumber)' - endpoint: ${{ variables.dockerRegistryReadOnly }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + endpoint: rnd-docker-niartifacts-ci-readonly + ${{ else }}: + endpoint: rnd-docker-niartifacts-pre-readonly workspace: clean: outputs steps: @@ -152,7 +168,10 @@ jobs: inputs: command: 'build' Dockerfile: '$(Build.SourcesDirectory)/.ci/docker/$(dockerImageName).Dockerfile' - containerRegistry: ${{ variables.dockerRegistryPublish }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + containerRegistry: rnd-docker-niartifacts-sdr-ci-publish + ${{ else }}: + containerRegistry: rnd-docker-niartifacts-pre-publish repository: '$(dockerImagePrefix)$(dockerImageName)' tags: $(Build.BuildNumber) buildContext: $(Build.SourcesDirectory) @@ -161,7 +180,10 @@ jobs: displayName: Push Image inputs: command: 'push' - containerRegistry: ${{ variables.dockerRegistryPublish }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + containerRegistry: rnd-docker-niartifacts-sdr-ci-publish + ${{ else }}: + containerRegistry: rnd-docker-niartifacts-pre-publish repository: '$(dockerImagePrefix)$(dockerImageName)' tags: $(Build.BuildNumber) @@ -178,7 +200,10 @@ jobs: matrix: $[ variables.winDockerImages ] container: image: '$(dockerImagePrefix)$(dockerImageName):$(Build.BuildNumber)' - endpoint: ${{ variables.dockerRegistryReadOnly }} + ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: + endpoint: rnd-docker-niartifacts-ci-readonly + ${{ else }}: + endpoint: rnd-docker-niartifacts-pre-readonly workspace: clean: outputs steps: diff --git a/.ci/uhd-pipeline-vars.yml b/.ci/uhd-pipeline-vars.yml index 83ae73171..34e8f93ff 100644 --- a/.ci/uhd-pipeline-vars.yml +++ b/.ci/uhd-pipeline-vars.yml @@ -1,23 +1,3 @@ variables: - name: UHDPipelineDockerImageArtifactName value: 'DockerImageNames' -# The rnd-docker-pre artifactory repo has a retention policy of 7 days. This is fine for -# PR builds, but for our mainline and release branches, we need to use the rnd-docker-ci -# repo to keep them around longer. -# The standard rnd-docker-niartifacts-ci-publish service connection only allows -# certain branch names, which don't include UHD's release branch naming. We were given -# a special sdr-specific service connection to allow this use case. -- ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/UHD-')) }}: - - name: dockerRegistryPublish - value: rnd-docker-niartifacts-sdr-ci-publish - - name: dockerRegistryReadOnly - value: rnd-docker-niartifacts-ci-readonly - - name: dockerImagePrefix - value: 'rnd-docker-ci/ni/rfsdr/' -- ${{ else }}: - - name: dockerRegistryPublish - value: rnd-docker-niartifacts-pre-publish - - name: dockerRegistryReadOnly - value: rnd-docker-niartifacts-pre-readonly - - name: dockerImagePrefix - value: 'rnd-docker-pre/ni/rfsdr/'