Hosting a Hugo site with firebase

This are all the steps needed to deploy your static Hugo page on Firebase for free (until you exceed the traffic of the free tier a.k.a Spark plan).
Firebase
Setup
- Go to https://console.firebase.google.com and create a new project (unless you already have a project and this is just an additional component to it).
- Install
firebase-tools
(node.js) using:npm install -g firebase-tools
- Login to firebase (setup on your local machine) using
firebase login
which opens a browser and you can select your account. Usefirebase logout
in case you are already logged in but to the wrong account. - In the root of your hugo site initialize the Firebase project with
firebase init
- Choose Hosting in the feature question
- Choose the project you did just setup
- Accept the default for database rules file
- Accept the default for the publish directory which is
public
- Choose No in the question if it is a single-page app
Deploy
Simply execute hugo && firebase deploy
and your site will be up in no time.
Alternatively Create a deploy.sh
file with the following content and make it executable chmod +x deploy.sh
:
#!/bin/sh
rm -rf public
hugo
firebase deploy
CI Setup
- Generate a deploy token using
firebase login:ci
- Setup your CI
- Add the token to a private variable like
$FIREBASE_DEPLOY_TOKEN
This is a private secret and it should not appear in a public repository. Make sure you understand you chosen CI and that it’s not visible to others.
- Add a step in your build to do
firebase deploy --token $FIREBASE_DEPLOY_TOKEN
Map a custom domain to a Firebase project
//TODO
Gitlab.com
Configure CI runner
- Get a deploy token for your Firebase project executing
firebase login:ci
which will bring up a browser with the authentication dialog and afterwards gives you a token to be used in CI - In your GitLab project, go to Pipelines > Environments and then add a new environment called Production
//TODO