ci: select docker image repo directly at container endpoint definitions

This fixes issues caused by e22a2a7395.
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."
This commit is contained in:
Matthew Crymble 2023-07-28 13:17:34 -05:00 committed by Aki Tomita
parent b70f546ffa
commit f80898c9f3
6 changed files with 47 additions and 30 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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/'