-
Notifications
You must be signed in to change notification settings - Fork 942
/
Copy pathdocker-container-to-acr.yml
81 lines (64 loc) · 2.86 KB
/
docker-container-to-acr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Docker image and Azure Container Registry
# Build a Docker image and push it to an Azure Container Registry.
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- {{ branch }}
resources:
- repo: self
variables:
# ========================================================================
# Mandatory variables
# ========================================================================
# Update Azure.ResourceGroupName value with Azure resource group name.
Azure.ResourceGroupName: '{{#toAlphaNumericString repositoryName 50}}{{/toAlphaNumericString}}'
# Update Azure.ServiceConnectionId value with AzureRm service endpoint.
Azure.ServiceConnectionId: '{{ azureServiceConnectionId }}'
# Update Azure.Location value with Azure Location.
Azure.Location: 'eastus'
# Update ACR.Name value with ACR name. Please note ACR names should be all lower-case and alphanumeric only.
ACR.Name: '{{#toAlphaNumericString repositoryName 46}}{{/toAlphaNumericString}}{{#shortGuid}}{{/shortGuid}}'
# ========================================================================
# Optional variables
# ========================================================================
ACR.ImageName: '$(ACR.Name):$(Build.BuildId)'
ACR.FullName: '$(ACR.Name).azurecr.io'
Azure.CreateResources: 'true' # Update Azure.CreateResources to false if you have already created resources like resource group and azure container registry.
System.Debug: 'false'
jobs:
- job: CreateResources
displayName: Create required resources
condition: and(succeeded(), eq(variables['Azure.CreateResources'], 'true'))
pool:
{{ pool }}
steps:
- task: AzureResourceGroupDeployment@2
displayName: 'Azure Deployment:Create Azure Container Registry'
inputs:
azureSubscription: '$(Azure.ServiceConnectionId)'
resourceGroupName: '$(Azure.ResourceGroupName)'
location: '$(Azure.Location)'
templateLocation: 'URL of the file'
csmFileLink: 'https://raw.githubusercontent.com/Microsoft/azure-pipelines-yaml/master/templates/resources/arm/acr.json'
overrideParameters: '-registryName "$(ACR.Name)" -registryLocation "$(Azure.Location)"'
- job: BuildImage
displayName: Build
dependsOn: CreateResources
condition: or(succeeded(), ne(variables['Azure.CreateResources'], 'true'))
pool:
{{ pool }}
steps:
- task: Docker@1
displayName: 'Build an image'
inputs:
azureSubscriptionEndpoint: '$(Azure.ServiceConnectionId)'
azureContainerRegistry: '$(ACR.FullName)'
imageName: '$(ACR.ImageName)'
command: build
dockerFile: '**/Dockerfile'
- task: Docker@1
displayName: 'Push an image'
inputs:
azureSubscriptionEndpoint: '$(Azure.ServiceConnectionId)'
azureContainerRegistry: '$(ACR.FullName)'
imageName: '$(ACR.ImageName)'
command: push