forked from RAHAMSHAIK007/terrarepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojdev.txt
237 lines (170 loc) · 7.62 KB
/
projdev.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
create 3 instances
jenkins
ansible
webapp
connection : jenkins -- > ansible & webapp
ansible -- > webapp
setup jenkins
free stype and repo give proj: one
manage jenkins -- > plugins -- > public overssh
manage jenkins -- > configuratiuon settings -- >
SSH SERVERS -- > Add -- >
name & hostname & user & remote dir -- > advance -- > password -- > test config
now you will get sucess
do it for all the nodes ansible & webapp
check by doing firts build
Jnekins server and check on var lib jenkins workpace
build step -- > Send files or execute commands over SSH
SSH Server -- > Name: Jenkins -- > exec command: rsync -avh /var/lib/jenkins/workspace/one/* [email protected]:/opt
save and apply
do build 2 and it will success
goto ansible server and check opt
go for job oen and config and ssh server on build steo and exec command
cd /opt
docker image build -t $JOB_NAME:v1.$BUILD_ID .
docker image tag $JOB_NAME:v1.$BUILD_ID rahamshaik007/$JOB_NAME:v1.$BUILD_ID
docker image tag $JOB_NAME:v1.$BUILD_ID rahamshaik007/$JOB_NAME:latest
docker image push $JOB_NAME:v1.$BUILD_ID rahamshaik007/$JOB_NAME:v1.$BUILD_ID
docker image push rahamshaik007/$JOB_NAME:latest
docker image rmi $JOB_NAME:v1.$BUILD_ID rahamshaik007/$JOB_NAME:v1.$BUILD_ID rahamshaik007/$JOB_NAME:latest
advanvce on top and click Verbose output in console
docker file:
FROM amazonlinux:latest
MAINTAINER [email protected]
RUN yum install httpd unzip -y
ADD https://www.free-css.com/assets/files/free-css-templates/download/page254/photogenic.zip /var/www/html/
WORKDIR /var/www/html/
RUN unzip photogenic.zip
RUN cp -rvf photogenic/* .
RUN rm -rf photogenic photogenic.zip
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
EXPOSE 80
ANSIBLE SERVER
sudo amazon-linux-extras install ansible2 -y
vim /etc/ansible/hosts
vim /etc/ansible/ansible.cfg
cd /opt/
vim ansible.yml
- hosts: webapp
tasks:
- name: create new container
shell: docker container run -itd --name mydockercontainer -p 9000:80 rahamshaik007/img1
jenkins job -- > build step -- > Send files or execute commands over SSH
Ansible -- > exec command: ansible-playbook /opt/ansible.yml -- > save
if u build it will fail because the conatiner name is varied
go to playbook and change container and give another name
- hosts: webapp
tasks:
- name: stop container
shell: docker stop mydockercontainer
- name: removig container
shell: docker rm mydockercontainer
shell: docker stop mydockercontainer
- name: removing image
shell: docker rm -f rahamshaik007/img1
- name: create new container
shell: docker container run -itd --name mydockercontainer -p 9000:80 rahamshaik007/img1
use webhook for this
============================================================================================================================================================================================
SAME PROJECT FOR WEBAPPLICATION:
CREATE 3 INSTANCES (JENKINS, ANSIBLE, DOCKER)
CHANGE ALL HOSTNAMES
INSTALL JAVA ON ALL OF THEM
sudo amazon-linux-extras install java-openjdk11 -y
vim /etc/ssh/sshd_config
systemctl restart sshd
systemctl status sshd
GO TO JENKINS SERVER
INSTALL JENKINS
cd /opt
wget https://dlcdn.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
tar -zxvf apache-maven-3.6.3-bin.tar.gz
mv apache-maven-3.6.3 maven
vim ~/.bash_profile
#PATH=$PATH:$HOME/bin
M2_HOME=/opt/maven
M2=$M2_HOME/bin
PATH=$PATH:$JAVA_HOME:$M2_HOME:$M2:$HOME/bin
export PATH
sudo su -
echo $PATH
echo $M2
visudo
DASHBOARD -- > MANAGE PLUGINS -- > MAVEN INTEGRATION & MAVEN INVOKER & PUBLISH OVER SSH -- > INSTALL
MANAGE JENKINS -- > LOBAL CONFIGURATIN TOOL -- > MAVEN -- > ADD MAVEN -- > NAME: maven & MAVEN_HOME: /opt/maven
GO TO ANSIBLE SERVER
yum install python -y
yum install python-pip -y
pip install ansible
ansible --version
mkdir /etc/ansible
cd /etc/ansible
vim hosts
enter localhost and save
useradd ansadmin
passwd ansadmin
echo "ansadmin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
yum install docker -y
systemctl start docker
systemctl status docker
usermod -aG docker ansadmin
su - ansadmin
cd /opt/
sudo mkdir docker
sudo chown -R ansadmin:ansadmin docker
ssh-copy-id ansadmin@localhost
ssh ansadmin@localhost
yes
ssh-copy-id [email protected] (private ip of docker)
yes
GO TO DOCKER SERVER
yum install docker -y
systemctl start docker
systemctl status docker
Dashboard -- > Manage Jenkins -- > Configure System
ssh server -- > add -- > name: ansible server -- > hostname: private ip of ansible -- > Username:ansadmin
Use password authentication, or use a different key : password -- > Test Configure -- > Apply & save
GOT TO ANSIBLE SEREVER
docker login
JOBS -- > ABC PROJECT -- > MAVEN PROJECT -- >
GIT : Repo url and Branch
on host file we need to give docker private ip
Build: Root POM: pom.xml -- > Goals ans Options: clean install package
PostBuild Actions : Send build artifacts over SSH
Name: ansible -- > Source files: Dockerfile, hosts, create-simple-devops-image.yml, create-simple-devops-project.yml
Remote directory: //opt/docker -- > apply & save
go to ansible node and loginto ansadmin and under /opt/docker you will see files
PostBuild Actions : Send build artifacts over SSH
Name: ansible -- > Source files: webapp/target/*.war -- > Remove prefix: webapp/target
Remote directory: //opt/docker -- > Exec command:
ansible-playbook -i /opt/docker/hosts /opt/docker/create-simple-devops-image.yml --limit localhost;
ansible-playbook -i /opt/docker/hosts /opt/docker/create-simple-devops-project.yml --limit 172.31.93.8;
apply & save
Brfor build check docker images & containers docker and ansibe server
FINAL OP:
DOCKERPUBLICIP:8080/webapp
FAILED:
EXECUTE PLAYBOOKS MANUALLY CHECK THE TAG AND USERNAME OF THE IMAGE OF PLAYBOOK
============================================================================================================================================================================================
TERRAFOR PROJECT:
Create 2 instnaces jenkins and mormal
manage plugins -- > terraform -- > install
manage jenkins -- > global tool config -- > Terraform -- > add Terraform
if You want to install automatically
Name : Terraform -- > Install from bintray.com : Terraform 1.1.3 linux (amd64)
if You want to install manually
untick the box -- > Install directory: /usr/local/bin -- > save
Dashboard -- > Manage Jenkins -- > Credentials -- > System -- > Global credentials (unrestricted)
if you want to interact github withapi then we need to generate a token (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)
kind: secret text -- > Secret: Give token -- > ID : github_api -- > create
Manage Jenkins -- > Configure System -- > GitHub -- > GitHub Server -- > Name: github_api -- > Credentials: github_api
Click on Manage hooks -- > Test Connection: Credentials verified for user RAHAMSHAIK007, rate limit: 4999 -- > save
Now we have authenticated from this jenkins machine to github
Manage Jenkins -- > Credentials -- > System -- > Global credentials (unrestricted) -- > Add credentials
Kind: secret text -- > ID: AWS_ACCESS_KEY_ID -- > Secret: -- > save
Kind: secret text -- > ID: AWS_SECRET_ACCESS_KEY -- > Secret: -- > save
jobs -- > Name -- > Pipeline -- > Build triggers -- > GitHub hook trigger for GITScm polling -- >
Pipeline -- > Pipeline script from SCM -- > SCM: Git -- > Repo URL: https://github.com/RAHAMSHAIK007/terrarepo.git
READ PIPELINE:
Pipeline syntax -- > Declarative -- > sample Directive: Tool -- > Add: Terraform -- > Generate -- >