Skip to content

Commit abca6c5

Browse files
committed
Updated workflow, readme and script
1 parent becb494 commit abca6c5

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@ You can deploy [this script](./azure/azure_arm_free_app_and_database.json) direc
99
4. Provide the required parameters:
1010
- Student Number 👈 Will be used to prefix the resource names
1111
- SQL Administrator Credentials
12-
- The IP address you would like to allow to access the resources (you can add more in the portal)
12+
- The Home IP address you would like to allow to access the resources (you can add more in the portal)
1313
5. Press Create
1414

1515
After the deployment has succeeded, navigate to output parameters and save these values. You need them later when you setup the GitHub Workflow.
1616

17-
#### Notes
17+
** Notes **
1818
- The free **SQL Server database** is **not available** in `westeurope`, so the script defaults to `northeurope`.
19-
- The SQL Server **uses SQL Authentication only**, as setting up Entra ID authentication via ARM scripts is not straightforward.
19+
- The SQL Server **uses SQL Authentication only**, as setting up Entra ID authentication through ARM templates is not straightforward.
2020

21-
## Create additional SQL user
22-
Execute [this script](./sql/create_database_user.sql) on the Azure SQL Database to create a contained SQL database user with only read/write access
21+
## GitHub Workflow Simplified
22+
This scripts takes the outputs from the Azure ARM template and the project name and uses it to create a simple CI/CD workflow through GitHub actions.
23+
24+
1. Add [this script](./github/github_workflow_simplified.yaml) in the Git repository under `/.github/workflows`
25+
2. Enter the ARM outputs as repository secrets in Github
26+
27+
The following secrets are required to run this worflow
28+
* AZURE_WEBAPP_NAME 👉 The name of the web application in Azure (output from the ARM template)
29+
* AZURE_WEBAPP_PUBLISH_PASSWORD 👉 The publishing user password (output from the ARM template)
30+
* AZURE_WEBAPP_PUBLISH_USERNAME 👉 The publishing user name (output from the ARM template)
31+
* WEBAPI_PROJECT_NAME 👉 The name of the project needed to publish
2332

33+
The secrets are used to construct a publishing profile. Unfortunately it is not possible to extract the full publish profile through the ARM template.
34+
35+
** Notes **
36+
* It checks if the secrets are available, if not, cancels the flow
37+
* It defaults to DOTNET_CORE_VERSION: 9.0.x but this is tested with .NET 8 projects as well
38+
39+
## Create additional SQL user
40+
Execute [this script](./sql/create_database_user.sql) on the Azure SQL Database to create a contained SQL database user with only read/write access.

github/github_workflow_simplified.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Build, Test and Deploy a .NET Core WebApi to Azure App Service
33
env: # Change these settings if you like
44
ARTIFACT_NAME: WebApi
55
DOTNET_CORE_VERSION: 9.0.x
6-
WORKING_DIRECTORY: "./ProjectMap.WebApi"
76
PUBLISH_DIRECTORY: "./out/publish"
87
on:
98
push:
@@ -15,10 +14,39 @@ on:
1514
workflow_dispatch:
1615

1716
jobs:
17+
check: # checking if the secrets exist (src: https://stackoverflow.com/questions/72925899/github-actions-detect-if-secret-exists)
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: "Check if AZURE_WEBAPP_NAME secret exists"
21+
env:
22+
super_secret: ${{ secrets.AZURE_WEBAPP_NAME }}
23+
if: ${{ env.super_secret == '' }}
24+
run: 'echo "echo the secret \"AZURE_WEBAPP_NAME\" has not been made; echo please go to \"settings \> Actions secrets and variables \> actions\" to create it"; exit 1;'
25+
26+
- name: "Check if AZURE_WEBAPP_PUBLISH_PASSWORD secret exists"
27+
env:
28+
super_secret: ${{ secrets.AZURE_WEBAPP_PUBLISH_PASSWORD }}
29+
if: ${{ env.super_secret == '' }}
30+
run: 'echo "echo the secret \"AZURE_WEBAPP_PUBLISH_PASSWORD\" has not been made; echo please go to \"settings \> Actions secrets and variables \> actions \" to create it"; exit 1;'
31+
32+
- name: "Check if AZURE_WEBAPP_PUBLISH_USERNAME secret exists"
33+
env:
34+
super_secret: ${{ secrets.AZURE_WEBAPP_PUBLISH_USERNAME }}
35+
if: ${{ env.super_secret == '' }}
36+
run: 'echo "echo the secret \"AZURE_WEBAPP_PUBLISH_USERNAME\" has not been made; echo please go to \"settings \> Actions secrets and variables \> actions\" to create it"; exit 1;'
37+
38+
- name: "Check if WEBAPI_PROJECT_NAME secret exists"
39+
env:
40+
super_secret: ${{ secrets.WEBAPI_PROJECT_NAME }}
41+
if: ${{ env.super_secret == '' }}
42+
run: 'echo "echo the secret \"WEBAPI_PROJECT_NAME\" has not been made; echo please go to \"settings \> Actions secrets and variables \> actions\" to create it"; exit 1;'
43+
1844
build:
1945

2046
runs-on: ubuntu-latest
47+
needs: check
2148
steps:
49+
2250
- uses: actions/checkout@v4
2351
- name: Setup .NET
2452
uses: actions/setup-dotnet@v4
@@ -35,7 +63,7 @@ jobs:
3563
run: dotnet test --no-build --verbosity normal
3664

3765
- name: Publish
38-
run: dotnet publish ${{ env.WORKING_DIRECTORY }} --output ${{env.PUBLISH_DIRECTORY}} --configuration Release
66+
run: dotnet publish ./${{ secrets.WEBAPI_PROJECT_NAME }} --output ${{env.PUBLISH_DIRECTORY}} --configuration Release
3967

4068
- name: Publish Artifacts
4169
uses: actions/upload-artifact@v4
@@ -45,7 +73,7 @@ jobs:
4573

4674
deploy:
4775
runs-on: ubuntu-latest
48-
needs: build
76+
needs: [check, build]
4977
steps:
5078

5179
- name: Download artifact from build job

sql/create_database_user.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ CREATE USER MY_APPLICATION_USER WITH PASSWORD = '(a safe password here)'
22

33
EXEC sp_addrolemember 'db_datawriter', 'MY_APPLICATION_USER';
44
EXEC sp_addrolemember 'db_datareader', 'MY_APPLICATION_USER';
5+
6+
7+
-- After this the Azure Connection String will look something like this
8+
-- Server=tcp:avansict(studentnummer).database.windows.net,1433;Initial Catalog=db(studentnummer);Persist Security Info=False;User ID=MY_APPLICATION_USER;Password=(a safe password here);MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

0 commit comments

Comments
 (0)