Artists Booking Venues powered by Python (Flask) and PostgreSQL Database. There is no user authentication or per-user data stored.
The project is designed for deployment on Azure App Service with a PostgreSQL flexible server. See deployment instructions below.
-
Download the project starter code locally
git clone https://github.com/john0isaac/flask-webapp-postgresql-db.git cd flask-webapp-postgresql-db
-
Initialize and activate a virtualenv using:
python -m virtualenv venv source venv/bin/activate
Note - In Windows, the
venv
does not have abin
directory. Therefore, you'd use the analogous command shown below:source venv/Scripts/activate deactivate
-
Install the dependencies:
pip install -r requirements.txt
-
Run the development server:
export FLASK_APP=app.py export FLASK_ENV=development export FLASK_DEBUG=true flask run --reload
-
Verify on the Browser
Navigate to project homepage http://127.0.0.1:5000/ or http://localhost:5000
This repository is set up for deployment on Azure App Service (w/PostgreSQL flexible server) using the configuration files in the infra
folder.
To deploy your own instance, follow these steps:
-
Sign up for a free Azure account
-
Install the Azure Dev CLI.
-
Initialize a new
azd
environment:azd init
It will prompt you to provide a name (like "flask-app") that will later be used in the name of the deployed resources.
-
Provision and deploy all the resources:
azd up
It will prompt you to login, pick a subscription, and provide a location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to "centralus") can help, as there may be availability constraints for some of the resources.
-
When azd has finished deploying, you'll see an endpoint URI in the command output. Visit that URI to browse the app! 🎉
If you make any changes to the app code, you can just run this command to redeploy it:
azd deploy
It is important to secure the databases in web applications to prevent unwanted data access. This infrastructure uses the following mechanisms to secure the PostgreSQL database:
- Azure Firewall: The database is accessible only from other Azure IPs, not from public IPs. (Note that includes other customers using Azure).
- Admin Username: A unique string generated based on the resource name (not random, but not a standard name, either).
- Admin Password: Randomly generated and updated on each deploy.
- PostgreSQL Version: Latest available on Azure, version 14, which includes security improvements.
Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage.
You can try the Azure pricing calculator for the resources:
- Azure App Service: Free Tier with shared CPU cores, 1 GB RAM. Pricing
- PostgreSQL Flexible Server: Burstable Tier with 1 CPU core, 32GB storage. Pricing is hourly. Pricing
azd down
.
-
Open the Google Cloud Shell and execute the following command:
git clone https://github.com/john0isaac/flask-webapp-postgresql-db.git cd flask-webapp-postgresql-db
-
Create the env_variables.yaml file that contains your secret environment variables.
nano env_variables.yaml
-
Add your Google Cloud SQL database connection details
env_variables: DB_USER_NAME: 'secret' DB_PASSWORD: 'secret' DB_NAME: 'secret' DB_HOST: '111.111.111.111' DB_PORT: '5432' DB_CONNECTOR: 'postgresql+pg8000' INSTANCE_UNIX_SOCKET: '/cloudsql/Connection name' DEPLOYMENT_LOCATION: 'gcp'
-
save and exit the file CTRL+x followed by y followed by Enter.
-
Deploy the web application.
gcloud app deploy app.yaml
-
Create a Cloud SQL instance using the following parameters:
- Specify instance name and password.
- Select production instead of production plus.
- Select Single Zone.
- Specify the machine configuration of 2 vCPUs and 8 GB Memory.
- Select the smallest storage option available 10 GB.
- Add your IP to the Instance Network.
- Select Create.
- Create a database and call it fyyur.
- Create a user and call it john.
- Grant All privileges to user john.
-
Import Data dump.
-
Pull the code to the Cloud Shell.
-
Create environment variables .yaml file.
-
Enable App Engine.
-
execute the following command
gcloud beta app repair
. -
execute the following command
gcloud app deploy --no-cache
.