In order to do efficient, modern software development, especially for web applications, it is absolutely necessary to have a system for continuous integration (CI) and continuous delivery (CD). The idea with CI is to continuously integrate working code to the repository so that it can continuously be checked for errors. So, a prerequisite is to be using some sort of test driven development (TDD) method or at least some unit test framework; otherwise there is chance to automatically test for errors when the code is committed to the repository. The best CI systems automate everything after the commit. A developer pushes her code, then the CI systems notices the change and automatically runs the tests. When the application passes all of its test, a continuous delivery system should then automatically put the code into the QA, staging, or testing environment. There can be a lot of steps required to get a decent CI/CD system working, and it can be especially daunting when there is no dedicated DevOps team. So, I created a cheat-sheet for quickly setting up a simple Jenkins CI/CD system on an AWS EC2 instance.
Before proceeding you must have an Amazon Web Services account and be somewhat familiar with AWS.
ZONE="America/New\_York"(or whatever timezone is required)
ssh -i \ ~/.ssh/SSH\_KEY\_NAME \ ec2-user@PUBLIC\_DNS\_NAME
If you are not already logged in to the instance from changing the timezone above, then log in now (see above).
sudo yum update sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo sudo rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key sudo yum install jenkins sudo service jenkins start sudo chkconfig jenkins on
sudo yum install -y ecs-init sudo gpasswd -a jenkins docker sudo service docker start sudo chkconfig docker on
sudo yum install git
If you are using the GitHub plug-in then you should create a key to log in to GitHub
sudo su -s /bin/bash jenkins cd /var/lib/jenkins/ ssh-keygen cat .ssh/id_rsa.pub
Copy the public key, which was just concatenated onto the screen, and add it to your GitHub keys.
The ssh connection will close while the system reboots, which is fine, we are done with it for now.
After the instance reboots, type PUBLIC_DNS_NAME:8080 (use the Public DNS name from above) into a browser. The Jenkins interface should be seen.
Install plugins which are appropriate for your needs, below are the ones that I use.
Jenkins needs to restart after all of the plugins are installed. It can take a while to update some of the existing plugins, so I normally take a break at this point and finish the steps below at a later time.
If you will be getting code from GitHub, then you will need to tell Jenkins to use the proper ssh key.
With the Jenkins system set up, it is now possible to create build and test processes. The steps required varies based upon which tools are being used, and they will be covered in future posts. The last thing which you may want to do is to go to the EC2 console and save this instance as an image, so that you do not have to go through all of these steps again.