Skip to content

Commit d8b2acc

Browse files
authored
Add files via upload
1 parent 51c184a commit d8b2acc

5 files changed

Lines changed: 130 additions & 0 deletions

File tree

CICD pipeline/AnsibleHosts.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[ansible-server]
3+
localhost
4+
5+
[kube]
6+
172.31.39.56

CICD pipeline/dockerfile.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
From tomcat
2+
Maintainer Sonal
3+
ADD addressbook.war /usr/local/tomcat/webapps
4+
CMD ["catalina.sh", "run"]
5+
EXPOSE 8080

CICD pipeline/dockerplaybook.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
- hosts: localhost
3+
become: true
4+
become_user: root
5+
6+
tasks:
7+
- name: Start docker
8+
service: name=docker state=started
9+
10+
- name: create docker image using war file
11+
command: docker build -t myproject:CICD .
12+
args:
13+
chdir: /opt/myproject
14+
15+
- name: create tag to image
16+
command: docker tag myproject:CICD edu123/myproject:CICD
17+
18+
- name: loginto docker
19+
command: docker login --username edu123 --password Edureka@123
20+
21+
- name: push image on to dockerhub
22+
command: docker push edu123/myproject:CICD
23+
24+
- name: remove docker images form ansible server
25+
command: docker rmi myproject:CICD edu123/myproject:CICD
26+
ignore_errors: yes

CICD pipeline/kubeplaybook.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: Create pods using deployment
3+
hosts: kube
4+
become: true
5+
user: root
6+
7+
tasks:
8+
- name: create a deployment
9+
command: kubectl apply -f deployment.yml
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
Step 1:
3+
4+
go to jenkins and download the plugin publish over ssh
5+
6+
go to manage jenkins--> go to configure system --> publist over ssh --> click on add server
7+
8+
take the private ip of CI/CD ACM provate ip
9+
10+
username: ec2-user
11+
passowrd : as created on ansible server for ec2-user
12+
13+
click on Test configuration
14+
15+
Jnekisn server connected to Ansible now.
16+
17+
**********************
18+
19+
Step 2:
20+
21+
Create CI job
22+
23+
create template maven
24+
25+
git repo :
26+
https://github.com/Sonal0409/DevOpsClassCodes.git
27+
28+
build section give : clean install package
29+
30+
31+
Now copy the addressbook.war file to ansible server
32+
33+
post build steps: select send files or execute commands over ssh
34+
35+
ssh server:
36+
Name: ansibleserver
37+
38+
Click on advance and select verbose
39+
40+
Transfers:
41+
42+
source files: target/*.war
43+
44+
remove prefix : target
45+
46+
Remote directory: //opt//myapp
47+
48+
exec command: ansible-playbook -i /opt/myapp/hosts /opt/myapp/dockerplaybook.yml
49+
50+
51+
Go to Ansible server : CI/CDACM
52+
53+
Create a directory under opt
54+
55+
cd /opt
56+
57+
sudo mkdir myapp
58+
59+
sudo chmod 777 myapp
60+
61+
Add dockerfile, dockerplaybook, kubeplaybook, host file
62+
63+
RUN the JOb in jenkins
64+
65+
adressbook.war will be there
66+
docker images will be pushed to docker hub
67+
68+
*****************************
69+
70+
Step 3:
71+
72+
Create a new job CD
73+
74+
select template default template
75+
76+
post build steps
77+
78+
send build over ssh
79+
80+
advanced--select verbose
81+
82+
ansible-playbook -i /opt/myapp/hosts /opt/myapp/kubeplaybook.yml
83+
84+

0 commit comments

Comments
 (0)