Chilled Geek's Blog

Always curious, always learning

Blogging using Hugo, Firebase, and Gitlab

Posted at — Jan 22, 2018

Why set up a Hugo Blog

Setup

My overall setup was similar to that in ariya’s blog, and the components I used were as follow:

Get a domain

Set up a domain or subdomain. I used namecheap, but there are plenty of options to choose from.

Hugo (local setup)

Referencing quickstart to set up Hugo, here’s the procedure (and command line code below) for mac:

  1. Install Go and Hugo

    # For Mac
    brew install go
    brew install hugo
    # For Linux
    snap install hugo --channel=extended
  2. Create a directory (…/<website>) and set it up for Hugo

    mkdir .../<website>
    hugo new site .../<website>
  3. Add some content (change the value of draft to ‘false’ in file to make it visible)

    hugo new about.md # then edit this file
  4. Clone a bunch of default themes, or just choose just one theme or download (or create your own)

    git clone --recursive https://github.com/spf13/hugoThemes themes
  5. Edit the file config.toml to tailor the theme to your need (e.g. set baseurl = “http://blog.example.com/"), then build the site locally to see the results

    hugo server --theme=<theme> #Build site (specify folder name in themes)

Firebase (and Google Cloud Platform)

Setting up with Gitlab (or other similar version controlled repositories)

SSH from local computer

SSH config: Generate ssh key pair (I renamed it to gitlab and gitlab.pub) In ~/.ssh/config add (IdentityFile should be private key):

Host gitlab.com
    HostName gitlab.com
    PubkeyAuthentication yes
    IdentityFile ~/.ssh/gitlab

Create firehose.json

Create/edit firebase.json file and place it in the hugo-blog directory. The file should contain the following:

{
  "hosting": {
    "public": "public"
  }
}

Set up .gitlab-ci.yml file

Add environment variables FIREBASE_TOKEN and FIREBASE_PROJECTID in “Settings - CI/CD”

variables:
    GIT_SSL_NO_VERIFY: "true"
stages:
    - deploy
deploy:
    stage: deploy
    image: nohitme/hugo-firebase
    script:
        # build site
        - cd ${CI_PROJECT_DIR}
        - rm -rf public
        - hugo --theme=hugo-theme-cactus-plus-mod
        # upload
        - firebase deploy --token ${FIREBASE_TOKEN} --project ${FIREBASE_PROJECTID}
    only:
        - master