Automate Docker Deployment with Docker Infrastructure

Hi

In a series of blog posts I want to take you through the experience I had recently with building docker images in an automatic procedure

What will we cover?

  • Deploy the underlying infrastructure into AWS using CloudFormation
  • Deploy Jenkins & Artifactory using docker-compose
  • Configure Jenkins pipeline to build docker images using Jenkinsfile (a.k.a “Infrastructure-as-code”)
  • Configure Artifactory as a repository for npm packages, rpm packages & docker images

AWS Deployment

The first step is to deploy the linux machiens that will run our containers. I chose to do it on Amazon Web Services (AWS), and the native way to deploy a set of resources in AWS is using CloudFormation.

CloudFormation?

You can read everything about CloudFormation here. To make a long story short, CloudFormation let’s you document your infrastructure into a text file that AWS “understands” and based on the configuration, CloudFormation will deploy your defined set of resource. This set of deployed resources is then called a Stack.

CloudFormation is AWS take on Infrastructure-as-code. As such, you can deploy, upgrade and delete your set of infrastructure components as an heterogenous unit, and basically approach it like a piece of code with version, rollback and a lot of methodology that you usually find in computer programming.

A common code of infrastructure will look like this (basically, a .json or .yaml formatted file):

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Build Pipeline Infrastructure Template",
"Mappings": {
"Networking": {
"VPC": {
"CIDR": "10.0.0.0/16"
},
"PublicSubnetOne": {
"CIDR": "10.0.1.0/24"
},
"PrivateSubnetOne": {
"CIDR": "10.0.2.0/24"
}
# code incomplete. this is only an example

What will we deploy?

Diagram
AWS Basic Infrastructure Deploymebnt
  • Virtual Private Cloud (VPC) that is basically our private network in the AWS landscape. It will include:
    • 2 subnets – public and private, with full routing and access between them
    • Internet Gateway – to allow access from the internet to one of our instances
    • NAT Gateway – to allow access from our private instances to the internet
  • 1 linux server with publicly-accessible static IP (called Elastic IP in AWS) that we will use as our gateway to our environment. This is called a Bastion Host
  • 2 Servers who are in a private subnet and are only accessible from the Bastion host created earlier, called Master and Slave (I will explain more about them in a later phase)

ok, How do I do it?

Before you go and deploy it, please note that this comes with cost. You must have a valid AWS account and you must know your AWS basics. Just to give you an idea, deploying the suggested stack with 1 t2.medium instance and 2 t2.large instances will set you back about ~ 200$ a month.

Prerequisite

Before you deploy the stack, go ahead and create a Key Pair in AWS EC2 service in the same region you will deploy the stack of resource. You will need to choose this Key Pair in the next phase. Make sure to keep the file safe, you will need it to log in to your instances

Deploy

Once you’re ready, go ahead and fire up CloudFormation in your AWS account. Click on Create Stack ⇒ Design template.

Click on the template tab in the lower-right corner and paste the text from my sample stack. Click on the create stack icon at the top-left (cloud with up arrow icon), fill in required details (instance size, Key Pair, etc.) and finalize the wizard to launch your stack

Warming up…

CreationInProgress.jpg

And finally, ready to rock!

CreationCompleted.jpg

Head over to the output tab and note down the IP of your bastion host. You can then SSH into it using the key pair you created earlier

BastionIPOutput.jpg

Conclusion

So there you have it, a simple stack of 3 EC2 Instances with full routing and internet access deployed in AWS. Remember, this is just our first step

In the next posts, we will continue to further develop our stack and deploy docker on top of it, run applications inside containers and, with a bit of luck, even deploy a containerized application into a fully fledged, orchestrated container-based environment

Stay tuned!

 

Advertisements

One thought on “Automate Docker Deployment with Docker Infrastructure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s