Skip to content

Setup your own private docker based continuous delivery pipeline… for free!

Now Docker for Mac is production ready, developing docker based applications has never been easier. By the end of this tutorial, you’ll have a local, CI and production environment, all powered by docker, and enabled to support continuous delivery. The aim is to complete this all within 30 mins. Ready? You’ll need the following ingredients.

Ingredients

Ingredients

Docker for Mac/Windows 10 – $0
Assuming you’re working on non-linux machine, you’ll want to download a native application to virtualize the Docker Engine for your environment. Please note, this is painless.

Docker-CD-Seed – $0
A sample node.js web application that has all the necessary files and config to easily run and deploy in our shiny environment.

Github private account – $7
Whichever git repo hosting service you use, it’s essential it supports web hooks/integration into CI systems. CircleCI supports Github really well, but I know they’re offering a beta for bitbucket too. As you may know already, bitbucket is free for private projects.

CircleCI account – $0
CircleCI offers 1 container for free. This is more than enough to get started.

Google Cloud Platform account – $0
We’ll need somewhere to host our Docker images (Google Container Registry) and then somewhere to run them (Google Container Engine). All of this is available from Google Cloud Platform for free (up to 5 containers).

Total – FREE! ($7 at most)

Getting Started

Step 1 – Create project and setup cluster on Google Cloud Platform

Start a free 60 day trial. You’ll be asked for a credit card, but you won’t get charged. You’ll be prompted at the end of the trial if you want to continue (and pay where necessary).

Create a new project, give it a name, and assign the location. For this tutorial, I called mine “really-cool-project“.

Use the hamburger and navigate to “Container Engine”. It may take a couple of minutes to warm up the first time you land on the view.

Create a cluster. Set the name and zone, the other options will be ok as default.

Activate Google Cloud Shell, and run the following commands:

gcloud container clusters get-credentials really-cool-cluster
kubectl run really-cool-container --image=node:argon --port=8080
kubectl expose deployment really-cool-container --type="LoadBalancer"

Use the following command to get the cluster ip – this is what you’ll eventually want to be set as your A record:

kubectl get service really-cool-container

Step 2 – Fork Docker-CD-Seed

Fork the repo, and change all of the variables as per the values discussed above. Instructions are in the README.

Step 3 – Integrate Github with CircleCI

Add the project to CircleCI. In project settings > environment settings, add an env var for “GCLOUD_SERVICE_KEY“. The value will be the base64’d service account JSON detailed here. Follow the instructions carefully on how to create the JSON service account and how to add it to CircleCI. Authentication with the gcloud tool will be covered already by our seed circle-ci.yml.

Step 4 – Run locally and push

If this all worked, you should now be able to build and run your container locally:

docker-compose build
docker-compose up

Test it by visiting http://localhost:8080 in your browser. Commit everything and push. This will:

  1. Start a build on CircleCI
  2. Build the docker image and run the container
  3. Run the functionality tests against the container
  4. Push the docker image to Google Container Registry
  5. Tell Google Container Engine to pull the image and run it on the cluster

Fin.

Congratulations, you’ve just setup your own free private docker based continuous delivery pipeline. Now you have the basics in place, you can develop the seed to power your own custom application.

Resources

Kubernetes – Hello World Walkthrough
Quickstart for Google Container Engine
CircleCI – Continuous Integration and Delivery with Docker
CircleCI – Authentication with Google Cloud Platform
Codeship – Continuous Integration and Delivery with Docker
PHP UK Conference 2016 – Szymon Skórczyński – Docker & PHP development and deployment

Chris Bell

Chris Bell is a software engineer based in Leeds, UK. Enjoy his personal accounts and insights into the weird and wacky world of software development.

Twitter LinkedIn Google+ 

Published inSoftware qualityWeb development

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *