Azure Deployment
Process to be followed for deploying the app on Azure
App convention
- GQC has now switched to a convention where we have separate folders for the
frontendof a project and thebackendof the project. - For the
ORSANCOproject, we have separate folders namely,orsanco_frontendorsanco_backend
ORSANCO/
orsanco_frontend/
src/
components/
package.json
orsanco_backend/
riverflows/
...
manage.py
.gitignore
requirements.txt
⚠️ Sudhir prefers deploying the apps directly from VSCode.
Frontend
There are multiple ways to deploy the React App to Azure.
As an App Service
As a Static Web App SWA with GitHub Actions
- Create a
SWAin the appropriate Resource Group - If you wish to have
Password Protectionin your app- Choose the
Standard Tier
- Choose the
- Choose the account/organization
- Choose the repo
- Choose the branch
- And Click Deploy
Backend
Generating the SECRET_KEY
To generate a SECRET_KEY in Djano, use the following command.
from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())
# or directly run this command
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
Deploy as an App Service
- Create an
App Servicein the appropriate Resource Group - Choose
Python 3.9as the stack andLinuxas the Operating System - To Deploy the App Service using CI through GitHub Actions,
- You will need to choose the
B1Tier for the App Service
- You will need to choose the
- Choose the account/organization
- Choose the repo
- Choose the branch
- And Click Deploy
Setting environment variables in Azure
⚠️ Deploying the App Service without setting the variables of DEBUG and SECRET_KEY, the deployment will fail.
- Click on
Configurationand add the following variables and their respective valuesSECRET_KEY = "secret key generated above"
DEBUG = False - In this app's case, the data comes from a Ubuntu VM running a PostgreSQL Database.
DB_NAME = orsanco_flows
DB_USER = gqc
DB_PASSWORD = gqc010102
DB_HOST = 20.14.140.39
DB_PORT = 5432
Managing requirements.txt
- Before deploying, on your local system, runto make sure things (endpoints) are working as expected
python manage.py check - Create a
requirements.txtusingpipreqsorpip freeze - ⚠️ With our current experience, both
pipreqsandpip freezehave a hard time creating a properrequirements.txt - Best way is to just create a new virutal environment locally and runand then iteratively add packages to the
python manage.py runserverrequirements.txt - Not having the
requirements.txtmade correctly will result in aModuleNotFoundErrorduring deployment.