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
Create new project and setup gcloud.
Complete the “Before You Begin” section in the quickstart tutorial
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
andfunction 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.
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
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.Your website should be ready at this point! You can view your website by
gcloud app browse
When you are ready to publicise your blog, map your domain to the GAE instance.
Learn how to save cost in the next chapter!