Production Meteor and Node, Using Docker, Part III
Continuous Integration for Building Containers Automatically
In the first two parts of this series, I outlined steps needed to build a Dockerfile for Meteor container and then deploy that container on Docker Cloud. I had mentioned that these tasks should be manageable for small teams, so in the spirit of simplicity, let’s take a look at automating deployments.
Note: Generally, “continuous integration” can also imply testing. Here, we focus more on building the images because often, by the time you are set to deploy your Docker image, you already know it works.
Project Ricochet is a full-service digital agency specializing in Open Source & Docker.
Is there something we can help you or your team out with?
In this exercise, we’ll examine:
- How to build Docker images when new code is pushed to GitHub or Bitbucket repositories
- How we can trigger our services to restart with the updated versions
How to Build Docker Images When New Code Is Pushed to GitHub or Bitbucket Repositories
GitHub is the most popular place to host Git repositories, and is also integrated directly with Docker Cloud. Bitbucket is integrated with Docker Hub; Docker’s own container repository. Conveniently, Docker Cloud uses the same repository. That means we can leverage Docker Hub's functionality and it will integrate with Docker Cloud!
For the GitHub-specific Setup:
- Log into Docker Cloud.
- On the landing page (or in the left-hand menu), click on Repositories.
- Click on
- If this is your first autobuild, you should see this screen:
To connect your GitHub account, click that Learn More link. Once at your account page, look for the Source Providers section:
- When your GitHub account is connected, go back to the edit screen. Now we are in business!
- Select the source repository you want. After that, more options will appear:
Leave Build Location and Autotest at their default values. Make sure you are satisfied with the Tag Mappings; these map your Docker image build tags (e.g. latest, test, production, etc.) to your GitHub branches. Ensure that Autobuild is enabled. If your Dockerfile needs any Environment Variables at build time, you can add them here. (Ours doesn’t.) Once you've set everything up, click Save.
The specified tag will now be built when you push to the associated branch:
For the Bitbucket-specific Setup:
- Log in at https://hub.docker.com/
- The Repositories tab should be open/available. Select it from the menu if not.
- Pick the Repository you want to manage from the list. Here’s an example:
- Click Build Settings.
- Connect your Bitbucket repository. Then, you should see a screen like this:
- In the Name field, enter the branch you want to use to build the Docker Tag Name (which you enter in that field). Click Save Changes.
- If you are using a private Bitbucket repo, scroll down and fill in the Deploy Key. You can set those up in your Bitbucket repo settings (full documentation).
How to Trigger Our Services to Restart with the Updated Versions
You may also want to automate the deployment of updated images once they are built. Docker Cloud makes this easy:
- Edit the service that is using the Docker image.
- In the General Settings section, ensure that Autoredeploy is enabled:
- Save changes. Redeploy if necessary, and you should be set.
Alright, that’s it for now. I hope you are enjoying this series so far. I look forward to bringing you the next couple of installments soon. I’ve created drafts for them already, so it won’t be long. In those upcoming posts, we’ll cover:
- Intelligent cross-cloud load balancing (plus Round-robin DNS tricks)
- MongoDB Replication using volumes
- Backups (not boring anymore!)
Curious about how much it might cost to get help from an agency that specializes in Docker?
We're happy to provide a free estimate!