├── Dockerfile
├── Jenkinsfile
├── README.md
├── ansible.yaml
├── deployment.yaml
├── hosts
├── pom.xml
├── src
└── main
│ └── webapp
│ ├── WEB-INF
│ └── web.xml
│ ├── css
│ └── jumbotron.css
│ └── index.jsp
└── test
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM tomcat
2 | WORKDIR webapps
3 | COPY target/WebApp.war .
4 | RUN rm -rf ROOT && mv WebApp.war ROOT.war
5 | ENTRYPOINT ["sh", "/usr/local/tomcat/bin/startup.sh"]
6 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | currentBuild.displayName = "Final_Demo # "+currentBuild.number
2 |
3 | def getDockerTag(){
4 | def tag = sh script: 'git rev-parse HEAD', returnStdout: true
5 | return tag
6 | }
7 |
8 |
9 | pipeline{
10 | agent any
11 | environment{
12 | Docker_tag = getDockerTag()
13 | }
14 |
15 | stages{
16 |
17 |
18 | stage('Quality Gate Statuc Check'){
19 |
20 | agent {
21 | docker {
22 | image 'maven'
23 | args '-v $HOME/.m2:/root/.m2'
24 | }
25 | }
26 | steps{
27 | script{
28 | withSonarQubeEnv('sonarserver') {
29 | sh "mvn sonar:sonar"
30 | }
31 | timeout(time: 1, unit: 'HOURS') {
32 | def qg = waitForQualityGate()
33 | if (qg.status != 'OK') {
34 | error "Pipeline aborted due to quality gate failure: ${qg.status}"
35 | }
36 | }
37 | sh "mvn clean install"
38 | }
39 | }
40 | }
41 |
42 |
43 |
44 | stage('build')
45 | {
46 | steps{
47 | script{
48 | sh 'cp -r ../devops-training@2/target .'
49 | sh 'docker build . -t deekshithsn/devops-training:$Docker_tag'
50 | withCredentials([string(credentialsId: 'docker_password', variable: 'docker_password')]) {
51 |
52 | sh 'docker login -u deekshithsn -p $docker_password'
53 | sh 'docker push deekshithsn/devops-training:$Docker_tag'
54 | }
55 | }
56 | }
57 | }
58 |
59 | stage('ansible playbook'){
60 | steps{
61 | script{
62 | sh '''final_tag=$(echo $Docker_tag | tr -d ' ')
63 | echo ${final_tag}test
64 | sed -i "s/docker_tag/$final_tag/g" deployment.yaml
65 | '''
66 | ansiblePlaybook become: true, installation: 'ansible', inventory: 'hosts', playbook: 'ansible.yaml'
67 | }
68 | }
69 | }
70 |
71 |
72 |
73 | }
74 |
75 |
76 |
77 |
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Build Instruction
4 |
5 |
6 | ```
7 | mvn clean package
8 | and build the instruction .
9 | ```
10 |
11 | # Deploy instruction
12 |
13 | Deploy ```target/WebApp.war``` on Tomcat properly for better experience.
14 |
15 |
--------------------------------------------------------------------------------
/ansible.yaml:
--------------------------------------------------------------------------------
1 | - hosts: test
2 | tasks:
3 | - name: copy deployment file to kubernetes master
4 | copy:
5 | src: deployment.yaml
6 | dest: /root/
7 | - name: delete the previous of kubernetes objects
8 | command: kubectl delete -f /root/deployment.yaml
9 | - name: Create a Deployment by reading the definition from a local file
10 | command: kubectl apply -f /root/deployment.yaml
11 |
12 |
--------------------------------------------------------------------------------
/deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: devops-training
5 | spec:
6 | selector:
7 | matchLabels:
8 | app: devops-training
9 | template:
10 | metadata:
11 | labels:
12 | app: devops-training
13 | spec:
14 | containers:
15 | - name: devops-training
16 | image: deekshithsn/devops-training:docker_tag
17 | command: ["/bin/sh"]
18 | args: ["-c","sh /usr/local/tomcat/bin/startup.sh;while true; do echo hello; sleep 10;done"]
19 | ports:
20 | - name: http
21 | containerPort: 8080
22 | replicas: 2
23 | ---
24 | apiVersion: v1
25 | kind: Service
26 | metadata:
27 | name: devops-training-app-service
28 | labels:
29 | app: devops-training
30 | spec:
31 | type: NodePort
32 | ports:
33 | - port: 8080
34 | nodePort: 31884
35 | protocol: TCP
36 | name: http
37 | selector:
38 | app: devops-training
39 |
--------------------------------------------------------------------------------
/hosts:
--------------------------------------------------------------------------------
1 | [test]
2 | Host_ip
3 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
DevOps is the combination of cultural philosophies, practices, and tools that increases an organization's ability to deliver applications and services at high velocity: evolving and improving products at a faster pace than organizations using traditional software development and infrastructure management processes.
65 | 66 |Jenkins is a free and open source automation server. Jenkins helps to automate the non-human part of the software development process, with continuous integration and facilitating technical aspects of continuous delivery
72 | 73 |Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages.
77 | 78 |