Skip to content

Instantly share code, notes, and snippets.

@mlsaito
Last active April 15, 2023 12:16
Show Gist options
  • Save mlsaito/5120e11a8c27c309345845a90a0568c5 to your computer and use it in GitHub Desktop.
Save mlsaito/5120e11a8c27c309345845a90a0568c5 to your computer and use it in GitHub Desktop.
Deploy Static Files to Google App Engine using Python (Always Free Tier!)

Deploy Static Files to Google App Engine using Python (Always Free Tier!)

By default, GAE (Google App Engine) supports Python as one of their default run time, which is always free!

Advantages of deploying static site to Google App Engine:

  1. It's always free! Google Cloud Platform provides always-free-tier for standard environment - hence Python!
  2. Free, auto-renewing SSL cert for custom domains.
  3. Direct traffic to instance instead of routing it through cloudflare for free cert.
  4. Makes deployment easier in just one line (using gcloud CLI tool).

Original reference here: https://cloud.google.com/appengine/docs/flexible/custom-runtimes/quickstart

Steps

  1. Install google-cloud-sdk
$ brew tap caskroom/cask
$ brew cask install google-cloud-sdk
  1. Initialize SDK
$ gcloud init
  1. Enable billing for newly created GAE (Google App Engine) app
Visit console directly or click:
https://console.developers.google.com/project/{project_name}/settings

Don't forget to replace {project_name} with your project name.
  1. Create project folder and boilerplate files
$ mkdir portfolio/public
$ cd portfolio
$ touch app.yaml
$ echo "<h1>Hi there!</h1>" > public/index.js
  1. Edit app.yaml - this maps the routes to static files.

app.yaml

runtime: python27
api_version: 1
threadsafe: true

default_expiration: "30d"

handlers:
# site root
- url: /
  static_files: public/index.html
  upload: public/index.html
  expiration: "15m"
  secure: always

Check full app.yaml here which copies and maps everything:

Note: This is GAE specific. Check documentation here.

  1. Deploy app
$ gcloud app deploy

That's it!

You can stream logs from the command line by running:

$ gcloud app logs tail -s default

To view your application in the web browser run:

$ gcloud app browse

Next Steps:

  1. Add custom domain through GAE.
  2. Enable SSL through GAE.
@hidaytrahman
Copy link

Do we have still have this always free tier?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment