Skip to content

Commit d8e2bb1

Browse files
project: Create simple Azure Static Web Apps #120 (#123)
Co-authored-by: Mohanalavala <[email protected]>
1 parent 059c2a8 commit d8e2bb1

File tree

8 files changed

+129
-0
lines changed

8 files changed

+129
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Azure Static Web Apps CI/CD
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "projects/azure-static-web-apps-simple/**"
9+
- ".github/workflows/azure-static-web-apps-salmon-field-0525b1010.yml"
10+
11+
pull_request:
12+
branches:
13+
- main
14+
paths:
15+
- "projects/azure-static-web-apps-simple/**"
16+
17+
jobs:
18+
build_and_deploy_job:
19+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
20+
runs-on: ubuntu-latest
21+
name: Build and Deploy Job
22+
steps:
23+
- uses: actions/checkout@v3
24+
with:
25+
submodules: true
26+
lfs: false
27+
- name: Build And Deploy
28+
id: builddeploy
29+
uses: Azure/static-web-apps-deploy@v1
30+
with:
31+
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_SALMON_FIELD_0525B1010 }}
32+
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
33+
action: "upload"
34+
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
35+
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
36+
app_location: "./projects/azure-static-web-apps-simple/src" # App source code path
37+
api_location: "" # Api source code path - optional
38+
output_location: "/" # Built app content directory - optional
39+
skip_app_build: true
40+
skip_api_build: true
41+
###### End of Repository/Build Configurations ######
42+
43+
close_pull_request_job:
44+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
45+
runs-on: ubuntu-latest
46+
name: Close Pull Request Job
47+
steps:
48+
- name: Close Pull Request
49+
id: closepullrequest
50+
uses: Azure/static-web-apps-deploy@v1
51+
with:
52+
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_SALMON_FIELD_0525B1010 }}
53+
action: "close"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This is the **third** repo of my DevOps trio repositories: [**tungbq/devops-basi
3131
| 10 | Deploy application on AKS with Istio | [aks-istio-application](./projects/aks-istio-application/) | ✔️ Done |
3232
| 11 | Nginx ingress with Istio service mesh on AKS | [aks-nginx-with-istio](./projects/aks-nginx-with-istio/) | ✔️ Done |
3333
| 12 | Deploy and Setup Jenkins on Kubernetes cluster | [jenkins-on-k8s](https://github.com/tungbq/K8sHub/tree/main/hands-on/jenkins-on-k8s) | ✔️ Done |
34+
| 13 | Azure Static Web Apps (Simple) | [azure-static-web-apps-simple](./projects/azure-static-web-apps-simple) | ✔️ Done |
3435

3536
### Explore our upcoming projects by visiting [this link](https://github.com/tungbq/devops-project/issues?q=is%3Aissue+is%3Aopen+label%3Aproject)
3637

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Project — Azure Static Web Apps (Simple)
2+
3+
This mini-project shows how to host a static website on **Azure Static Web Apps (SWA)** and deploy it automatically from GitHub using **GitHub Actions**.
4+
5+
---
6+
7+
## What you’ll build
8+
- A tiny static site (`index.html`, `styles.css`, `main.js`).
9+
- A GitHub Actions workflow that deploys only when files in this project change.
10+
11+
---
12+
13+
## Prerequisites
14+
- Azure subscription (Free tier is fine).
15+
- Fork of this repository with this project folder present.
16+
17+
---
18+
19+
## Create the Static Web App (Portal)
20+
21+
When creating the SWA in the Azure Portal:
22+
23+
- **Build preset:** `HTML`
24+
- **App location:** `projects/azure-static-web-apps-simple/src`
25+
- **API location:** *(leave blank)*
26+
- **Output location:** *(leave blank)*
27+
28+
- Static app creation Azure
29+
![](./src/assets/app1.png)
30+
![](./src/assets/app2.png)
31+
32+
If you connect GitHub in the portal creation wizard, Azure will generate a workflow in `.github/workflows/` for you. You can keep that, or use the generic workflow in this repo — just don’t keep **both** enabled at the same time.
33+
34+
---
35+
36+
## Local run
37+
Open `src/index.html` directly in your browser, or use any static server:
38+
39+
cd projects/azure-static-web-apps-simple/src
40+
python -m http.server 8000
41+
42+
43+
44+
## Reference documents
45+
46+
- Azure: https://learn.microsoft.com/en-us/azure/static-web-apps/get-started-portal?tabs=vanilla-javascript&pivots=github
292 KB
Loading
240 KB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>Azure Static Web Apps — Simple</title>
7+
<link rel="stylesheet" href="./styles.css" />
8+
</head>
9+
<body>
10+
<main>
11+
<h1>🚀 Azure Static Web Apps</h1>
12+
<p>This site is deployed from <code>projects/azure-static-web-apps-simple/src</code>.</p>
13+
<button id="ping">Ping</button>
14+
<pre id="out"></pre>
15+
</main>
16+
<script src="./main.js"></script>
17+
</body>
18+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
document.getElementById("ping").addEventListener("click", () => {
2+
const out = document.getElementById("out");
3+
out.textContent = `SWA is up! ${new Date().toLocaleString()}`;
4+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:root { font-family: system-ui, Arial, sans-serif; }
2+
body { margin: 0; background: #0f172a; color: #e2e8f0; }
3+
main { max-width: 720px; margin: 6rem auto; padding: 2rem; background: #111827; border-radius: 16px; }
4+
h1 { margin-top: 0; }
5+
button { padding: 0.6rem 1rem; border-radius: 8px; border: none; cursor: pointer; }
6+
pre { background: #0b1220; padding: 1rem; border-radius: 8px; overflow: auto; }
7+

0 commit comments

Comments
 (0)