This page looks best with JavaScript enabled

2. Blog with Hugo on GAE

 ·  ☕ 2 min read  ·  🐨 Puliyo

We’ve covered how to create website in previous chapter.

This chapter describes how to deploy blog created with Hugo to Google App Engine.

Google App Engine

We’ll upload file to GAE as it’s cheap option for small sites.

NOTE: The free tier is available only for the Standard Environment.

Setup

  1. Create new project and setup gcloud.

    Complete the “Before You Begin” section in the quickstart tutorial

  2. Create main.go

    File main.go is referenced by GAE that has GO runtime.

    Below is the simple form of main.go

    package main
    
    import (
        "net/http"
    )
    
    func init() {
        http.Handle("/", http.FileServer(http.Dir("public")))
    }
    

    package main and function init() {...} is required for GAE.

    Within the function, we have http object serving the files under directory public.

    Hugo will generate files under directory ‘public’. All blog contents will be served from this file.

  3. Create app.yaml

    app.yaml controls the behaviour of your GAE:

    • what to be uploaded to the server
    • what url is valid and how it’s handled
    • instance management
    runtime: go
    api_version: go1
    env: standard
    
    # Resource non-hungry setting
    threadsafe: true
    automatic_scaling:
      max_instances: 1
      max_idle_instances: 1
      min_pending_latency: "3000ms"
    
    skip_files:
    - ^(?!public|main\.go).*$
    
    handlers:
    - url: /css
      static_dir: public/css
    
    - url: /js
      static_dir: public/js
    
    - url: /img
      static_dir: public/img
    
    - url: /fonts
      static_dir: public/fonts
    
    - url: /.*
      script: _go_app
    
  4. Deploy the codes to Google App Engine

    Issue gcloud app deploy to upload the files to GAE.

    If you haven’t ran gcloud init yet, you should call this first.

  5. Your website should be ready at this point! You can view your website by gcloud app browse

  6. When you are ready to publicise your blog, map your domain to the GAE instance.


Learn how to save cost in the next chapter!

Share on