This is a nextjs project consisting a OpenLayer Map that show beautiful windy style layer. The main goal of this website is to showcase complete workflow of auto deploy pipeline using Github Actions to Microsoft Azure platform.
Two approaches were practiced:
-
IaaS Approach using Azure Virtual Machines:
- Deploy the application on an Azure Ubuntu Virtual Machine.
- Manage the entire VM, including Docker containers, ports, application dependencies.
- Suitable for scenarios requiring deep customisation and control over the server environment.
-
PaaS Approach using Azure Web App Service and Azure Container Apps:
- Deploy the application using Azure Web App Service for managed hosting.
- Utilize Azure Container Instances to deploy the Docker image from Container Registry.
- Simplifies deployment and management with less overhead.
The application is hosted on:
-
Azure Ubuntu Virtual Machine (Production, discontinued)
-
Azure Web App Service (Staging, discontinued): https://nextjsazure.azurewebsites.net/
-
Azure Container App (Staging, discontinued): http://suizer.bqazfuf4fmdfdjgr.southeastasia.azurecontainer.io/
-
Vercel (dev site with no database connection): https://nextjsazure.vercel.app/
In the project directory, you can run:
Runs the app in the development mode.
npm install
npm run dev
Open http://localhost:8000/ to view it in the browser.
The page will reload if you make edits. You will also see any lint errors in the console.
To fix all formatting and linting using prettier
:
npm run format
DATABASE_URL=sqlserver://
SDATABASE_URL=sqlserver:// # Shadow database for prisma migration
You can store the env variable somewhere using .env or setting this inside your container or pipeline variables so it don't get exposed
In this project we use Prisma ORM to talk with database:
npx prisma init
npx prisma generate
npx prisma migrate dev
Must have wsl2 and Docker Desktop installed:
docker-compose up --build
docker exec nextjsazure-nextjsazure-1 npx prisma generate
docker exec nextjsazure-nextjsazure-1 npm run format
- Go to Azure Portal
- Create a resource group
- Create a container registry (ACR) under same resource group
- Create a web service/container instance tied to that ACR
You will also need to install Azure Cli to perform:
az login
az account set --subscription "<Your-Subscription-Name-Or-ID>"
az ad sp create-for-rbac --name "<Your-Service-Principal-Name>" --role contributor --scopes /subscriptions/{SubscriptionId}/resourceGroups/<Your-Resource-Group-Name>
az webapp log tail --name <app-name> --resource-group <resource-group-name> # log
Follow the Dockerfile configuration, then go to: https://learn.microsoft.com/en-gb/azure/app-service/configure-custom-container?pivots=container-linux&tabs=debian#enable-ssh
Many people have been facing issues establishing a connection between Azure linux hosted web app and Azure SQL database server. Some of the forum discussions: https://serverfault.com/questions/1104918/azure-app-service-to-sql-server-db-connection-fails-with-generic-error-occurred
The alternative way is to use a Azure virtual machine instead.
If you are looking to deploy this Next.js app on an Azure Ubuntu VM, please refer to the documentation provided here.