77 include :
88 - main
99 - support/v1
10+ - task/move-to-deploy-stage
1011 tags :
1112 include :
1213 - ' v*'
1516 include :
1617 - main
1718 - support/v1
19+ - task/move-to-deploy-stage
1820
1921variables :
2022 buildPlatform : ' Any CPU'
2123 buildConfiguration : ' Release'
2224 ProductBinPath : ' $(Build.SourcesDirectory)\src\Microsoft.OpenApi\bin\$(BuildConfiguration)'
23- REGISTRY : ' msgraphprodregistry .azurecr.io'
25+ REGISTRY : ' msgraphpperegistry .azurecr.io'
2426 IMAGE_NAME : ' public/openapi/hidi'
25- PREVIEW_BRANCH : ' refs/heads/main '
27+ PREVIEW_BRANCH : ' refs/heads/task/move-to-deploy-stage '
2628
2729resources :
2830 repositories :
@@ -203,18 +205,79 @@ extends:
203205 sourceFolder : $(Build.ArtifactStagingDirectory)
204206 content : ' *.nupkg'
205207
206- # Copy repository files to be used in the deploy stage
207- - task : CopyFiles@2
208- displayName : ' Copy repository files for deploy stage'
209- inputs :
210- SourceFolder : ' $(Build.SourcesDirectory)'
211- Contents : |
212- **/*
213- !**/bin/**
214- !**/obj/**
215- !**/.git/**
216- TargetFolder : ' $(Build.ArtifactStagingDirectory)/RepoFiles'
208+ # Instead of copying repository files, build Docker images here
209+ - script : |
210+ docker run --privileged --rm tonistiigi/binfmt --install all
211+ displayName: "Enable multi-platform builds"
212+
213+ - script : |
214+ docker buildx create --use --name mybuilder
215+ displayName: "Set up Docker BuildX"
217216
217+ - script : |
218+ docker buildx inspect --bootstrap
219+ displayName: "Ensure BuildX is working"
220+
221+ - bash : |
222+ # Extract version from project properties
223+ versionInfo=$(pwsh -Command "(Get-Content '$(Build.SourcesDirectory)/Directory.Build.props' | Select-String -Pattern '<Version>(.*)</Version>').Matches.Groups[1].Value")
224+ echo "##vso[task.setvariable variable=VERSION]$versionInfo"
225+
226+ # Get date for tagging
227+ buildDate=$(date +'%Y%m%d')
228+ echo "##vso[task.setvariable variable=BUILDDATE]$buildDate"
229+
230+ # Extract run number
231+ runNumber=$(echo "$(Build.BuildNumber)" | grep -o '[0-9]\+$' || date +"%S%N" | cut -c1-3)
232+ echo "##vso[task.setvariable variable=RUNNUMBER]$runNumber"
233+ displayName: 'Extract version and build info'
234+
235+ - bash : |
236+ # Create image tag based on branch/tag
237+ if [[ "$(Build.SourceBranch)" == "$(PREVIEW_BRANCH)" ]]; then
238+ # For main branch
239+ IMAGE_TAGS="--tag $(REGISTRY)/$(IMAGE_NAME):nightly --tag $(REGISTRY)/$(IMAGE_NAME):$(VERSION).$(BUILDDATE)$(RUNNUMBER)"
240+ elif [[ "$(Build.SourceBranch)" == refs/tags/v* ]]; then
241+ # For release tags
242+ IMAGE_TAGS="--tag $(REGISTRY)/$(IMAGE_NAME):latest --tag $(REGISTRY)/$(IMAGE_NAME):$(VERSION)"
243+ else
244+ # For other branches/PRs
245+ IMAGE_TAGS="--tag $(REGISTRY)/$(IMAGE_NAME):$(VERSION).$(BUILDDATE)$(RUNNUMBER)"
246+ fi
247+
248+ echo "##vso[task.setvariable variable=IMAGE_TAGS]$IMAGE_TAGS"
249+ displayName: 'Set Docker image tags'
250+
251+ - task : AzureCLI@2
252+ displayName : ' Login to Azure Container Registry'
253+ inputs :
254+ azureSubscription : ' ACR Push Test'
255+ scriptType : bash
256+ scriptLocation : inlineScript
257+ inlineScript : |
258+ az acr login --name msgraphpperegistry
259+
260+ - bash : |
261+ # Build image with BuildX but don't push yet - save to local tar file
262+ docker buildx build \
263+ --platform linux/amd64,linux/arm64/v8 \
264+ --output "type=docker,dest=$(Build.ArtifactStagingDirectory)/docker-image.tar" \
265+ $(IMAGE_TAGS) \
266+ $(Build.SourcesDirectory)
267+ displayName: 'Build Docker image and save to artifact'
268+
269+ - task : PublishPipelineArtifact@1
270+ displayName : ' Publish Docker Image Artifact'
271+ inputs :
272+ targetPath : ' $(Build.ArtifactStagingDirectory)/docker-image.tar'
273+ artifactName : ' DockerImage'
274+
275+ - task : PublishPipelineArtifact@1
276+ displayName : ' Publish Image Tag Info'
277+ inputs :
278+ targetPath : ' $(Build.ArtifactStagingDirectory)'
279+ artifactName : ' ImageBuildInfo'
280+
218281 - stage : deploy
219282 condition : and(or(contains(variables['Build.SourceBranch'], 'refs/tags/v'), eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])), succeeded())
220283 dependsOn : build
@@ -348,8 +411,11 @@ extends:
348411 isProduction : true
349412 inputs :
350413 - input : pipelineArtifact
351- artifactName : RepoFiles
352- targetPath : ' $(Pipeline.Workspace)'
414+ artifactName : DockerImage
415+ targetPath : ' $(Pipeline.Workspace)/DockerImage'
416+ - input : pipelineArtifact
417+ artifactName : ImageBuildInfo
418+ targetPath : ' $(Pipeline.Workspace)/ImageBuildInfo'
353419 strategy :
354420 runOnce :
355421 deploy :
@@ -363,110 +429,20 @@ extends:
363429 scriptType : bash
364430 scriptLocation : inlineScript
365431 inlineScript : |
366- az acr login --name msgraphprodregistry
367-
368- - powershell : |
369- $content = [XML](Get-Content $(Pipeline.Workspace)/Directory.Build.props)
370- Write-Host "XML loaded, finding version..."
371-
372- # Handle PropertyGroup as either a single element or array
373- $version = $null
374- if ($content.Project.PropertyGroup -is [array]) {
375- Write-Host "PropertyGroup is an array, checking each entry..."
376- foreach ($pg in $content.Project.PropertyGroup) {
377- if ($pg.Version) {
378- $version = $pg.Version.ToString().Trim()
379- Write-Host "Found version in PropertyGroup array: $version"
380- break
381- }
382- }
383- } else {
384- # Single PropertyGroup
385- $version = $content.Project.PropertyGroup.Version
386- if ($version) {
387- $version = $version.ToString().Trim()
388- Write-Host "Found version in PropertyGroup: $version"
389- }
390- }
391-
392- if (-not $version) {
393- Write-Host "##vso[task.logissue type=error]Version not found in Directory.Build.props"
394- exit 1
395- }
396-
397- Write-Host "Version found: $version"
398- Write-Host "##vso[task.setvariable variable=version;isoutput=true]$version"
399- Write-Host "##vso[task.setvariable variable=VERSION]$version"
400- displayName: 'Get version from csproj'
401- name: getversion
432+ az acr login --name msgraphpperegistry
402433
403434 - bash : |
404- # Debug output to verify version variable
405- echo "Version from previous step: $VERSION"
406- displayName: 'Verify version variable'
407-
408- - bash : |
409- echo "Build Number: $(Build.BuildNumber)"
410- # Extract the last 3 characters for the run number
411- runnumber=$(echo "$(Build.BuildNumber)" | grep -o '[0-9]\+$')
412- echo "Extracted Run Number: $runnumber"
435+ # Load the Docker image from tar file
436+ docker load < $(Pipeline.Workspace)/DockerImage/docker-image.tar
413437
414- # If extraction fails, set a default
415- if [ -z "$runnumber" ]; then
416- echo "Extraction failed, using default value"
417- runnumber=$(date +"%S%N" | cut -c1-3)
418- echo "Generated fallback run number: $runnumber"
438+ # Push the image tags
439+ if [[ "$(Build.SourceBranch)" == "$(PREVIEW_BRANCH)" ]]; then
440+ docker push $(REGISTRY)/$(IMAGE_NAME):nightly
441+ docker push $(REGISTRY)/$(IMAGE_NAME):$(VERSION).$(BUILDDATE)$(RUNNUMBER)
442+ elif [[ "$(Build.SourceBranch)" == refs/tags/v* ]]; then
443+ docker push $(REGISTRY)/$(IMAGE_NAME):latest
444+ docker push $(REGISTRY)/$(IMAGE_NAME):$(VERSION)
445+ else
446+ docker push $(REGISTRY)/$(IMAGE_NAME):$(VERSION).$(BUILDDATE)$(RUNNUMBER)
419447 fi
420-
421- # Set the variable for later steps
422- echo "##vso[task.setvariable variable=RUNNUMBER]$runnumber"
423- echo "##vso[task.setvariable variable=RUNNUMBER;isOutput=true]$runnumber"
424- displayName: 'Get truncated run number'
425- name: getrunnumber
426- condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
427-
428- - bash : |
429- date=$(date +'%Y%m%d')
430- echo "Date value: $date"
431- echo "##vso[task.setvariable variable=BUILDDATE;isOutput=true]$date"
432- echo "##vso[task.setvariable variable=BUILDDATE]$date"
433- displayName: 'Get current date'
434- name: setdate
435- condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
436-
437- - script : |
438- docker run --privileged --rm tonistiigi/binfmt --install all
439- displayName: "Enable multi-platform builds"
440-
441- - script : |
442- docker buildx create --use --name mybuilder
443- displayName: "Set up Docker BuildX"
444-
445- - script : |
446- docker buildx inspect --bootstrap
447- displayName: "Ensure BuildX is working"
448-
449- - bash : |
450- echo "Building Docker image..."
451- echo "Using build date: ${BUILDDATE}"
452- # Using quotes around tags to prevent flag interpretation
453- docker buildx build \
454- --platform linux/amd64,linux/arm64/v8 \
455- --push \
456- -t "$(REGISTRY)/$(IMAGE_NAME):nightly" \
457- -t "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}" \
458- "$(Pipeline.Workspace)"
459-
460- displayName: 'Build and Push Nightly Image'
461- condition: eq(variables['Build.SourceBranch'], variables['PREVIEW_BRANCH'])
462-
463- - bash : |
464- echo "Building Docker image for release..."
465- docker buildx build\
466- --platform linux/amd64,linux/arm64/v8 \
467- --push \
468- -t "$(REGISTRY)/$(IMAGE_NAME):latest" \
469- -t "$(REGISTRY)/$(IMAGE_NAME):${VERSION}.${BUILDDATE}${RUNNUMBER}" \
470- "$(Pipeline.Workspace)"
471- displayName: 'Build and Push Release Image'
472- condition: contains(variables['Build.SourceBranch'], 'refs/tags/v')
448+ displayName: 'Push Docker Image to Registry'
0 commit comments