All Case Studies Design Development Interviews Our Way Project Management

How To Set Up An Automatic Docker Staging - Mini Guide

Dynamic staging, or integration, uses the combined power of Docker and Docker Compose, which is a tool that lets you easily configure and link containers with a single YAML file and to build containers with linked services, such as databases, redis, etc. Take a look at how to set up an automatic Docker staging and how we do it at Netguru.

How does it work in Netguru?

Each time a pull request is created, GitHub sends a webhook to our specially created app - Heaven - which takes the latest Git revision of that specific branch along with the pull request number and “builds” the app using said Docker Compose configuration, which is later accessible by the host specified in docker-compose.yml.

A sample Docker Compose configuration might look like this:

[code]

We define what should be built in line 2 and provide the Dockerfile on line 3.

We have the section links which does what it says - it links the containers from lines 12 and 14, which are built on given images and which are later accessible from within our “main” application container. We can easily set up the environment variables for our container and other options such as cpu_quota or hostname.

As long as our pull request is opened, every new commit to that PR rebuilds the container with the new code, so when we access the host we provided on line 8 of the configuration file, we should see our “dynamically” setup application.

When developing an application using pull requests, every ticket has its own branch which means that every ticket has own pull request. This gives us the ability to test changes that are only within the scope of our ticket and we don’t have to worry about changes from other people which might break the application. It also has a downside, because on one hand every dynamic staging has its own database container that we can break, but on the other hand data between the normal staging and the dynamic one isn’t linked, which means we have to specify the seeds for the initial database state that we need.

What do you think about this solution? Let me know in the comments below!

New Call-to-action
Follow Netguru
Join our Newsletter

Scaling SaaS
READ ALSO FROM Dev
Read also
Need a successful project?
Estimate project or contact us