|
| 1 | +# Additional sample inputs can be found in `eng/containers/ci.yml`, but here is an example. |
| 2 | +# - name: test_proxy_linux |
| 3 | +# dockerRepo: 'engsys/testproxy-lin' |
| 4 | +# prepareScript: tools/test-proxy/docker/prepare.ps1 |
| 5 | +# excludeFromManifest: true/false |
| 6 | +# configPath: 'tools/test-proxy/docker' |
| 7 | +# stableTags: |
| 8 | +# - 'latest' |
| 9 | + |
| 10 | +# A "ManifestDeployment" is a secondary deployment that can be used to map multiple docker tags to a single platform-sensitive one. It waits until |
| 11 | +# all previous tag deployments are created, then triggers a manifest upload that bundles all tags configured in DockerDeployments. To exclude an item from the |
| 12 | +# manifest upload, set deployment config property excludeFromManifest to true. |
| 13 | +# - name: test_proxy_manifest |
| 14 | +# dockerRepo: 'engsys/testproxy' |
| 15 | +# stableTags: |
| 16 | +# - 'latest' |
| 17 | +parameters: |
| 18 | + - name: DockerDeployments |
| 19 | + type: object |
| 20 | + default: [] |
| 21 | + - name: ManifestDeployment |
| 22 | + type: object |
| 23 | + default: [] |
| 24 | + - name: ImageTag |
| 25 | + type: string |
| 26 | + - name: ContainerRegistry |
| 27 | + type: string |
| 28 | + default: 'azsdkengsys' |
| 29 | + - name: Publish |
| 30 | + type: boolean |
| 31 | + default: true |
| 32 | + |
| 33 | +stages: |
| 34 | + - stage: |
| 35 | + displayName: Build/Publish Containers |
| 36 | + variables: |
| 37 | + - template: /eng/pipelines/templates/variables/globals.yml |
| 38 | + - template: /eng/pipelines/templates/variables/image.yml |
| 39 | + jobs: |
| 40 | + - ${{ each config in parameters.DockerDeployments }}: |
| 41 | + - job: container_build_${{ config.name }} |
| 42 | + displayName: Build ${{ config.name }} Image |
| 43 | + pool: |
| 44 | + name: $(LINUXPOOL) |
| 45 | + image: $(LINUXVMIMAGE) |
| 46 | + os: linux |
| 47 | + |
| 48 | + ${{ if parameters.Publish }}: |
| 49 | + templateContext: |
| 50 | + outputs: |
| 51 | + - output: containerImage |
| 52 | + displayName: Push ${{ config.name }}:${{ parameters.ImageTag }} |
| 53 | + condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) |
| 54 | + image: ${{ parameters.ContainerRegistry }}.azurecr.io/${{ config.dockerRepo }}:${{ parameters.ImageTag }} |
| 55 | + - ${{ if config.stableTags }}: |
| 56 | + - ${{ each stableTag in config.stableTags }}: |
| 57 | + - output: containerImage |
| 58 | + displayName: Push ${{ config.name }}:${{ stableTag }} |
| 59 | + condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) |
| 60 | + image: ${{ parameters.ContainerRegistry }}.azurecr.io/${{ config.dockerRepo }}:${{ stableTag }} |
| 61 | + |
| 62 | + steps: |
| 63 | + - ${{ if config.prepareScript }}: |
| 64 | + - pwsh: | |
| 65 | + ./${{ config.prepareScript }} |
| 66 | + displayName: "Run prep script" |
| 67 | + - task: 1ES.BuildContainerImage@1 |
| 68 | + displayName: Build ${{ config.name }}:${{ parameters.ImageTag }} |
| 69 | + inputs: |
| 70 | + image: ${{ parameters.ContainerRegistry }}.azurecr.io/${{ config.dockerRepo }}:${{ parameters.ImageTag }} |
| 71 | + path: ${{ config.configPath }} |
| 72 | + enableNetwork: true |
| 73 | + useBuildKit: true |
| 74 | + - ${{ if config.stableTags }}: |
| 75 | + - ${{ each stableTag in config.stableTags }}: |
| 76 | + - task: 1ES.BuildContainerImage@1 |
| 77 | + displayName: Build ${{ config.name }}:${{ stableTag }} |
| 78 | + condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) |
| 79 | + inputs: |
| 80 | + image: ${{ parameters.ContainerRegistry }}.azurecr.io/${{ config.dockerRepo }}:${{ stableTag }} |
| 81 | + path: ${{ config.configPath }} |
| 82 | + enableNetwork: true |
| 83 | + useBuildKit: true |
| 84 | + |
| 85 | + - ${{ if and(parameters.ManifestDeployment, parameters.Publish) }}: |
| 86 | + - ${{ each deployment in parameters.ManifestDeployment }}: |
| 87 | + - job: container_build_${{ deployment.name }} |
| 88 | + displayName: Build ${{ deployment.name }} Manifest |
| 89 | + ${{ if gt(length(parameters.DockerDeployments), 0) }}: |
| 90 | + dependsOn: |
| 91 | + - ${{ each config in parameters.DockerDeployments }}: |
| 92 | + - container_build_${{ config.name }} |
| 93 | + pool: |
| 94 | + name: $(LINUXPOOL) |
| 95 | + image: $(LINUXVMIMAGE) |
| 96 | + os: linux |
| 97 | + |
| 98 | + steps: |
| 99 | + - pwsh: | |
| 100 | + $configurations = '${{ convertToJson(parameters.DockerDeployments) }}' -replace '\\', '/' |
| 101 | + $assembledDependentTags = $(Build.SourcesDirectory)/eng/pipelines/templates/scripts/get-docker-manifest-input.ps1 ` |
| 102 | + -DockerDeploymentJson $configurations ` |
| 103 | + -ContainerRegistry "${{ parameters.ContainerRegistry }}" ` |
| 104 | + -ImageTag "${{ parameters.ImageTag }}" ` |
| 105 | +
|
| 106 | + Write-Host "##vso[task.setvariable variable=ManifestVariable]$assembledDependentTags" |
| 107 | + displayName: Generate Manifest Variable |
| 108 | +
|
| 109 | + - pwsh: | |
| 110 | + docker manifest create ${{ parameters.ContainerRegistry }}.azurecr.io/${{ deployment.dockerRepo }}:${{ parameters.ImageTag }} $(ManifestVariable) |
| 111 | + displayName: Generate Manifest |
| 112 | +
|
| 113 | + - pwsh: | |
| 114 | + docker manifest push ${{ parameters.ContainerRegistry }}.azurecr.io/${{ deployment.dockerRepo }}:${{ parameters.ImageTag }} |
| 115 | + displayName: Upload Manifest |
| 116 | +
|
| 117 | + - ${{ if deployment.stableTags }}: |
| 118 | + - ${{ each stableTag in deployment.stableTags }}: |
| 119 | + - pwsh: | |
| 120 | + $configurations = '${{ convertToJson(parameters.DockerDeployments) }}' -replace '\\', '/' |
| 121 | + $assembledDependentTags = $(Build.SourcesDirectory)/eng/pipelines/templates/scripts/get-docker-manifest-input.ps1 ` |
| 122 | + -DockerDeploymentJson $configurations ` |
| 123 | + -ContainerRegistry "${{ parameters.ContainerRegistry }}" ` |
| 124 | + -ImageTag "${{ stableTag }}" ` |
| 125 | +
|
| 126 | + Write-Host "##vso[task.setvariable variable=ManifestVariable]$assembledDependentTags" |
| 127 | + displayName: Generate Manifest Variable |
| 128 | +
|
| 129 | + - pwsh: | |
| 130 | + docker manifest create ${{ parameters.ContainerRegistry }}.azurecr.io/${{ deployment.dockerRepo }}:${{ stableTag }} $(ManifestVariable) |
| 131 | + displayName: Generate Manifest |
| 132 | +
|
| 133 | + - pwsh: | |
| 134 | + docker manifest push ${{ parameters.ContainerRegistry }}.azurecr.io/${{ deployment.dockerRepo }}:${{ stableTag }} |
| 135 | + displayName: Upload Manifest |
0 commit comments