Skip to content

Commit 988bebd

Browse files
committed
Created static web app with the React framework for uploading CSV files to Azure blob storage by calling an HTTP-triggered Azure Function
1 parent 975aa6e commit 988bebd

24 files changed

+18177
-33
lines changed

.github/workflows/deploy_to_azure.yml

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ on:
99
env:
1010
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'
1111
PYTHON_VERSION: '3.10'
12+
STORAGE_ACCOUNT_NAME: 'hvalfangststorageaccount'
1213

1314
jobs:
14-
build:
15+
build-function:
1516
runs-on: ubuntu-latest
1617
steps:
1718
- name: Checkout repository
@@ -41,13 +42,12 @@ jobs:
4142
release.zip
4243
!venv/
4344
44-
deploy:
45+
deploy-function:
4546
runs-on: ubuntu-latest
46-
needs: build
47+
needs: build-function
4748
environment:
4849
name: 'Production'
4950
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
50-
5151
steps:
5252
- name: Download artifact from build job
5353
uses: actions/download-artifact@v4
@@ -57,7 +57,12 @@ jobs:
5757
- name: Unzip artifact for deployment
5858
run: unzip release.zip
5959

60-
- name: 'Deploy to Azure Functions'
60+
- name: Login to Azure using Service Principal
61+
uses: azure/login@v1
62+
with:
63+
creds: ${{ secrets.AZURE_CREDENTIALS }}
64+
65+
- name: Deploy to Azure Functions
6166
uses: Azure/functions-action@v1
6267
id: deploy-to-function
6368
with:
@@ -66,4 +71,60 @@ jobs:
6671
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
6772
scm-do-build-during-deployment: true
6873
enable-oryx-build: true
69-
publish-profile: ${{ secrets.PUBLISH_PROFILE }}
74+
75+
build-react:
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Checkout repository
79+
uses: actions/checkout@v4
80+
81+
- name: Setup Node.js
82+
uses: actions/setup-node@v3
83+
with:
84+
node-version: 16
85+
86+
- name: Install dependencies
87+
run: npm install
88+
working-directory: ./client
89+
90+
- name: Build React app
91+
run: npm run build
92+
working-directory: ./client
93+
94+
- name: Zip build folder
95+
run: zip -r build.zip ./client/build
96+
97+
- name: Upload React build artifact
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: react-build
101+
path: build.zip
102+
103+
deploy-react:
104+
runs-on: ubuntu-latest
105+
needs: build-react
106+
steps:
107+
- name: Download React build artifact
108+
uses: actions/download-artifact@v4
109+
with:
110+
name: react-build
111+
112+
- name: Unzip React build
113+
run: unzip build.zip
114+
115+
- name: Login to Azure using service principal
116+
uses: azure/login@v1
117+
with:
118+
creds: ${{ secrets.AZURE_CREDENTIALS }}
119+
120+
121+
- name: Deploy React build to Azure Static Website
122+
uses: azure/CLI@v1
123+
with:
124+
azcliversion: latest
125+
inlineScript: |
126+
az storage blob upload-batch \
127+
--account-name hvalfangststorageaccount \
128+
--source ./client/build \
129+
--destination '$web' \
130+
--overwrite

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
# Python API integrated with Azure Service Bus Queue
1+
# Static web app invoking Azure functions
2+
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.
6+
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.
8+
9+
210

311
## Requirements
412

513
- **Platform**: x86-64, Linux/WSL
6-
- **Programming Language**: [Python 3](https://www.python.org/downloads/)
14+
- **Programming Languages**: [React](https://reactjs.org/docs/getting-started.html), [Python 3](https://www.python.org/downloads/)
715
- **Cloud Account**: [Azure](https://azure.microsoft.com/en-us/pricing/purchase-options/azure-account)
816
- **Resource provisioning**: [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/)
917

@@ -21,6 +29,7 @@ graph TD
2129
A --> B[Resource Group]
2230
B --> C[Storage Account]
2331
C --> D[Blob Container]
32+
D -->|Static Website Hosting| H[index.html]
2433
B --> E[App Service Plan]
2534
E -->|Hosts| G[Function App]
2635
G -->|Uses| F[Application Insights]
@@ -32,24 +41,9 @@ graph TD
3241
B -->|Contains| F
3342
```
3443

35-
For this script to work it is necessary to have a configuration file named **infra_config.env** in your [infra](infra) directory. It contains sensitive information
36-
such as tenant and subscription id as well as information used to reference resources. The file has been added to our [.gitignore](.gitignore) so that you don't accidentally commit it.
37-
### Structure of 'infra/infra_config.env'
38-
```bash
39-
TENANT_ID={TO_BE_SET_BY_YOU_MY_FRIEND}
40-
SUBSCRIPTION_ID={TO_BE_SET_BY_YOU_MY_FRIEND}
41-
LOCATION=northeurope
42-
RESOURCE_GROUP_NAME=hvalfangstresourcegroup
43-
STORAGE_ACCOUNT_NAME=hvalfangststorageaccount
44-
BLOB_CONTAINER_NAME=hvalfangstblobcontainer
45-
FUNCTION_APP_NAME=hvalfangstfunctionapp
46-
SERVICE_PLAN_NAME=hvalfangstserviceplan
47-
APP_INSIGHTS_NAME=hvalfangstappinsights
48-
```
49-
5044
## Deallocate resources
5145

52-
The shell script [deallocate_resources](infra/deallocate_resources.sh) deletes our Azure service bus queue, namespace and resource group.
46+
The shell script [deallocate_resources](infra/deallocate_resources.sh) deletes our Azure resources.
5347

5448
# CI/CD
5549

@@ -61,4 +55,6 @@ In order for the pipeline to work, the following secrets must be set in the repo
6155
The associated values of the aforementioned secret can be retrieved from the Azure portal, under our deployed Function App.
6256
Click on the **Get publish profile** button and copy/paste the file content into the secret value field.
6357

64-
![img_1.png](img_1.png)
58+
![img_1.png](img_1.png)
59+
60+

client/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

0 commit comments

Comments
 (0)