Docker Cloud: The future of cloud deployments
This is a repost of: https://blog.geografia.com.au/how-we-are-using-docker-cloud-for-automated-testing-and-deployments-of-applications-bb87ec3173e7
How we are using Docker Cloud for automated testing and deployments of applications.
In this post I will share with you how we deploy application to the cloud at Geografia using Docker Cloud, Amazon AWS or Digital Ocean.
At Geografia we aim to build applications in a sustainable, cost-effective and repeatable way. For this we have embraced Docker and settled on a deployment workflow for our Rails Projects.
At a high level it consists of
- Github triggered Docker image builds & tests
- Docker Cloud (Microservices) stack definition
- Linking the cloud provider and Docker Cloud
- Docker Cloud CLI for running & managing the microservices
Git based automated image build
After we have our development and production application dockerized and a docker-compose setup (see my posts on that here, here & here) we go for configuring automated Docker builds, triggered by Github pull requests on docker cloud. It’s fairly easy and the documentation is pretty straight forwards. Here we can also create automated test configuration. New images are only pushed to the registry if the tests pass.
Docker cloud stack
Once this is working nicely it’s time to set up our docker-cloud services stack. docker-cloud stacks configuration is pretty much the same as docker-compose configuration, with a couple of caveats. A small set of docker-compose keys are unsupported in docker-cloud. Again the docs are great!
Adding deployment nodes
Once the stack file is defined it’s time to run a stack in the cloud! So we need to connect docker cloud to our cloud provider. This is easy for AWS you create a role and a policy. See this walk through. For DigitalOcean it’s even easier: OAuth based authorization, heck yeah! With this done we can create nodes on our cloud platform of choice.
docker-cloud CLI
We are now ready to deploy our stack to a node-cluster. We can do this via docker-cloud cli. To make sure the cli works see this document. You will need to set the following environment variables.
export DOCKERCLOUD_PASS=xxxxxxx
export DOCKERCLOUD_APIKEY=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export DOCKERCLOUD_USER=sabman
export DOCKERCLOUD_NAMESPACE=geografia
We can now deploy a stack, monitor it and scale it. Below you can see our stack for the City of Melbourne’s Population website, which provides forecasts of the City of Melbourne’s residential population and dwellings to 2036.
$ docker-cloud stack ls
NAME UUID STATUS DEPLOYED
melbourne-population-production 3a579397 ▶ Running 55 days ago
We can inspect this stack
$ docker-cloud stack inspect melbourne-population-production
{
"current_num_containers": 3,
"name": "melbourne-population-production",
"synchronized": true,
"destroyed_datetime": null,
"uuid": "xxxxxx-xxxx-xxxx-a9d9-7613b69c66a9",
"state": "Running",
"services": [
"/api/app/v1/geografia/service/xxxx-xxxx-d14398d00e81/",
"/api/app/v1/geografia/service/xxxx-xxxx-8899c4622914/",
"/api/app/v1/geografia/service/xxxx-xxxx-468387e5dac7/"
],
"deployed_datetime": "Wed, 8 Feb 2017 09:32:12 +0000",
"nickname": "melbourne-population-production",
"dockercloud_action_uri": "",
"resource_uri": "/api/app/v1/geografia/stack/xxxx/"
}
Related to this, Docker just released docker swarm (which is in beta). We’ll be giving this a spin for running our data analytics tasks. I’ll write more about that in a future post.
If you have questions feel free to get in touch with me at shoaib@geografia.com.au.