-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (93 loc) · 3.52 KB
/
eshoponweb-cicd.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
name: eShopOnWeb Build and Test
#Triggers (uncomment line below to use it)
on: [push, workflow_dispatch]
#Environment variables https://docs.github.com/en/actions/learn-github-actions/environment-variables
env:
RESOURCE-GROUP: rg-eshoponweb-rhost
LOCATION: eastus
TEMPLATE-FILE: infra/webapp.bicep
SUBSCRIPTION-ID: a1035237-b0c8-484b-8e38-06ec7562dddf
WEBAPP-NAME: eshoponweb-webapp-rhost
jobs:
#Build, test and publish .net web project in repository
buildandtest:
runs-on: ubuntu-latest
steps:
#checkout the repository
- uses: actions/checkout@v4
#prepare runner for desired .net version SDK
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-quality: 'preview'
#Build/Test/Publish the .net project
- name: Build with dotnet
run: dotnet build ./eShopOnWeb.sln --configuration Release
- name: Test with dotnet
run: dotnet test ./eShopOnWeb.sln --configuration Release
- name: dotnet publish
run: |
dotnet publish ./src/Web/Web.csproj -c Release -o ${{env.DOTNET_ROOT}}/myapp
cd ${{env.DOTNET_ROOT}}/myapp
zip -r ../app.zip .
# upload the published website code artifacts
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/app.zip
# upload the bicep template as artifacts for next job
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: bicep-template
path: ${{ env.TEMPLATE-FILE }}
# Use Bicep to deploy infrastructure + Publish webapp
deploy:
runs-on: ubuntu-latest
needs: buildandtest
environment:
name: 'Development'
steps:
#Download the publish files created in previous job
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: .net-app
path: .net-app
#Download the bicep templates from previous job
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: bicep-template
path: bicep-template
#Login in your azure subscription using a service principal (credentials stored as GitHub Secret in repo)
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Deploy Azure WebApp using Bicep file
- name: deploy
uses: azure/arm-deploy@v2
with:
subscriptionId: ${{ env.SUBSCRIPTION-ID }}
resourceGroupName: ${{ env.RESOURCE-GROUP }}
template: bicep-template/webapp.bicep
parameters: 'webAppName=${{ env.WEBAPP-NAME }} location=${{ env.LOCATION }}'
failOnStdErr: false
# Publish website to Azure App Service (WebApp)
# Step disabled due to issue where the site sometimes can't be found: https://github.com/microsoft/pipelines-appservice-lib/issues/56. Instead deploy using CLI
- name: Publish Website to WebApp
if: false #Disable step due to comment above
uses: Azure/webapps-deploy@v3
with:
type: ZIP
app-name: ${{ env.WEBAPP-NAME }}
package: .net-app/app.zip
# Publish website to Azure App Service using CLI (WebApp)
- name: Publish Website to WebApp
uses: Azure/cli@v2
with:
inlineScript: |
az webapp deploy --name ${{ env.WEBAPP-NAME }} --resource-group ${{ env.RESOURCE-GROUP }} --src-path .net-app/app.zip --type zip