The purpose of this guide, is to show you just a way to construct a continuos integration strategy trough Docker-Jenkins related technologies. In this repository you'll be able to find source code, that you will need, this is just such like a template so feel free to use this one is what you're just looking for a fast solution to test, some kind of prototype or proof of concept. This guide is based on several sources of information, you'll find the links at the end of the article.
- GitHub/BitBucket account or any other related provider.
- Source code to deploy.
- Docker registry account or any other related provider(public/private).
- AWS EC2 (Or any other platfform that supports cloud computing).
- PuTTy sw installed on your local computer.Get it here
There are three basic things that you need to know about a integration process between Jenkins and Docker, first of all i'm going to suposse that you know what's Docker and how does it works but if you don't just dont worry and go to the Docker Site and take yourself into a journey of UNIX and containers. But let's go to the point you need to consider the Dockerfile as like a recipe for the container construction.
The Dockerfile is intended to be used when you're building a docker image, and you'll need a Jenkinsfile to construct a pipeline. A pipeline is a programatic way of defining a set of tasks that are going to be executed by the Jenkins plattform when it's performed a build task.
- First of all you have two choices, clone this repository with the source code and avoid writting your own Dockerfile,Jenkinsfile and SourceCode by having this approach you'll be focusing only on the related infrastructure setup involving Jenkins-Docker-AWS or just start from the begining creating your own repo and of course adding your desired source code, Dockerfile and Jenkinsfile that's your choice.
- Create an account here in the Docker registry and take note about the credentials, we'll need'em in foreward steps.
- Create a free account on AWS just register yourself here.
- Sign in AWS and go to: Console => Build a solution and look for the option Launch a virtual machine with EC2.AWS EC2 Overview
- In this step you're going to select your prefered SO for your own VM, i'd recommed to choose a simple and lightweigth one and take advice of the free tier selection, this are not going to charge you for the service despite another heavier machines that are going to lead AWS charging for the services.
- Select free tier checkbox:
- Select Ubuntu Server 16.04 LTS
- Select free tier option to avoid any charge for the next 12 months => Review and Launch
- You must create a new key pair, so you have to select the option create a new key pair and of course give a name for the file that you're going to create and download. NOTE It's very important for you to save this file in a safety place, because it's impossible to get it again and if lose the file you'll be unable to connect to the VM and won't be avoidable your VM will be doomed and unable to access by yourself at anyway. Just push download save the file and after that push launch instances.
- Save your key on your local directory.
- Push launch instances and you're going to be redirected to the next page, this is gonna put you on advise about your new VM, and how to connect to you VM avoid this we're going to see this in foreward steps.
- Let's transform your aws.pem into a aws.ppk
- Open PuTTYgen app.
- Double check that you have selected RSA in parameters section, and press load a windows will pop up, go to the directory where your pem file is located, select this and push open.
- Accept the confirmation pop up.
- Save the private key file on you local directory and give a meaningful name to the file.
- Leave empty the passphrase box, and confirm that is your desire to leave it empty when prompted.
- We are going to configure a software that allow us to connect via SSH to our AWS Instance, in my case and due to the lack of a Windows computer rigth now, i'm going to configure a Termius session on a Mac.
- Open up Termius sofware and configure your SSH session.
- Click on the down arrow and select option => Keychain.
- Select addkey option.
- Add a label, and open up your ppk file with a text editor and copy the entire content into the PrivateKey textbox, press save button.
- After adding your key we're going to add our host configuration. Go to Hosts and select New Host
- Go to your AWS console and get the public ip of your AWS Instance.
- Fill out the new host data required.
- In the key section click on the arrow and select the recent created key configuration AWSEC2
- Click connect and we're up and running on your AWSEC2 instance.
- Login into the instance that you've recently created.
- Make sure to verify which version of Java is on your SO, make sure to install the Oracle's Java version.
- Once in the console, let's have some fun and update the apt-get
ubuntu@ip-172-31-35-221:~$ sudo apt-get update
- Let's add to our repositories list the Oracle's PPA.
sudo add-apt-repository ppa:webupd8team/java
- Once in the console, let's have some fun and update the apt-get
ubuntu@ip-172-31-35-221:~$ sudo apt-get update
- Let's install the latest version of Oracle's Java. Note: It's recomendable to install the JDK to avoid any issues about possible configurations in the Jenkins server.
ubuntu@ip-172-31-35-221:~$ sudo apt-get install oracle-java8-installer
- Let's verify that you're running by default with the Oracle's version of Java.
ubuntu@ip-172-31-35-221:~$ sudo update-alternatives --config java
-
Let's start installing our Jenkins server inside our Ubuntu's SO.
-
We're going to add the repository key to our system.
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
- Modify our source.list, append the next URL.
echo deb https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
- Perform an update on our apt-get, please:
sudo apt-get update
- Let's install our Jenkins:
sudo apt-get install jenkins
- Let's start our Jenkins instance.
sudo systemctl start jenkins
- Verify that Jenkins started correctly:
sudo systemctl status jenkins