Devops Project Solution PDF
Devops Project Solution PDF
co/devops
Certification Project
Solution
Problem Statement
AppleBite Co. is using Cloud for one of their products. The project uses modular components,
multiple frameworks and want the components to be developed by different teams or by 3rd-party
vendors.
The company’s goal is to deliver the product updates frequently to production with High quality &
Reliability. They also want to accelerate software delivery speed, quality and reduce feedback time
between developers and testers.
As development progressed, they are facing multiple problems, because of various technologies
involved in the project. Following are the problems:
To solve these problems, they need to implement Continuous Integration & Continuous Deployment
with DevOps using following tools:
Git – For version control for tracking changes in the code files
Jenkins – For continuous integration and continuous deployment
Docker – For deploying containerized applications
Puppet/Ansible - Configuration management tools
Selenium - For automating tests on the deployed web application
This project will be about how to do deploy code to dev/stage/prod etc, just on a click of button.
Business challenge/requirement
As soon as the developer pushes the updated code on the GIT master branch, a new test server
should be provisioned with all the required software. Post this, the code should be containerized and
deployed on the test server.
The deployment should then be tested using a test automation tool, and if the build is successful, it
should be pushed to the prod server.
All this should happen automatically and should be triggered from a push to the GitHub master
branch.
Solution
1. Go to Manage Jenkins-> Configure Global Security and under Agents set the TCP port for JNLP
agents to Random
3. Now, set the “name”, “Remote root directory” and choose Launch agent via Java Web Start in
Launch Method
And under Node Properties check Tool Locations and give path to git directory and click on
save
4. Now Select the newly created node and download the agent.jar file in your master node
5. Copy the above highlighted code in your agent node’s terminal and replace the localhost with
Master’s IP address
---
- hosts: agent
become: true
vars:
ansible_become_pass: edureka
tasks:
- name: Install Git
package:
name: git
state: present
class docker::install {
package {'curl':
ensure => present,
}
exec {'apt-update':
command => '/usr/bin/apt-get update'
}
exec {'download_docker_key':
command => '/usr/bin/curl -fsSL
https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -'
}
exec {'add_docker_repo':
command => '/usr/bin/add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"',
require => Exec['apt-update']
}
exec {'docker_cache':
command => '/usr/bin/apt-cache policy docker-ce'
}
exec {'install_docker':
command => '/usr/bin/apt-get install -y docker-ce'
}
class docker {
class {'docker::install':}
}
11. Call this Module inside the main Puppet manifest(i.e. site.pp)
class {'docker':}
-FROM devopsedu/webapp
-
-ADD proj /var/www/html
-
-RUN rm /var/www/html/index.html
-
-CMD apachectl -D FOREGROUND
13. Write the following Selenium code and create a .jar file after compiling the code in eclipse(or
any other java IDE
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.openqa.selenium.chrome.ChromeOptions;
System.setProperty("webdriver.chrome.driver","/home/edureka/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--no-sandbox");
WebDriver driver = new ChromeDriver(chromeOptions);
chromeOptions.addArguments("--headless");
driver.get("http://localhost:8081");
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.findElement(By.id("About Us")).click();
}
}
15. Now, In the build phase add a build step to execute shell commands and save the Job
wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
sudo dpkg -i puppetlabs-release-pc1-xenial.deb
sudo apt-get update
sudo apt-get install -y puppet-agent
sudo systemctl start puppet
sudo systemctl start puppet
Job to trigger puppet agent to pull and apply the catalog from master
17. Create a new job and restrict it to execute only on the remote machine
18. Add a build step to execute a shell command to trigger Puppet agent
Job to create a docker container, run the container and execute Selenium test case on it
19. Create a new job and restrict it to execute only on the remote machine
20. Add Your GitHub link in the GitHub Project and also make this job restricted to remote
machine only
21. Under Source Code Management in the git section again add your GitHub url
22. Under Build Triggers check poll SCM and give it appropriate time interval to poll GiHiub for
changes
23. Now, add a build step to execute the following shell commands on the remote machine
24. Add a Post-build Actions -> Post build task to ensure that if the Selenium test fails, the docker
containers are deleted. Here keep the Log text as failure and add the docker container
removing commands in the script section
Note: While creating the Puppetagent trigger job Set the Post Build Action to Trigger even if the
build fails. This is because for some reason Jenkins is considering Puppet agent Successful build to be
a failure.
Execution
1. Execute the Ansible Playbook for initial setup of the agent node