Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/main_todowebapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Node.js app to Azure Web App - todowebapp

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read #This is required for actions/checkout

steps:
- uses: actions/checkout@v4

- name: Set up Node.js version
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: node-app
path: .

deploy:
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write #This is required for requesting the JWT
contents: read #This is required for actions/checkout

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: node-app

- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_75A14F9C328D47B08B58CBC222D3DFBD }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_BDB2E7EDDC1D4A56B646FA78FBC7B7BF }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_516375029F6B42C2A83CCBD564858F93 }}

- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: 'todowebapp'
slot-name: 'Production'
package: .

60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ products:
- azure-app-service
- azure-monitor
- azure-pipelines
- github-actions
urlFragment: todo-nodejs-mongo
name: React Web App with Node.js API and MongoDB on Azure
description: A complete ToDo app on Azure App Service with Node.js API and Azure Cosmos API for MongoDB for storage. Uses Azure Developer CLI (azd) to build, deploy, and monitor
Expand Down Expand Up @@ -54,6 +55,65 @@ azd init --template Azure-Samples/todo-nodejs-mongo
azd up
```

## Deployment via GitHub Actions (Cloud-only)

If you want to deploy directly from GitHub without installing tools locally, configure GitHub Actions as follows.

### 1. Generate Azure Credentials

Run the following command in **Azure Cloud Shell**:

```bash
az ad sp create-for-rbac --name "github-auth-sp" --role contributor --scopes /subscriptions/<SUBSCRIPTION_ID> --sdk-auth
```

Replace `<SUBSCRIPTION_ID>` with your Azure Subscription ID.
The command returns a JSON credential.

---

### 2. Add GitHub Secret

Open your repository and navigate to:

**Settings → Secrets and variables → Actions**

Create a **New repository secret**:

```
Name: AZURE_CREDENTIALS
Value: <Paste the entire JSON output from Step 1>
```

---

### 3. Add GitHub Variables

Go to **Settings → Secrets and variables → Variables** and add:

```
AZURE_SUBSCRIPTION_ID = <Your Azure Subscription ID>
AZURE_LOCATION = centralindia
AZURE_ENV_NAME = todo-node-env
```

---

### 4. Run Deployment

Trigger the workflow by pushing a commit:

```bash
git add .
git commit -m "trigger deployment"
git push origin main
```

Or run it manually from:

**GitHub → Actions → Run workflow**


### Application Architecture

This application utilizes the following Azure resources:
Expand Down