Python App Development on Google Cloud Platform (GCP)
A Tutorial On How to Deploy Python App on GCP
Google Cloud Platform supports Python 3. If you are a python developer and you are still new in Google Cloud Platform, this article will guide you step by step. Please keep on reading
Knowing the basics Google Cloud Platform
Google Cloud Console, Cloud Shell, Google Command Line, Google Editor, Virtual Machine Instance, Google Compute Engine, Google API.
Google Cloud Console: An interface basis on the web to run the google cloud platform.
Cloud Shell: a Debian-based virtual machine and as the terminal environment for you to manage GCP projects and resources easily by typing the google command line.
Google Command Line
You can utilize this instrument to perform numerous platform tasks in scripts, or command lines, or another automation.
Reference :
https://cloud.google.com/sdk/gcloud/reference and https://cloud.google.com/sdk/docs/cheatsheet
Google Cloud Editor
https://cloud.google.com/shell/docs/viewing-and-editing-files
Virtual Machine Instance
A virtualized operating system or application environment to implement software in the cloud system that can be run on Google infrastructure.
Google Compute Engine
A Google service on the google cloud platform permits clients to dispatch virtual machines on request.
Google API
This tool is the way for you to interact on the Google Cloud Platform by enabling the APIs and Services on the google cloud console
Set Up Python Environment
Prepare the Python environment for your local machine
- Install the latest version of Python.
- Use
venv
to isolate dependencies. - Install an editor (optional): Sublime Text, Atom, Pycharm
- Install the Cloud SDK (optional).
- Install the Cloud Client Libraries for Python (optional).
- Install other useful tools.
Step by step to Run App Dev with python on GCP
You must have an account on the GCP first. You should register for a new account if you are a new GCP user. If you already had it, log in to your GCP account.
After that, You need to create the virtual machine instance with google compute engine first.
Here are the steps to create VM instance on Google Console :
- On the Google Cloud Console, Choose Compute Engine, VM Instance then click create
2. Create the instance: Type The name, select the Region and the Zone
3. Allow full access to all Cloud APIs in the Identity and API section.
4. Enable Allow HTTP traffic in the firewall.
5. Create
6. Click The instance you just created on the VM instance page
7. Click SSH to open the browser window
Still in SSH Window, Now Install Software.
Here is a step by step guidance for you:
- Update The Debian Package list: Sudo apt-get update
- Install Git: Sudo apt-get install git
- Install python :
sudo apt-get install python3-setuptools python3-dev build-essential
4. Install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Sudo python3 get-pip.py
Verify Python Installation
- python3 — version
- pip3 — version
- git clone https://github.com/GoogleCloudPlatform/training-data-analyst (This is a sample file from Google Cloud Platform)
- cd ~/training-data-analyst/courses/developingapps/python/devenv/
- sudo python3 server.py
Then Configure your Virtual Machine so you can run the Application
Navigation menu ===> Compute Engine ===> Virtual Instances, and click on the External IP address for the instance that you just created it before.
- Return to the SSH window, and stop the application by pressing Ctrl+c.
- sudo pip3 install -r requirements.txt
- python3 list-gce-instances.py <PROJECT_ID> — zone=<YOUR_VM_ZONE>
Resource & credits :
Google Cloud Platform Documentation
Qwiklabs Hands-On Google