Hosting Hugo On Google App Engine

August 6, 2017
Using html or javascript or enable BlackFriday.hrefTargetBlank

Hugo Deployment

Ensure config.toml baseURL is live URL.

baseURL = "https://hugo-app.appspot.com/"

Compile the content for publishing using hugo command.

hugo
# Output
Started building sites ...
Built site for language en:
0 of 13 drafts rendered
0 future content
0 expired content
78 regular pages created
154 other pages created
1 non-page files copied
85 paginator pages created
51 tags created
total in 724 ms

Create Google Cloud and Google App Engine Project

Create a project on Google Cloud Platform.

  • Remember your Project ID

Create an App Engine app

  • Language: Python (pick a language you are familar with, though it doesn’t matter for static website)
  • Region: us-central (depending on your audience)
  • Don’t have to proceed with the Quickstart Tutorial.

Create App Engine

Install Google Cloud SDK

Download the latest Google Cloud SDK

Extract the package (e.g. tar -zxf google-cloud-sdk*.tar.gz)

Run install script to add SDK rools to your path

./google-cloud-sdk/install.sh
# Output
Modify profile to update your $PATH and enable shell command
completion? [Y]
Enter a path to an rc file to update, or leave blank to use
[ENTER]

Initialize the SDK (enter your Google credential and select Project ID)

./google-cloud-sdk/bin/gcloud init

# You can respond "n" to the following
API [compute-component.googleapis.com] not enabled on project
[793702336627]. Would you like to enable and retry?  (Y/n)?

Create App Engine project files

Create a directory for your app engine project.

mkdir hugo-app
cd hugo-app

Create an app.yaml file.

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /
  static_files: www/index.html
  upload: www/index.html

- url: /(.*)
  static_files: www/\1
  upload: www/(.*)

Create www as symbolic link to hugo’s public directory.

ln -s /hugo/public www

Deploy to App Engine

Deploy local files to App Engine server.

gcloud app deploy -v 1
# output
Services to deploy:

descriptor:      [/hugo-app/app.yaml]
source:          [/hugo-app]
target project:  [hugo-app-id]
target service:  [default]
target version:  [1]
target url:      [https://hugo-app.appspot.com]


Do you want to continue (Y/n)?  Y

Launch brower to preview the website

gcloud app browse -v 1

References

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.