This is a flask app that hosts a course enrollment site for a traffic school. The - very simple - web page save the enrollments to course in a MySQL instance hosted on Google Cloud. The app is deployed with Docker and run in a Google CLoud Run instance.
The data from the app is written to a GCP mySQL instance and sent to a pubsub topic. From there, there is a pubsub subscriber that reads the data from the topic and writes it to a GCP BigQuery table.
The app can be spinned up locally or hosted in Google Cloud Run.
- Create a MySQl Instance on Google - choose settings that suit you. Make the instance public
- Add your IP to the range of allowed IPs on the SQL instance page. Also add the vaule to the secret manager
- Create a database via the UI and add the name to the env file and to the secret manager
- Add a user via the UI and add the name and the password to the env file and to the secret manager.
- Log in with the user you just created
- Create the table needed with the sql in the setup folder
Create a virtual environment
python -m venv course_app
- cd into it and activate it with
Scripts/activateInstall the packages in requirements.txtpip install -r requirements.txtUncomment the CREDENTIAL_PATH lines in app.py
- Uncomment the CREDENTIAL_PATH lines in app.py
- Open docker desktop to start the docker engine
- In case you have made changes in the repo and need to update the image, do it with
docker build . -t course_app - Create credentials with
gcloud auth application-default loginGo to the file and paste the content in the file named in application_default_credentials.json in the Repos/secrets folder - Start the container with
docker run -it -v “C:\Users\Ch_EP\OneDrive\Skrivbord\Repos\secrets:/app/auth" -p 5000:5000 course_appdocker run -it -p 5000:5000 course_app`
- Upload your repo to GitHub
- Go to Cloud Run in the GCP UI. Click on build from GitHub
- Follow the steps. For example with the help of https://medium.com/codex/continuously-deploying-a-flask-app-from-a-github-repository-to-google-cloud-run-6f26226539b0#
- When done, go to Triggers. Make sure the correct settings are here. Especially that the correct service account is chosen
- Go to Permissions and make sure the correct service account is also used there
- Go to Artefact UI
- Click on create a new repository
- Fill in the info
- Run
gcloud auth configure-docker europe-west3-docker.pkg.devExchange the region with your region - Tag your local picture
docker build -t europe-west3-docker.pkg.dev/etl-test-404717/course-app/course-app:1.0.0 .. Exchange the region, the project, the repo-name (from artefact repo name) and the image name - Push it to GCP
docker push europe-west3-docker.pkg.dev/etl-test-404717/course-app/course-app:1.0.0
- Plan what kind of transformations should be done to the raw data and what technology?
- Set up one transformation Job
- Create a few different outputports (unique Students, unique courses?, exams?)
- Set up dataplex / Data Catalouge
- Create some Notebook
- Do some AI project
Install needed packages (for mysql)
- pip install SQLAlchemy
- pip install PyMySQL
- pip install "cloud-sql-python-connector[pymysql]"
- pip install python-dotenv
Might be you have to gcloud auth application-default login (no!) Add the needed database name, user name and password in the env file Load the env file into the test sql connection file Add a row in this file and check if it got there
The database will run up costs even though you turn it off. To properly save costs you need to delete it and store it as a backup This backup can be put back to live an all data within, users and so on will persist. However, the region you have to set again (europe3, Frankfurt) and the IP will de different. Update the env variable MYSQL_PUBLIC_IP_ADDRESS with the new IP and run the script again. If you need to update your own Ip Address to the whitelist, see here how to do it in the right format https://mxtoolbox.com/subnetcalculator.aspx.