Skip to content

Commit 5064361

Browse files
authored
Merge pull request #1 from vtjc2002/main
update azure devops pipeline yaml file to build and deploy
2 parents 9b36ad9 + 7a3b408 commit 5064361

File tree

3 files changed

+142
-1
lines changed

3 files changed

+142
-1
lines changed

.azdo/pipelines/app-ci.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
trigger:
2+
- main
3+
4+
pool:
5+
vmImage: 'ubuntu-latest'
6+
7+
stages:
8+
- stage: Build
9+
jobs:
10+
- job: WebApp
11+
steps:
12+
- task: Npm@1
13+
displayName: 'Npm Install'
14+
inputs:
15+
command: 'install'
16+
workingDir: 'app/frontend/'
17+
- task: Npm@1
18+
displayName: 'Npm run build'
19+
inputs:
20+
command: 'custom'
21+
workingDir: 'app/frontend/'
22+
customCommand: 'run build'
23+
24+
- task: Maven@4
25+
displayName: 'Build springboot app'
26+
inputs:
27+
mavenPomFile: 'app/backend/pom.xml'
28+
goals: 'package'
29+
javaHomeOption: 'JDKVersion'
30+
jdkVersionOption: '1.17'
31+
jdkArchitectureOption: 'x64'
32+
publishJUnitResults: true
33+
mavenVersionOption: 'Default'
34+
mavenAuthenticateFeed: false
35+
effectivePomSkip: false
36+
sonarQubeRunAnalysis: false
37+
38+
# get jar name from pom.xml and set it as output variable so Deploy job and use it
39+
- task: Bash@3
40+
displayName: 'Get jar file name from pom.xml'
41+
inputs:
42+
targetType: 'inline'
43+
script: |
44+
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
45+
artifactId=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
46+
echo "##vso[task.setvariable variable=jarfilename;isOutput=true]$artifactId-$version"
47+
workingDirectory: 'app/backend/'
48+
name: pomvariable
49+
50+
# copy final jar file to target folder
51+
- task: CopyFiles@2
52+
displayName: 'Copy jar file'
53+
inputs:
54+
Contents: 'app/backend/target/$(pomvariable.jarfilename).jar'
55+
TargetFolder: '$(Build.ArtifactStagingDirectory)'
56+
57+
# upload the artifact to spring-boot-app container
58+
- task: PublishBuildArtifacts@1
59+
displayName: 'Upload springboot app artifacts'
60+
inputs:
61+
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
62+
ArtifactName: 'spring-boot-app'
63+
publishLocation: 'Container'
64+
65+
- stage: DeployDev
66+
condition: eq(variables['Build.SourceBranch'], 'refs/heads/dev')
67+
dependsOn: Build
68+
variables:
69+
buildjarfilename: $[ stageDependencies.Build.WebApp.outputs['pomvariable.jarfilename'] ]
70+
jobs:
71+
- deployment: DeploySpringbootApp
72+
displayName: 'Azure Web App'
73+
variables:
74+
- group: azureSearchOpenAiDemoJavaDev
75+
- name: buildjarfilename
76+
value: $[ stageDependencies.Build.WebApp.outputs['pomvariable.jarfilename'] ]
77+
environment: 'dev'
78+
strategy:
79+
runOnce:
80+
deploy:
81+
steps:
82+
- task: AzureWebApp@1
83+
displayName: 'Azure Web App'
84+
inputs:
85+
azureSubscription: '<azureSubscriptionServiceConnection>'
86+
appType: 'webAppLinux'
87+
appName: '$(azureAppServiceName)'
88+
package: '$(Pipeline.Workspace)/**/$(buildjarfilename).jar'
89+
runtimeStack: 'JAVA|17-java17'
90+
startUpCommand: 'java -jar /home/site/wwwroot/$(buildjarfilename).jar'
91+
92+
- stage: DeployProd
93+
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
94+
dependsOn: Build
95+
variables:
96+
- group: azureSearchOpenAiDemoJavaProd
97+
- name: buildjarfilename
98+
value: $[ stageDependencies.Build.WebApp.outputs['pomvariable.jarfilename'] ]
99+
100+
jobs:
101+
- deployment: DeploySpringbootApp
102+
displayName: 'Azure Web App'
103+
environment: 'prod'
104+
strategy:
105+
runOnce:
106+
deploy:
107+
steps:
108+
- task: AzureWebApp@1
109+
displayName: 'Azure Web App'
110+
inputs:
111+
azureSubscription: '<azureSubscriptionServiceConnection>'
112+
appType: 'webAppLinux'
113+
appName: '$(azureAppServiceName)'
114+
package: '$(Pipeline.Workspace)/**/$(buildjarfilename).jar'
115+
runtimeStack: 'JAVA|17-java17'
116+
startUpCommand: 'java -jar /home/site/wwwroot/$(buildjarfilename).jar'

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ Once in the web app:
106106
* Click on "settings" to try different options, tweak prompts, etc.
107107

108108
## App Continuous Integration
109+
110+
### GitHub
109111
if you don't want to use azd to build and deploy the app, a GitHub automated CI pipeline is provided in `.github/workflows/app-ci.yml`. Some notes about the CI pipeline design:
110112
- It uses a "branch per environment approach". The deploy environment name is computed at 'runtime' based on a git branch. You can check branch/env-name mapping logic in the "set environment for branch" step (line 29). The current implemented logic maps everything to a dev like environment. Therefore on each git push on the `main branch` the pipeline is triggered trying to deploy to an environment called `Development`. For more info about GitHub environments and how to set specific env variables and secrets read [here](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment).
111113
- GitHub environment variables and secrets are used to configure development environment specific configuration. They need to be configured manually in github repository settings:
@@ -123,6 +125,29 @@ To properly configure automated build and deploy for both backend and frontend c
123125

124126
![pipeline success](./docs/github-actions-pipeline-success.png)
125127

128+
### Azure DevOps
129+
Azure Devops can also be used to build and deploy the app. Azure Devops automated CICD pipeline is provided in `.azdo/pipelines/app-ci.yaml`. Some notes about the CICD pipeline design:
130+
- Similar to Github action above, this pipeline uses branch per environment approach as well.
131+
- Azure Devops library variable groups and variables are used to configure environment specific configuration. They need to be configured manually in Azure Devops Pipeline Library.
132+
1. Navigate to Pipeline / Library
133+
2. Add new variable group `azureSearchOpenAiDemoJavaDev` and variable `azureAppServiceName`. Put the name of the Azure App Service for development as the value.
134+
3. Add new variable group `azureSearchOpenAiDemoJavaProd` and variable `azureAppServiceName`. Put the name of the Azure App Service for production as the value.
135+
136+
Connect Azure Devops to the Github Repo:
137+
1. Create a new pipeline.
138+
2. For 'Where is your code?' Select Github.
139+
3. Go through the Github App authentication process [Github App](https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml#github-app-authentication).
140+
4. Select Existing Azure Pipeline YAML file.
141+
5. Point dropdown values to the path `.azdo/pipelines/app-ci.yaml`.
142+
6. Do not Run but Save the pipeline.
143+
Once saved, you will see dev and prod enviornment got automatically created under Pipeline / Enviornments. You can setup Approvals and Checks within enviornments if necessary.
144+
145+
Connect Azure Devops to Azure:
146+
1. Add a Service Connection following this [guide](https://learn.microsoft.com/en-us/azure/devops/pipelines/library/connect-to-azure?view=azure-devops) to allow Azure Devops pipeline to connect to your Azure resources /App Service.
147+
2. Modify `.azdo/pipelines/app-ci.yaml` '<azureSubscriptionServiceConnection>' and replace it with the name of the Service Connection.
148+
149+
You can now either run the pipeline manually or commit to a branch to trigger the pipeline.
150+
126151
## Custom Data Ingestion and Indexing
127152
The repo includes sample pdf documents in the data folder. They are ingested in blob container and indexed in azure cognitive search during infra provisioning by azure developer cli post provision hooks (see line 23 in [azure.yaml](azure.yaml))
128153

azure.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ hooks:
3131
shell: sh
3232
run: ./scripts/prepdocs.sh
3333
interactive: true
34-
continueOnError: false
34+
continueOnError: false

0 commit comments

Comments
 (0)