By now, you’ve build a gorgeous Hugo site that you admire at http://localhost:1313 that no one but you can see. This post aims to help you fix that, by taking the first deployment step: putting your Hugo site into a GCS bucket. This assumes that you also have git bash installed with the Google Cloud SDK (
gsutil), and that you’re familiar enough with http://console.cloud.google.com that you can log in and double check your settings. This also assumes that you’ve purchased a domain name that you administer through http://domains.google. Now! to begin.
Step 1 – Build your Hugo site. Even though you can view it on localhost, the static site hasn’t been built yet.
cd /d/Hugo/myrealsite hugo
That’s it! The GO engine behind Hugo just created a ton of static web pages on your behalf, and popped them into the /public directory. Go into that directory and ls -spla just to make sure stuff is there.
Step 2 – Use
gsutil to set up your new bucket and tell Google Cloud that it will be a web site. You should still be sitting in
/d/Hugo/myrealsite. Note: The domain name MUST have
www in the beginning, even if you want to direct people to yourdomainname.yourtld.
gsutil mb gs://www.yourdomainname.yourtld gsutil web set -m index.html -e 404.html gs://www.yourdomainname.yourtld
Step 3 – Make everything in that bucket public so people on the internet have the permissions to get to your page. This part was a little tricky for me, because I’m not sure exactly which command made it work, but I can tell you how to double check. Start by doing one (or both) of these:
gsutil defacl ch -u allUsers:R gs://www.yourdomainname.yourtld gsutil iam ch allUsers:objectViewer gs://www.yourdomainname.yourtld
When you go into http://console.cloud.google.com, head to Storage -> Browser. Find the line item that has your http://www.yourdomainname.yourtld name that you just created. In the “Public Access” column, there should be a little orange warning icon and the words “Public to Internet”. If you don’t see that, then Google around for more advice on “how to make the contents of your GCS bucket public to the internet”.
While you’re in there, check to make sure the bucket is set up to serve a web page. On the far far right side of that same line, you’ll see three vertical dots. Click on them, and go into “Edit Website Configuration”. The top textbox should say
index.html and the bottom should say
404.html. If they don’t, make them say that, and then click Save.
Step 4 – Populate your GCS bucket with your built Hugo site in
/public (not the raw files you edited). Make sure you’re still sitting in
/d/Hugo/myrealsite and then do this:
gsutil rsync -R public gs://www.yourdomainname.yourtld
Step 5 – You now have a Hugo web site on Google Cloud! Test it out by pointing a browser to
https://storage.googleapis.com/www.yourdomainname.yourtld/index.html (being sure to put your actual domain name in there) — if you get a permission error or an XML dump, go back to Step 3 because something went wrong there.
Now it’s time to link your bought domain name with your publicly visible Hugo web site!