-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
243 lines (215 loc) · 8.16 KB
/
azure-pipelines.yml
File metadata and controls
243 lines (215 loc) · 8.16 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# This pipeline sets the build number using variables from a linked group,
# builds a Node.js application, publishes it, and then deploys it to an Azure Web App,
# updating an app setting with the generated build number.
# The 'name' property defines the format of the build number.
# It uses variables from the linked variable group and $(Rev:r) for a unique revision.
# IMPORTANT: Ensure 'ragfrontend-global-vars' contains MajorVersion, MinorVersion.
name: 'v$(MajorVersion).$(MinorVersion).$(ReleaseVersion).$(Date:yyyyMMdd).$(Rev:r)'
trigger:
branches:
include:
- main
- develop
- release/*
pool:
vmImage: 'ubuntu-latest'
variables:
- group: ragfrontend-global-vars
- name: system.debug
value: true
stages:
- stage: Build
displayName: 'Build Stage'
jobs:
- job: Build
displayName: 'Build Job'
steps:
- task: NodeTool@0
inputs:
versionSpec: '22.x'
displayName: 'Install Node.js'
# Replace NEXT_PUBLIC_VERSION in .env file with build.buildNumber
- script: |
cat << EOF > .env
NEXT_PUBLIC_VERSION=$(Build.BuildNumber)
NEXT_PUBLIC_V2_SERVER_URL=https://app-ragbackend-dev-wus-001.azurewebsites.net
NEXT_PUBLIC_V2_SERVER_URL_WS=wss://app-ragbackend-dev-wus-001.azurewebsites.net
EOF
displayName: 'Update .env with build number and other variables'
- task: CmdLine@2
displayName: 'npm install and build'
inputs:
script: |
npm install
npm run build --if-present
- task: CmdLine@2
displayName: 'Prepare output folder (build‐artifacts)'
inputs:
script: |
rm -rf output
mkdir -p output
cp -r .next/standalone/* output/ # Copy contents of .next/standalone (includes server.js)
cp -r .next output/ # Copy the entire .next directory
rm -rf output/.next/cache # Optional: Remove cache to reduce ZIP size
cp -r public output/ # Copy public folder
cp package.json output/
cp package-lock.json output/
cp next.config.mjs output/
- task: ArchiveFiles@2
displayName: 'Zip artifact for deployment'
inputs:
rootFolderOrFile: 'output'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/release.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
displayName: 'Publish build artifact'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'node-app'
publishLocation: 'Container'
# Dev Deployment Stage
- stage: Deploy_Dev
displayName: 'Deploy to Dev'
dependsOn: Build
condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/heads/develop'))
jobs:
- deployment: DeployDev
displayName: 'Deploy to Azure Web App - Dev'
variables:
- group: ragfrontend-dev-vars
environment:
name: ragmodel_dev
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: node-app
- task: CmdLine@2
displayName: 'Verify downloaded artifact'
inputs:
script: |
echo "Listing downloaded artifacts:"
ls -la $(Pipeline.Workspace)/node-app
- task: AzureAppServiceManage@0
displayName: 'Stop the Azure Web App'
inputs:
azureSubscription: 'Sparc-Azure'
Action: 'Stop Azure App Service'
WebAppName: 'app-ragfrontend-dev-wus-001'
- task: AzureRmWebAppDeployment@5
displayName: 'Deploy to Azure Web App - Dev'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Sparc-Azure'
appType: 'webAppLinux'
WebAppName: 'app-ragfrontend-dev-wus-001'
packageForLinux: '$(Pipeline.Workspace)/node-app/release.zip'
RuntimeStack: 'NODE|22-lts'
DeploymentTypeLinux: 'zipDeploy'
TakeAppOfflineFlag: true
CleanDeploymentFlag: true
StartupCommand: 'node server.js'
AppSettings: '-NEXT_PUBLIC_V2_SERVER_URL "$(BackEndServer_URL)" -NEXT_PUBLIC_VERSION "$(Build.BuildNumber)"'
- task: AzureAppServiceManage@0
displayName: 'Start the Azure Web App'
inputs:
azureSubscription: 'Sparc-Azure'
Action: 'Start Azure App Service'
WebAppName: 'app-ragfrontend-dev-wus-001'
# Stage Deployment Stage
- stage: Deploy_Stage
displayName: 'Deploy to Stage'
dependsOn: Build
condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/heads/release'))
jobs:
- deployment: DeployDev
displayName: 'Deploy to Azure Web App - Stage'
environment:
name: ragmodel_stage
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: node-app
- task: CmdLine@2
displayName: 'Verify downloaded artifact'
inputs:
script: |
echo "Listing downloaded artifacts:"
ls -la $(Pipeline.Workspace)/node-app
- task: AzureAppServiceManage@0
displayName: 'Stop the Azure Web App'
inputs:
azureSubscription: 'Sparc-Azure'
Action: 'Stop Azure App Service'
WebAppName: 'app-ragfrontend-stg-wus-001'
- task: AzureRmWebAppDeployment@5
displayName: 'Deploy to Azure Web App - Stage'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Sparc-Azure'
appType: 'webAppLinux'
WebAppName: 'app-ragfrontend-stg-wus-001' # Update this to your actual Stage Web App name
packageForLinux: '$(Pipeline.Workspace)/node-app/release.zip'
RuntimeStack: 'NODE|22-lts'
DeploymentTypeLinux: 'zipDeploy'
TakeAppOfflineFlag: true
CleanDeploymentFlag: true
StartupCommand: 'node server.js'
- task: AzureAppServiceManage@0
displayName: 'Start the Azure Web App'
inputs:
azureSubscription: 'Sparc-Azure'
Action: 'Start Azure App Service'
WebAppName: 'app-ragfrontend-stg-wus-001'
# Stage Deployment Prod
- stage: Deploy_Prod
displayName: 'Deploy to Prod'
dependsOn: Deploy_Stage
condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/heads/release'))
jobs:
- deployment: DeployDev
displayName: 'Deploy to Azure Web App - Prod'
environment:
name: ragmodel_Prod
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: node-app
- task: CmdLine@2
displayName: 'Verify downloaded artifact'
inputs:
script: |
echo "Listing downloaded artifacts:"
ls -la $(Pipeline.Workspace)/node-app
- task: AzureAppServiceManage@0
displayName: 'Stop the Azure Web App'
inputs:
azureSubscription: 'Sparc-Azure'
Action: 'Stop Azure App Service'
WebAppName: 'app-ragfrontend-prod-inc-001'
- task: AzureRmWebAppDeployment@5
displayName: 'Deploy to Azure Web App - Stage'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Sparc-Azure'
appType: 'webAppLinux'
WebAppName: 'app-ragfrontend-prod-inc-001' # Update this to your actual Stage Web App name
packageForLinux: '$(Pipeline.Workspace)/node-app/release.zip'
RuntimeStack: 'NODE|22-lts'
DeploymentTypeLinux: 'zipDeploy'
TakeAppOfflineFlag: true
CleanDeploymentFlag: true
StartupCommand: 'node server.js'
- task: AzureAppServiceManage@0
displayName: 'Start the Azure Web App'
inputs:
azureSubscription: 'Sparc-Azure'
Action: 'Start Azure App Service'
WebAppName: 'app-ragfrontend-prod-inc-001'