Setting Up a Blog with Firebase Hosting

There’s No Such Thing as a Free Lunch

“Free” isn’t as it seems, but with a little technical know how… you can setup a blog with free hosting very easily.

Most software engineers use Github Pages to setup their blogs to talk about projects they’ve been working on. But, I’ve decided to use Firebase to host my blog because I have aspirations of using the Firebase Realtime Database for future projects.

Firebase

First, you need to setup a Firebase project. This isn’t too difficult to do. Follow these steps provided by Google to get started.

The biggest thing you should be aware of is Firebase Hosting. Firebase provides free hosting for custom domains based on traffic. Once that’s all setup you can move on to setting up Git and Jekyll.

Git

Second, you will need to track changes using Git. Git will allow you to follow changes you make using Jekyll. You can host this repo on Bitbucket or Github.

This will allow you to hook up continuous integration using CircleCI or the like. CirclcCI will listen to changes that are made to your hosted repo and execute the build script located in your project. I will discuss how that all works later in this post.

Jekyll

Then, you need to familiarize yourself with the Jekyll blog engine. This is a Ruby project that generates static html files based on markdown posts.

There are a bunch of different templates that you can customize. I’m currently writing this post in Markdown. Jekyll can recognize this post and generate the static html required to publish it to Firebase.

CircleCI

Finally, you can start using CircleCI or any other continuous integration services to basically build out your Jekyll static pages and push to Firebase hosting.

This is the meat and potatoes for this whole project. Below is the circle.yaml file to include in the root of your project for CircleCI to build from:

# The Firebase tools want a v6.x version of Node but Circle CI
# defaults to v4.x. Set the latest LTS version.
machine:
  node:
    version: 6.10.3

# Need to install firebase-tools so that the deploy works
dependencies:
  pre:
    - npm install -g firebase-tools

# Need to tell Circle CI how to build the site
compile:
  override:
    - bundle exec jekyll build --verbose

# Circle CI expects some kind of testing to pass in order for the
# build to be successful and deploy. Since you don't have tests
# you can fake it by just returning true. http://gph.is/1MLPDWK
test:
  override:
    - "true"

# How you tell Circle to deploy to Firebase. The important thing to
# note here is the FIREBASE_TOKEN env variable. See below.
deployment:
  production:
    branch: master
    commands:
      - firebase deploy --token=$FIREBASE_TOKEN --non-interactive

???

Profit

Well, that’s a quick look at my setup. You’ll find others have done similar setups on Stack Overflow and personal blogs. I thought this would be a great spark for others to consider for their own needs.

Google search: “firebase hosting jekyll“… enjoy!

Coffee Status

val coffee = 3
val status = when(coffee) {
	0 -> "no coffee"
	1 -> "1 coffee"
	else -> "$coffee coffees"
}
println(status) // 3 coffees