-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontend-pipeline.yml
145 lines (138 loc) · 5.13 KB
/
frontend-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
141
142
143
144
145
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- main
resources:
- repo: self
variables:
# Variable groups
- group: acr_service_connection
- group: arm_service_connection
- group: docker_build_arguments
# Hardcoded variables
- name: imageRepository
value: "dapalpha"
- name: dockerfilePath
value: "$(Build.SourcesDirectory)/gascd_app/Dockerfile"
- name: tag
value: "$(Build.BuildId)"
- name: vmImageName
value: "ubuntu-latest"
# Environment parameters to iterate through
parameters:
- name: environments
type: object
default:
- name: dev
environment_name: 'Webapp - dev'
arm_connection: "$(dev_arm_service_connections)"
acr_connection: "$(dev_acr_connection)"
acr_name: "$(dev_acr_name)"
container_port: "$(dev_container_port)"
- name: test
environment_name: 'Webapp - test'
arm_connection: "$(test_arm_service_connections)"
acr_connection: "$(test_acr_connection)"
acr_name: "$(test_acr_name)"
container_port: "$(test_container_port)"
- name: uat
environment_name: 'Webapp - UAT'
arm_connection: "$(uat_arm_service_connections)"
acr_connection: "$(uat_acr_connection)"
acr_name: "$(uat_acr_name)"
container_port: "$(uat_container_port)"
- name: prod
environment_name: 'Webapp - prod'
arm_connection: "$(prod_arm_service_connections)"
acr_connection: "$(prod_acr_connection)"
acr_name: "$(prod_acr_name)"
container_port: "$(prod_container_port)"
stages:
# Build/deploy across environments
- ${{ each environment in parameters.environments}}:
# Build
- stage: Build_${{environment.name}}
displayName: "${{environment.name}}: Build and push stage"
condition: succeeded()
jobs:
- deployment: Build
displayName: Build
environment: "${{environment.environment_name}}"
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: Docker@2
displayName: Build an image
inputs:
command: build
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: ${{environment.acr_connection}}
arguments: >
--build-arg CONTAINER_PORT=${{environment.container_port}}
--build-arg NEXT_PUBLIC_APP_ENV=${{environment.name}}
tags: |
$(tag)
latest
- task: Docker@2
displayName: Push an image to container registry
inputs:
command: push
repository: $(imageRepository)
containerRegistry: ${{environment.acr_connection}}
tags: |
$(tag)
latest
# Test
- stage: Test_${{environment.name}}
displayName: "${{environment.name}}: Run jest tests"
dependsOn: Build_${{environment.name}}
condition: succeeded()
jobs:
- job: JestTest
displayName: Run Jests Tests
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
- task: NodeTool@0
inputs:
versionSpec: "16.x"
- script: npm install
displayName: install dependencies
workingDirectory: gascd_app
- script: npm run test -- --reporters=default --reporters=jest-junit --outputFile=gascd_app/junit.xml
displayName: Run Jest Tests
workingDirectory: gascd_app
- task: PublishTestResults@2
displayName: Publish Test Results
inputs:
testResultsFormat: "JUnit"
searchFolder: "$(Build.SourcesDirectory)"
testResultsFiles: "gascd_app/junit.xml"
failTaskOnFailedTests: true
# Deploy
- stage: Deploy_${{environment.name}}
displayName: "${{environment.name}}: Deploy to Azure Web App"
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: "${{environment.name}}"
pool:
vmImage: "ubuntu-latest"
strategy:
runOnce:
deploy:
steps:
- task: AzureWebAppContainer@1
inputs:
appType: "webAppLinux"
appName: "dapalpha-${{environment.name}}-app"
azureSubscription: ${{environment.arm_connection}}
containers: "${{environment.acr_name}}.azurecr.io/$(imageRepository):$(tag)"