CI/CD: Automate your Firebase deploy with Wercker

Wercker is a Docker-Native CI/CD Automation platform for Kubernetes & Microservice Deployments

De Ville Weppenaar
De Ville Weppenaar
September 19, 2016

Editor’s note: Today’s guest post is by De Ville Weppenaar, a developer at Ad Dynamo, showing how to Automate your Firebase deploy with Wercker 

Automate your Firebase deploy with Wercker

I’ve recently started using Wercker for my continuous integration and deployment needs. I also like to use Firebase for hosting of single page apps or static content. In this post I’ll cover what you’ll need to automate the deployment of your app to Firebase via Wercker.

What you’ll need

  • A project in Wercker
  • The Firebase CLI available in Wercker. You can either install it via a script step (npm i -g firebase-tools), or use a Docker image with it pre-installed. I use the devillex/docker-firebase image.
  • A name of project in Firebase to deploy to
  • A Firebase authentication token (obtained via the login:ci command of the Firebase CLI)

Setting up Wercker

For this to work, we need to create a pipeline for the deployment, set the necessary environment variables and create a workflow to deploy the code to the right environment on a successful build. Wercker manages builds and deployments via two main concepts:

  • Workflows: Defines the sequence of pipelines. Allows for branching (one pipeline completion results in the triggering of multiple pipelines), and limiting to a specific Git branch.
  • Pipelines: Series of steps defined in your wercker.yml file. Can be kicked off by a commit to a specific branch, or on successful completion of another pipeline (via chaining).

The firebase-deploy pipeline

To simplify the process I created a custom wercker step to take care of the actual deployment to Firebase: devillex/firebase-deploy@1.0.0. The step takes two parameters, namely the Firebase project name/alias and the Firebase authentication token. These values are set via environment variables in wercker. To use the firebase-deploy step, we create a pipeline in wercker for each environment we want to deploy to. In my case, this is development and staging. I call the pipelines “deploy-{environment}” (i.e. deploy-development), but use the “deploy-firebase” value for the YML pipeline name in both cases. This maps a pipeline configured in wercker to the set of steps defined in your wercker.yml file.


Setting environment variables

We need to set the Firebase project name environment variable on each of the deployment pipelines.

wercker workflows firebase

We also need to set the Firebase authentication token, but this can be set on the project (under the Environment tab) as it is used for all deployments.


Once the deployment pipelines are set up, it’s time to configure the workflow.

The workflow

In my project I have a straightforward build pipeline that triggers deployments to development and staging environments, depending on the branch that triggered the build. As seen below, I configure wercker to automatically deploy to my development environment on Firebase on commits to the development branch in Git, and I similarly deploy to the staging environment on commits to the master branch in Git.

wercker workflow


And that’s it! Any commits to either master or development will be automatically deployed to the correct Firebase project. In this post we briefly looked at how you can simplify your Firebase deployments even further by hooking them up to workflows in wercker. In the next section I provide the wercker.yml file that I am currently using for reference.

# latest node image with firebase cli
box: devillex/docker-firebase

    - npm-install
    - script:
        name: run npm build script
        code: npm run build
    - script:
        name: echo nodejs information
        code: |
          echo "node version $(node -v) running"
          echo "npm version $(npm -v) running"
    - slack-notifier:
        url: $SLACK_WEBHOOK_URL
        username: wercker

    - devillex/firebase-deploy@1.0.0:
        project: $FIREBASE_PROJECT_NAME
        token: $FIREBASE_TOKEN
    - slack-notifier:
        url: $SLACK_WEBHOOK_URL
        username: wercker

In the above code snippet the environment variables are as follows:

  • FIREBASE_PROJECT_NAME: The project name that you wish to deploy to in Firebase.
  • FIREBASE_TOKEN: The authentication token obtained from the Firebase CLI’s login:ci command.
  • SLACK_WEBHOOK_URL: Not related to the deployment to Firebase, and used for notifications to Slack.

Earn some stickers!

As usual, if you want to stay in the loop follow us on twitter @wercker or hop on ourpublic slack channel. If it’s your first time using wercker, be sure to tweet out your#greenbuilds and we’ll send you some swag!


Topics: Product, Tutorials, Integrations