GitHub issues GitHub forks GitHub stars GitHub license

DevOps for Web Development

This is the code repository for DevOps for Web Development, published by Packt. It contains all the supporting project files necessary to work through the book from start to finish.

Instructions and Navigation

All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter02.

Code Snippet:


Chapter 1:

You can find all the necessary code here for the chapter 1.

Chapter 2:

java -jar jenkins.war --httpPort=9999
java -jar jenkins.war --httpsPort=8888
java -jar slave.jar -jnlpUrl -secret 65464e02c58c85b192883f7848ad2758408220bed2f3af715c01c9b01cb72f9b Required metadata

sonar.projectName=Simple Java project analyzed with the SonarQube Runner 

Comma-separated paths to directories with sources (required) onar.sources=src

Language sonar.language=java Encoding of the source files sonar.sourceEncoding=UTF-8

Chapter 3:

echo 'Hello from Pipeline Demo'
stage 'Compile'
build 'PetClinic-Compile'
stage 'Test'
build 'PetClinic-Test'

echo 'Hello from Pipeline Demo'
stage 'Compile'
node {
  git url: ''
  def mvnHome = tool 'Maven3.3.1'
  sh "${mvnHome}/bin/mvn -B compile"
stage 'Test'
node('WindowsNode') {
  git url: ''
  def mvnHome = tool 'WindowsMaven'
  bat "${mvnHome}\\bin\\mvn -B verify"
  step([$class: 'ArtifactArchiver', artifacts: '**/target/*.war', fingerprint: true])  
  step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])

Create a user with name admin and assign password and roles as below. 
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="[email protected]" roles="manager-script" />
Now, we need to add Tomcat's admin user that we created in the Maven setting file.

Find Tomcat Plugin block in Pom.xml and add following details. Make sure that Server Name is same that we provided in settings.xml of Maven as Id:


Chapter 4:

rpm -ivh chef-12.9.41-1.el6.x86_64.rpm 
knife bootstrap -x root -P [email protected] -N tomcatserver
knife node run_list add tomcatserver"role[vtomcat]"

Chapter 5:

docker run -p 8180:8080 -d --name devopstomcat1devopstomcatnew

Chapter 6:

knife ec2 server create -I ami-1ecae776 -f t2.micro -N DevOpsVMonAWS --aws-access-key-id '< Your Access Key ID >' --aws-secret-access-key '< Your Secret Access Key >' -S book --identity-file book.pem --ssh-user ec2-user -r role[v-tomcat]

knife azure server create --azure-dns-name 'distechnodemo' --azure-vm-name 'dtserver02' --azure-vm-size 'Small' -N DevOpsVMonAzure2 --azure-storage-account 'classicstorage9883' --bootstrap-protocol 'cloud-api' --azure-source-image '5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-67-20160310' --azure-service-location 'Central US' --ssh-user 'dtechno' --ssh-password '[email protected]' -r role[v-tomcat] --ssh-port 22

Chapter 7:

FROM tomcat:8.0

MAINTAINER Mitesh<[email protected]>

COPY tomcat-users.xml /usr/local/tomcat/conf/tomcat-users.xml

Chapter 8:

java -jar newrelic.jar install

Chapter 9:

ssh -t -t [email protected] "ifconfig; rvm use 2.1.0; knife ec2 server create -I ami-1ecae776 -f t2.micro -N DevOpsVMonAWS1 --aws-access-key-id '<YOUR ACCESS KEY ID>' --aws-secret-access-key '<YOUR SECRET ACCESS KEY>' -S book --identity-file book.pem --ssh-user ec2-user -r role[v-tomcat]"

ssh -t -t [email protected] "ifconfig; rvm use 2.1.0; knife ec2 server create -I ami-1ecae776 -f t2.micro -N DevOpsVMonAWS1 --aws-access-key-id '<YOUR ACCESS KEY ID>' --aws-secret-access-key '<YOUR SECRET ACCESS KEY>' -S book --identity-file book.pem --ssh-user ec2-user -r role[v-tomcat]"

java -jar slave.jar -jnlpUrl -secret 65464e02c58c85b192883f7848ad2758408220bed2f3af715c01c9b01cb72f9b

ssh  -i /home/mitesh/book.pem -o StrictHostKeyChecking=no -t -t [email protected] "sudo usermod -a -G tomcat ec2-user; sudo chmod -R g+w /var/lib/tomcat6/webapps; sudo service tomcat6 stop;" 
scp  -i /home/mitesh/book.pem /home/mitesh/target/*.war [email protected]:/var/lib/tomcat6/webapps
ssh  -i /home/mitesh/book.pem -o StrictHostKeyChecking=no -t -t [email protected] "sudo service tomcat6 start"

node('Master') {
   // Mark the code checkout 'stage'
   stage 'Checkout'

   // Get code for PetClinic Application from a GitHub repository
   git url: ''

   // Get the maven tool.
   // This ' Maven3.3.1' maven tool must be configured in the global  configuration.           
   def mvnHome = tool 'Maven3.3.1'

   // Mark the code Compile 'stage'....
   stage 'Compile'
   // Run the maven build
   sh "${mvnHome}/bin/mvn clean compile"

   // Mark the code for Unit test execution and package 'stage'....
   stage 'Test&Package'
   sh "${mvnHome}/bin/mvn clean package"

   // Mark the code Cloud provisioning 'stage' where instance is allocated in Amazon EC2
// Once Instance is available, Chef will be used for Configuration Management
// knife ec2 plugin will be used for instance provisioning in the AWS cloud
   stage 'Cloud Provisioning'
   sh "ssh -t -t [email protected] 'ifconfig; rvm use 2.1.0; knife ec2 server create -I ami-1ecae776 -f t2.micro -N DevOpsVMonAWS9 --aws-access-key-id xxxxxxxxxxxxxxxxxxxx --aws-secret-access-key xxxxxxxxxxxxxxxxxxxxxxxxxxxxx -S book --identity-file book.pem --ssh-user ec2-user -r role[v-tomcat]'"

Related DevOps Products:

Suggestions and Feedback

Click here if you have any feedback or suggestions.