hsano.jp

Note from daily life.

Deploying the Hugo based project to Firebase Hosting by using CircleCI

Posted at — Aug 3, 2019

Prerequisites

Configuration

Generate a token for CI service to connect Firebase

Run the following command.

firebase login:ci

Follow the instruction. (an URL appears or you will be navigated to the page, and then approve to grant permissions to the token.) Then, the token appears on your console.

Save the toke to CircleCI

To make a token usable as an environment variable in CircleCI, save your token as name FIREBASE_TOKEN by one of the ways below:

  1. Project page > Settings > Environment Variables under BUILD SETTINGS
  2. Home of your account > SETTINGS > Contexts

Place a config file for CircleCI

Save the below YAML as .circleci/config.yml.

version: 2
jobs:
  build:
    docker:
      - image: cibuilds/hugo:latest
    steps:
      - checkout
      - run: mkdir public
      - run: hugo
      - persist_to_workspace:
          root: .
          paths:
            - .
  deploy:
    docker:
      - image: circleci/node:latest
    steps:
      - attach_workspace:
          at: .
      - run: npm install firebase-tools
      - run: ./node_modules/.bin/firebase deploy --token=$FIREBASE_TOKEN
workflows:
  version: 2
  build-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master

What this setting is doing is…

  1. Build: Launching Hugo environment by using cibuilds/hugo:latest image, generating static files in ./public, then persist the workspace.
  2. Deploy: Launching NodeJS environment by using circleci/node:latest image, install firebase-tools, then deploying.

The workflows part defines the dependency, and filtering branch to trigger CI or not.

Enjoy!

comments powered by Disqus