Files
runner-images/images.CI/linux-and-win/azure-pipelines/image-generation.yml
T

101 lines
4.3 KiB
YAML
Raw Normal View History

2020-02-26 11:36:04 +03:00
# Ideally we would use GitHub Actions for this, but since we use self-hosted machines to run image builds
# we need the following features to use GitHub Actions for Images CI:
2020-02-25 19:07:45 +03:00
# - https://github.community/t5/GitHub-Actions/Make-secrets-available-to-builds-of-forks/m-p/30678#M508
# - https://github.community/t5/GitHub-Actions/GitHub-Actions-Manual-Trigger-Approvals/td-p/31504
# - https://github.community/t5/GitHub-Actions/Protecting-github-workflows/td-p/30290
2020-02-14 19:09:09 +03:00
jobs:
- job:
displayName: Image Generation (${{ parameters.image_type }})
2020-02-15 20:52:05 +03:00
timeoutInMinutes: 600
2020-05-12 17:47:44 +02:00
cancelTimeoutInMinutes: 30
pool: ci-agent-pool
2020-02-15 20:52:05 +03:00
variables:
- group: Image Generation Variables
2020-02-14 19:09:09 +03:00
steps:
2020-02-19 14:30:44 +03:00
- task: PowerShell@2
2020-02-18 15:37:23 +03:00
displayName: 'Download custom repository'
2020-02-25 19:07:45 +03:00
condition: and(ne(variables['CUSTOM_REPOSITORY_URL'], ''), ne(variables['CUSTOM_REPOSITORY_BRANCH'], ''))
2020-02-19 14:30:44 +03:00
inputs:
targetType: 'filePath'
filePath: ./images.CI/download-repo.ps1
arguments: -RepoUrl $(CUSTOM_REPOSITORY_URL) `
2020-09-16 19:44:58 +03:00
-RepoBranch $(CUSTOM_REPOSITORY_BRANCH)
- task: PowerShell@2
displayName: 'Set image template variables'
inputs:
targetType: 'inline'
script: |
$ImageType = "${{ parameters.image_type }}"
$TemplateDirectoryName = if ($ImageType.StartsWith("ubuntu")) { "linux" } else { "win" }
$TemplateDirectoryPath = Join-Path "images" $TemplateDirectoryName | Resolve-Path
$TemplatePath = Join-Path $TemplateDirectoryPath "$ImageType.json"
Write-Host "##vso[task.setvariable variable=TemplateDirectoryPath;]$TemplateDirectoryPath"
Write-Host "##vso[task.setvariable variable=TemplatePath;]$TemplatePath"
2020-02-18 15:37:23 +03:00
- task: PowerShell@2
displayName: 'Build VM'
inputs:
targetType: filePath
2020-09-16 19:44:58 +03:00
filePath: ./images.CI/linux-and-win/build-image.ps1
2020-02-21 11:34:07 +03:00
arguments: -ResourcesNamePrefix $(Build.BuildId) `
2020-02-14 19:09:09 +03:00
-ClientId $(CLIENT_ID) `
-ClientSecret $(CLIENT_SECRET) `
-TemplatePath $(TemplatePath) `
2020-02-14 19:09:09 +03:00
-ResourceGroup $(AZURE_RESOURCE_GROUP) `
-StorageAccount $(AZURE_STORAGE_ACCOUNT) `
-SubscriptionId $(AZURE_SUBSCRIPTION) `
-TenantId $(AZURE_TENANT) `
-Location $(AZURE_LOCATION) `
-VirtualNetworkName $(BUILD_AGENT_VNET_NAME) `
-VirtualNetworkRG $(BUILD_AGENT_VNET_RESOURCE_GROUP) `
2021-04-15 18:59:28 +07:00
-VirtualNetworkSubnet $(BUILD_AGENT_SUBNET_NAME)
env:
PACKER_LOG: 1
PACKER_LOG_PATH: $(Build.ArtifactStagingDirectory)/packer-log.txt
2020-02-14 19:09:09 +03:00
2020-11-16 10:12:38 +03:00
- task: PowerShell@2
displayName: 'Output Readme file content'
inputs:
targetType: 'inline'
script: |
Get-Content -Path (Join-Path "$(TemplateDirectoryPath)" "${{ parameters.image_readme_name }}")
- task: PowerShell@2
displayName: 'Print provisioners duration'
inputs:
targetType: 'filePath'
filePath: ./images.CI/measure-provisioners-duration.ps1
arguments: -PackerLogPath "$(Build.ArtifactStagingDirectory)/packer-log.txt" `
-PrefixToPathTrim "$(TemplateDirectoryPath)" `
-PrintTopNLongest 25
2020-11-16 10:12:38 +03:00
2020-02-20 17:52:12 +03:00
- task: PowerShell@2
displayName: 'Create release for VM deployment'
inputs:
targetType: filePath
2020-09-16 19:44:58 +03:00
filePath: ./images.CI/linux-and-win/create-release.ps1
2020-02-21 11:34:07 +03:00
arguments: -BuildId $(Build.BuildId) `
2020-02-20 17:52:12 +03:00
-Organization $(RELEASE_TARGET_ORGANIZATION) `
-DefinitionId $(RELEASE_TARGET_DEFINITION_ID) `
-Project $(RELEASE_TARGET_PROJECT) `
-ImageName ${{ parameters.image_type }} `
-AccessToken $(RELEASE_TARGET_TOKEN)
- task: PowerShell@2
displayName: 'Clean up resources'
condition: always()
inputs:
targetType: filePath
2020-09-16 19:44:58 +03:00
filePath: ./images.CI/linux-and-win/cleanup.ps1
2020-02-21 11:34:07 +03:00
arguments: -ResourcesNamePrefix $(Build.BuildId) `
-Image ${{ parameters.image_type }} `
-StorageAccount $(AZURE_STORAGE_ACCOUNT) `
-SubscriptionId $(AZURE_SUBSCRIPTION) `
2020-02-14 19:09:09 +03:00
-ClientId $(CLIENT_ID) `
-ClientSecret $(CLIENT_SECRET) `
2020-05-12 17:47:44 +02:00
-TenantId $(AZURE_TENANT)