Skip to content

Instantly share code, notes, and snippets.

@sgarciav
Last active February 9, 2023 17:44
Show Gist options
  • Save sgarciav/5e200465d44d242714f385edbc48ecd5 to your computer and use it in GitHub Desktop.
Save sgarciav/5e200465d44d242714f385edbc48ecd5 to your computer and use it in GitHub Desktop.
Setup a Python Web app with Google Cloud

References

App Engine

First Time Installation

  1. Install the Google Cloud SDK:
$ echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
$ sudo apt update
$ sudo apt install google-cloud-cli
$ sudo apt install google-cloud-cli-app-engine-python
  1. Setup up a Google App Engine account (here)

  2. Create a new App Engine project from the Dashboard view.

  3. Authenticate your project on your machine:

$ gcloud init

Deploy the App

Execute anytime you want to update your app on the server:

$ cd /path/to/project (where the `app.yaml` file lives)
$ gcloud app deploy

Cloud Storage

Activate Default Bucket

Taken from this tutorial, follow these steps to activate the default Cloud Storage bucket for your app:

Click Create under Default Cloud Storage Bucket in the App Engine settings page for your project. Notice the name of this bucket: it is in the form <project-id>.appspot.com.

NOTES:

  • If you need more storage than the 5GB limit, you can increase this by enabling billing for your project, making this a paid bucket. You will be charged for storage over the 5GB limit.
  • The App Engine services are enough if users will not be uploading files. Cloud storage is needed in order for the app to read/write files.

Writing your app

Follow these instructions to make sure that your app correctly handles the read/write functions.

The beginning of the linked tutorial asks you to create a new bucket and make it publicly readable:

$ gsutil mb gs://[YOUR_BUCKET_NAME]
$ gsutil defacl set public-read gs://[YOUR_BUCKET_NAME]

Authenticate Account

If you're making use of the Cloud Storage services, you'll need to authentica your account first. Taken from this tutorial, execute the following and follow the prompts to log into your Google account:

$ gcloud auth login

After login, you should see the page: You are now authenticated with the gcloud CLI!. There are several additional resources on the page that you can explore, or you can close the page and continue developing.

After authentication, define the current project by executing:

$ gcloud config set project [PROJECT_ID]

You should now have the green light to deploy your app (see above).

General Notes

  • To disable an app, go to the Settings tab in the cloud webpage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment