Deploy To An Ephemeral Environment Directly From Pull Request

Why?

While working on the complex TestRigor system our team ran into a need to validate some of our feature branches manually. And our system consists of 5 different components/services. Originally we approached the problem by building a dev environment for every person on the team and used deployments to these environments to showcase our branches. It worked for some time, but then we ran into two issues:

  • There are sometimes more than one branch per person in review
  • Setting up these dev environments appeared to be a non-trivial task because it involved some non-trivial ops and managing limited resources.

We thought, “why not use Docker Compose, which we use to test locally and simply deploy it on every branch?” And furthermore, “why do we even need to go elsewhere, when we can just do it from GitHub itself?”

And it was as simple as that – we setup a system for ourselves to deploy based on a comment from a PR.

Then we thought, “this is so cool, someone else might also want to use it!” And so we decided to set up this simple web page to see if there is any interest in this cool tool from similar teams and developers. You are welcome to sign up for early access to help indicate your interest to us. All teams that sign up during January and February 2018 will get a 4-months unlimited account (which will remain de-facto free until we implement billing).

OK. How does it work, then?

Well, unsurprisingly, we use Docker in Docker to allow anyone to easily build their compose within thier own build image.

First, you’ll need to set up our GitHub webhook, so we can respond to the comments and reply back to your PR with the URL of deployed environment.

Then there needs to be a docker image available which will be used to build your docker compose file. The docker image will have to have the latest docker compose installed, so you can actually build it in your image. You need to make sure that your docker uses /var/run/docker.sock socket so that we can expose your ports on the machine.

In your docker file we will mount /project folder with your GitHub PR code checked out and you will be able to specify your build command and setup command after we run

docker-compose -f docker-compose.yml up -d

What you get from it is:

  • Once you comment on your pull request “Deploy, please” we kickoff a new machine for your branch;
  • Then we checkout your code;
  • Then we mount it to /project in your docker image and run your build code there;
  • Then we start docker compose for you from your image;
  • Then we run your setup script (in case if you need to update your DB or something like that) again in your image;
  • Then we post the URL of your deployed running compose back on your PR.

What do you gain in return for these efforts? A new pure docker-compose based fresh environment for every feature branch at any time!

The format for the yml file which let us know what to use and how to build is like this:

---
deploy_on:
  - comment
build:
  commands:
    - "make"
  image: "testrigor/base-build:prestashop"
compose: docker-compose-ci.yml
setup:
  - "make reset"
postfix: ":8080/"

In this example, we would run

make

to build the project, we use

testrigor/base-build:prestashop

image as a build image and run

make reset

to set up the DB and settings. Then when we post the URL back to the PR we will append your postfix to http://AN_IP of the machine where it is deployed in case if you want a specific port and/or path to be part of the resulting URL.

We are excited to help you with your branch deployments!