Setting up Cachet on Google Cloud

Note: This article assumes you have some knowledge about Docker, Google Cloud Platform and Kubernetes.

Cachet (https://cachethq.io) is an open source status page package written on top of the Laravel framework. At Printr, we don’t run any other PHP service, so configuring a seperate server to run Cachet on would take a lot of time, resources and maintanance. Luckily, Cachet’s community has created a Docker implementation of Cachet, which is hosted on Docker Hub. There’s a few quirks however that make it more difficult to deploy on hosted container platforms like Google Cloud’s container engine. After taking a few hours to figure it out, I thought it would be nice to share my setup with you, so you can do the same thing in just a few minutes!

Cachet has set up GitHub repository with a Dockerfile, Docker Compose configuration to run it locally and some handy helper scripts. In their own Docker setup guide, they advise you to use one of the tagged Docker images hosted on Docker Hub. This caused a few issues for me. Their latest stable tag dates from 4 months back (at the time of writing this) and uses a 3 container setup: an app (Cachet) container, a Postgres container and an nginx container. The last one is great if you wanna run it locally using Docker Compose, but when deploying to for example Google Cloud it’s a burden. Their current master branch however has a setup with 2 containers: an app + nginx container and the Postgres container. This setup is much easier to work with when deploying to production. To get to the same setup as I did, just follow these steps.

Step 1: Checkout the master branch of the repository

Just checkout the repo and switch to the master branch:

git clone https://github.com/cachethq/Docker.git cachet-docker
cd cachet-docker
git checkout master

Step 2: Build the container locally and upload it

Before we can deploy the container in Google Cloud we have to build it locally and then upload it to their container registry. Google likes tagged containers with a {REPO_NAME}/{GCP_PROJECT_NAME}/{APP_NAME}:{VERSION} structure. In my case I’m using eu.gcr.io, which is Google European container registry domain. The project name is your Google Cloud project name, and the app name is cachet (but can be anything you want).

docker build -t eu.gcr.io/{GCP_PROJECT_NAME}/cachet:master .

After building the container locally, confirm it exists with the correct tag by running docker images.

If everything checks out, we can upload the container. This assumes you’ve installed the gcloud SDK.

gcloud docker -- push eu.gcr.io/{GCP_PROJECT_NAME}/cachet:master

Step 3: Create your deployment config and environment variables

After pushing the container, we can start using it in a deployment. Our deployment will consist of 2 containers, and we’ll add a service as well to expose the Cachet container to the world. If this is the first time you’re using Google container engine, please take a look at the reference of their underlying engine Kubernetes.

Check out this Gist for the deployment configuration. As you can see, it contains the deployment itself (specifying both containers), which ports to open and the environment variables to connect Cachet to the database. There is also a service that connects Cachet to a LoadBalancer, which will make Google Cloud automatically spawn an external IP address.

To apply the deployment, run the following command. This assumes that you’ve installed the kubectl command line tool which comes with the gcloud SDK.

kubectl create -f deployment.yml

After a few seconds, you should see the containers and services being created when running kubectl get deployments or kubectl get svc.

If you want to check which IP address your Cachet setup got appointed, run kubectl get svc and check for the external IP address in the resulting list.

And that’s it! You’ve now deployed Cachet on Google Cloud platform using a custom Docker container setup and Kubernetes. You can check out our own deployment at status.formide.com.

Questions? Shoot them down below!