Back

Continuously Deploy a Hugo Site with GitLab CI CD and Surge.sh

Hi all, long time no see.. After a few year left a blogging world, i decide to write again in my blog.

In this post i wanna share my step to deploy a hugo static site using gitlab ci cd to surge.sh. I decide to use surge sh because support custom domain with no terms (until i write this ya).

Prerequisite:

  • Hugo
  • Gitlab Account
  • Surge Cli

Example of workflow : Hugo -> Gitlab CI/CD -> Surge.sh

First you need a hugo site that has been pushed to gitlab. After that, you need create .gitlab-ci.yml like this :

image: node:8-alpine

before_script:
    - npm install -g surge
    - npm install --save-dev hugo-bin
    - node --version
    - surge --version
    - surge list  --token $SURGE_TOKEN
    - $(npm bin)/hugo version

surge_deploy:
  only:
    - master
  script:
    - rm -rf public
    - $(npm bin)/hugo
    - surge --project ./public/ --token $SURGE_TOKEN --domain putrafirman.com

Before you push .gitlab-ci.yml you must set surge credentials in gitlab ci/cd configuration. In your local computer, type in terminal surge token and you will be get the token.

Set SURGE_LOGIN with your email, and SURGE_TOKEN with your token what you get from local terminal. And commit your .gitlab-ci.yml. Voila! Your site is deployed and can get access with your domain (or can get free subdomain from surge.sh).