-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipeline.yml
140 lines (127 loc) · 5.85 KB
/
azure-pipeline.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
variables:
serviceName: 'eventregistration-dev'
tagName: 'dev'
packageVersion: ''
prereleaseVersion: ''
pool:
name: ECS Build Agents
steps:
# Change the service name and tag name when running on master
- script: "echo '##vso[task.setvariable variable=serviceName]eventregistration-prod'"
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'master'), ne(variables['Build.Reason'], 'PullRequest'))
- script: "echo '##vso[task.setvariable variable=tagName]prod'"
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'master'), ne(variables['Build.Reason'], 'PullRequest'))
# Change the service name and tag name when running on eval
- script: "echo '##vso[task.setvariable variable=serviceName]eventregistration-eval'"
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'eval'), ne(variables['Build.Reason'], 'PullRequest'))
- script: "echo '##vso[task.setvariable variable=tagName]eval'"
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'eval'), ne(variables['Build.Reason'], 'PullRequest'))
# Download common build scripts
- task: DownloadBuildArtifacts@0
displayName: 'Download common build scripts'
inputs:
buildType: 'specific'
project: 'WS'
pipeline: 'uwwebservices.buildscripts'
buildVersionToDownload: 'LatestFromBranch'
branchName: 'refs/heads/master'
downloadType: 'specific'
itemPattern: '**'
downloadPath: '$(System.DefaultWorkingDirectory)/temp'
# Get package.json version
- task: PowerShell@2
displayName: Get package.json version
inputs:
targetType: 'inline'
script: |
[string] $packageVersion = (Get-Content package.json) -join "`n" | ConvertFrom-Json | Select -ExpandProperty "version"
Write-Host "Setting the package version variable to '$packageVersion'."
Write-Host "##vso[task.setvariable variable=packageVersion]$packageVersion"
# Set prereleaseVersion
- task: PowerShell@2
displayName: Set prereleaseVersion
condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'master'), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
targetType: 'inline'
script: |
[string] $dayOfYear = (Get-Date).DayOfYear
[string] $year = (Get-Date -Format "yy")
[string] $time = (Get-Date -Format "HHmm")
[string] $partialMinute = [Math]::Round((Get-Date -Format "ss") / 60d * 10)
[string] $versionNumber = "$(packageVersion)-$year$dayOfYear.$time$partialMinute"
Write-Host "Setting package.json version property to '$versionNumber' and leaving dirty"
$packageFile = (Get-Content package.json) -join "`n" | ConvertFrom-Json
$packageFile.version = $versionNumber
$packageFile | ConvertTo-Json | Set-Content package.json
Write-Host "Setting the name of the build AND the version number variable to '$versionNumber'."
Write-Host "##vso[task.setvariable variable=versionNumber]$versionNumber"
Write-Host "##vso[build.updatebuildnumber]$versionNumber"
# Download sp-key file from secure files
- task: DownloadSecureFile@1
displayName: 'Download sp-key file'
inputs:
secureFile: 'sp-key.pem'
# Copy files from source folder to target folder using match patterns (The match patterns will only match file paths, not folder paths)
- task: CopyFiles@2
displayName: 'Copy sp-key file to UWER project directory'
inputs:
overWrite: true
sourceFolder: '$(Agent.TempDirectory)'
contents: 'sp-key.pem'
targetFolder: '$(Build.SourcesDirectory)'
# Remove dangling docker images
- task: CmdLine@2
displayName: 'Remove dangling docker images'
inputs:
script: 'docker image prune -f'
# Build the docker image
- task: Docker@0
displayName: 'Build docker image'
inputs:
containerregistrytype: 'Container Registry'
imageName: 'eventregistrationimage'
qualifyImageName: false
includeLatestTag: true
# Push the new docker image up to AWS
- task: ECRPushImage@1
condition: |
and(
or(eq(variables['Build.SourceBranchName'], 'dev'), eq(variables['Build.SourceBranchName'], 'eval'), eq(variables['Build.SourceBranchName'], 'master')),
ne(variables['Build.Reason'], 'PullRequest')
)
displayName: 'Push docker image to AWS Container Registry'
inputs:
awsCredentials: 'AWS OTIK2'
regionName: 'us-east-1'
sourceImageName: 'eventregistrationimage'
repositoryName: eventregistration
pushTag: $(tagName)
# Poke the instance so it'll grab the newly uploaded image
- task: AWSCLI@1
condition: |
and(
or(eq(variables['Build.SourceBranchName'], 'dev'), eq(variables['Build.SourceBranchName'], 'eval'), eq(variables['Build.SourceBranchName'], 'master')),
ne(variables['Build.Reason'], 'PullRequest')
)
displayName: 'Force a new deployment for the new docker image'
inputs:
awsCredentials: 'AWS OTIK2'
regionName: 'us-east-1'
awsCommand: ecs
awsSubCommand: 'update-service'
awsArguments: '--cluster ews-cluster --service $(serviceName) --force-new-deployment'
failOnStandardError: true
- task: AWSCLI@1
condition: |
and(
or(eq(variables['Build.SourceBranchName'], 'dev'), eq(variables['Build.SourceBranchName'], 'eval'), eq(variables['Build.SourceBranchName'], 'master')),
ne(variables['Build.Reason'], 'PullRequest')
)
displayName: 'Wait for the service to become stable'
inputs:
awsCredentials: 'AWS OTIK2'
regionName: 'us-east-1'
awsCommand: ecs
awsSubCommand: 'wait'
awsArguments: 'services-stable --cluster ews-cluster --service $(serviceName)'
failOnStandardError: true