|
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
| 3 | +# |
| 4 | +# Scheduled rebuild of the microsoftgraph/powershell container image. |
| 5 | +# |
| 6 | +# Why this pipeline exists: |
| 7 | +# The release pipeline (sdk-release.yml) only builds and pushes this image on `v*` tags, so |
| 8 | +# between releases the published digest goes stale and keeps accruing Ubuntu USN / PowerShell |
| 9 | +# CVEs. That is the root cause of the two S360 "Replace Vulnerable Registry Reference" items. |
| 10 | +# This lightweight pipeline rebuilds the image on a cadence against a patched base and pushes a |
| 11 | +# fresh digest to :latest, keeping the registry copy patched without re-running the full release. |
| 12 | +# |
| 13 | +# Setup (one-time): register this YAML as a new pipeline definition in the |
| 14 | +# "Graph Developer Experiences" ADO project, targeting the default branch. |
| 15 | +name: $(Date:yyyyMMdd)$(Rev:.r)_docker-image-refresh |
| 16 | + |
| 17 | +parameters: |
| 18 | +- name: LinuxPool |
| 19 | + type: string |
| 20 | + default: Azure-Pipelines-1ESPT-ExDShared |
| 21 | + |
| 22 | +variables: |
| 23 | + REGISTRY: 'msgraphprodregistry.azurecr.io' |
| 24 | + IMAGE_NAME: 'public/microsoftgraph/powershell' |
| 25 | + |
| 26 | +# Rebuild weekly so the image regularly picks up patched OS layers. `always: true` forces a run |
| 27 | +# even when there are no new commits (the whole point is to refresh the base image). |
| 28 | +schedules: |
| 29 | +- cron: "0 6 * * 1" # 06:00 UTC every Monday |
| 30 | + displayName: Weekly image refresh |
| 31 | + branches: |
| 32 | + include: |
| 33 | + - main |
| 34 | + always: true |
| 35 | + |
| 36 | +# Do not build on every push/PR; the release pipeline already handles tag-driven publishes. |
| 37 | +trigger: none |
| 38 | +pr: none |
| 39 | + |
| 40 | +resources: |
| 41 | + repositories: |
| 42 | + - repository: 1ESPipelineTemplates |
| 43 | + type: git |
| 44 | + name: 1ESPipelineTemplates/1ESPipelineTemplates |
| 45 | + ref: refs/tags/release |
| 46 | + |
| 47 | +extends: |
| 48 | + template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates |
| 49 | + parameters: |
| 50 | + pool: |
| 51 | + name: ${{ parameters.LinuxPool }} |
| 52 | + image: ubuntu-latest |
| 53 | + os: linux |
| 54 | + settings: |
| 55 | + networkIsolationPolicy: Permissive |
| 56 | + customBuildTags: |
| 57 | + - ES365AIMigrationTooling |
| 58 | + stages: |
| 59 | + - stage: RefreshDockerImage |
| 60 | + displayName: 'Refresh docker image' |
| 61 | + jobs: |
| 62 | + - job: RebuildAndPush |
| 63 | + displayName: 'Rebuild and push patched image' |
| 64 | + pool: |
| 65 | + name: ${{ parameters.LinuxPool }} |
| 66 | + image: ubuntu-latest |
| 67 | + os: linux |
| 68 | + steps: |
| 69 | + - checkout: self |
| 70 | + |
| 71 | + - task: AzureCLI@2 |
| 72 | + displayName: 'Log in to Azure Container Registry' |
| 73 | + inputs: |
| 74 | + azureSubscription: 'ACR Images Push Service Connection' |
| 75 | + scriptType: 'bash' |
| 76 | + scriptLocation: 'inlineScript' |
| 77 | + inlineScript: | |
| 78 | + az acr login --name $(REGISTRY) |
| 79 | +
|
| 80 | + - script: | |
| 81 | + docker run --privileged --rm tonistiigi/binfmt --install all |
| 82 | + displayName: 'Enable multi-platform builds' |
| 83 | +
|
| 84 | + - script: | |
| 85 | + docker buildx create --use --name refreshbuilder |
| 86 | + displayName: 'Set up Docker BuildX' |
| 87 | +
|
| 88 | + - bash: | |
| 89 | + set -euo pipefail |
| 90 | + formatted_date=$(date +"%Y%m%d%H%M%S") |
| 91 | + echo "Rebuilding $(REGISTRY)/$(IMAGE_NAME) on a patched base" |
| 92 | + docker buildx build \ |
| 93 | + --platform linux/amd64 \ |
| 94 | + --push \ |
| 95 | + -t "$(REGISTRY)/$(IMAGE_NAME):latest" \ |
| 96 | + -t "$(REGISTRY)/$(IMAGE_NAME):$formatted_date" \ |
| 97 | + "$(Build.SourcesDirectory)" |
| 98 | + displayName: 'Build and push refreshed image' |
0 commit comments