Skip to content

Commit bded8b9

Browse files
committed
Updated pipeline to use service principal with federated credential to authenticate with Azure in order to deploy the static web app instead of using the deprecated approach
1 parent 988bebd commit bded8b9

File tree

8 files changed

+95
-275
lines changed

8 files changed

+95
-275
lines changed

.github/workflows/deploy_to_azure.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ jobs:
4545
deploy-function:
4646
runs-on: ubuntu-latest
4747
needs: build-function
48-
environment:
49-
name: 'Production'
50-
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
48+
permissions:
49+
id-token: write
50+
contents: read
5151
steps:
5252
- name: Download artifact from build job
5353
uses: actions/download-artifact@v4
@@ -57,11 +57,6 @@ jobs:
5757
- name: Unzip artifact for deployment
5858
run: unzip release.zip
5959

60-
- name: Login to Azure using Service Principal
61-
uses: azure/login@v1
62-
with:
63-
creds: ${{ secrets.AZURE_CREDENTIALS }}
64-
6560
- name: Deploy to Azure Functions
6661
uses: Azure/functions-action@v1
6762
id: deploy-to-function
@@ -71,6 +66,7 @@ jobs:
7166
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
7267
scm-do-build-during-deployment: true
7368
enable-oryx-build: true
69+
publish-profile: ${{ secrets.PUBLISH_PROFILE }}
7470

7571
build-react:
7672
runs-on: ubuntu-latest
@@ -103,6 +99,9 @@ jobs:
10399
deploy-react:
104100
runs-on: ubuntu-latest
105101
needs: build-react
102+
permissions:
103+
id-token: write
104+
contents: read
106105
steps:
107106
- name: Download React build artifact
108107
uses: actions/download-artifact@v4
@@ -112,10 +111,12 @@ jobs:
112111
- name: Unzip React build
113112
run: unzip build.zip
114113

115-
- name: Login to Azure using service principal
116-
uses: azure/login@v1
114+
- name: Login to Azure with OIDC
115+
uses: azure/login@v2
117116
with:
118-
creds: ${{ secrets.AZURE_CREDENTIALS }}
117+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
118+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
119+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
119120

120121

121122
- name: Deploy React build to Azure Static Website

README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Static web app invoking Azure functions
22

3-
Static web app built with the React framework. The [application](client/src/App.js) allows users to upload CSV files to a storage blob via an HTTP-triggered function.
4-
The uploaded files are then processed by a blob-triggered function, which stores the results in a separate container. Aforementioned functions
5-
are present in the [function_app.py](hvalfangst_function/function_app.py) python script - which is the main entrypoint of our Azure Function App instance.
3+
This repository contains a [static web app](client/src/App.js), which enables users to upload CSV files containing demographic and financial data about individuals to a designated storage blob via an HTTP-triggered Azure Function.
4+
Once uploaded to the blob, another, blob-triggered function calculates correlations between various variables, such as experience, state, gender, and income. The computed statistics are then stored in a separate storage blob.
5+
These functions are defined in the python script [function_app.py](hvalfangst_function/function_app.py) - which is the main entrypoint of our Azure Function App instance.
66

7-
A pipeline has been set up to deploy the function app and the static web app to Azure using GitHub Actions. The pipeline is triggered by a push to the main branch or by manually running the workflow.
7+
The associated Azure infrastructure is deployed with a script (more on that below).
88

9+
A branch-triggered pipeline has been set up to deploy our code to the respective Azure resources using a GitHub Actions Workflows [script](.github/workflows/deploy_to_azure.yml).
10+
The two functions are deployed using the Function App's associated **publish profile**, whereas the static web app is deployed using a service principal configured with a federated credential.
11+
Note that the static web app is actually hosted directly on a storage blob, which is configured to serve static websites. Thus, deploying the web app is simply a matter of uploading the files to the designated blob container.
912

1013

1114
## Requirements
@@ -18,8 +21,8 @@ A pipeline has been set up to deploy the function app and the static web app to
1821

1922
## Allocate resources
2023

21-
The shell script [allocate_resources](infra/allocate_resources.sh) creates Azure resources specified in a
22-
[Bicep](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview?tabs=bicep) template [file](infra/main.bicep).
24+
The shell script [allocate_resources](infra/allocate_resources.sh) creates Azure resources using the Azure CLI and a
25+
[Bicep](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview?tabs=bicep) template [file](infra/main.bicep).
2326

2427
It will create the following hierarchy of resources:
2528

@@ -41,20 +44,13 @@ graph TD
4144
B -->|Contains| F
4245
```
4346

44-
## Deallocate resources
45-
46-
The shell script [deallocate_resources](infra/deallocate_resources.sh) deletes our Azure resources.
47-
48-
# CI/CD
49-
50-
A CI/CD pipeline for deploying our [Function App](hvalfangst_function/function_app.py) to Azure has been set up using a GitHub Actions workflows [script](.github/workflows/deploy_to_azure.yml). The pipeline is either triggered by a push to the main branch or by manually running the workflow.
51-
In order for the pipeline to work, the following secrets must be set in the repository settings:
52-
53-
![img.png](img.png)
54-
55-
The associated values of the aforementioned secret can be retrieved from the Azure portal, under our deployed Function App.
56-
Click on the **Get publish profile** button and copy/paste the file content into the secret value field.
57-
58-
![img_1.png](img_1.png)
47+
## GitHub secrets
48+
Four secrets are required in order for the GitHub Actions Workflow script to deploy the code to the Azure resources.
49+
As may be observed in the [script](.github/workflows/deploy_to_azure.yml), these are:
5950

51+
- **AZURE_CLIENT_ID**: Used to authenticate the service principal in order to deploy the static web app
52+
- **AZURE_SUBSCRIPTION_ID**: Used to authenticate the service principal in order to deploy the static web app
53+
- **AZURE_TENANT_ID**: Used to authenticate the service principal in order to deploy the static web app
54+
- **PUBLISH_PROFILE**: Used to deploy our two functions to the Azure Function App
6055

56+
![img_1.png](images/img_1.png)

client/package-lock.json

Lines changed: 12 additions & 233 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)