This tutorial will demonstrate how to deploy an existing Python site to App Engine. A bare bones Python site can be found in this Github repository. |
|
Install the Google Cloud Command Line Interface for your specific platform by following the instructions provided by Google.
Skip this step if you already have a project created. You will need the project's name in Step 4.
Proceed to the Google Cloud Console to create a new Google Cloud Project.
Each GCP project can host ONLY ONE App Engine project. If you need to host more than one site, you'll have to create a new project for each.
Copy the name of the project. You will use it in the next step.
On the command line, navigate into the directory that contains your application's files.
If you are using the sample application noted above, this would be the directory that contains the main.py file.
Open the Terminal/command line on your local machine where you install the Google Cloud CLI. Set the current working project with the following command:
gcloud config set project project-name
Use the project name you created in Step 2 in place of project-name
All App Engine deployments require a configuration file entitled app.yaml
Using your favorite code editor, create an app.yaml file in the top level of the directory holding your website files.
Add the following to the app.yaml file.
runtime: python39
With your Cloud project selected, deployment to App Engine is simple:
gcloud app deploy
The first time that you deploy your app, you will be asked to choose a region. Select the region that is geographically closest to you (likely us-central). You will not be asked this on subsequent deployments.
Step 7: View your Application
After a few moments, your application will be hosted online in App Engine. Look for the Target URL in the App Engine setup notifications.
From the command line, you can also launch your application in a browser with this command:
gcloud app browse
A sample remote repository for this application can be found here.