-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsFile
113 lines (87 loc) · 3.43 KB
/
JenkinsFile
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
pipeline {
agent
{
label 'docker-node'
}
environment
{
DOCKERHUB_CREDENTIALS=credentials('docker-hub')
}
stages {
stage('Clone Project') {
steps {
git branch: 'main', url: 'http://192.168.111.202:3000/stoyan/exam/'
}
}
stage ('Build Images'){
steps {
sh 'cd client && docker image build -t img-client .'
sh 'cd generator && docker image build -t img-generator .'
sh 'cd storage && docker image build -t img-storage .'
}
}
stage ('Network') {
steps{
script
{
sh 'docker network ls | grep exam-net || docker network create exam-net'
}
}
}
stage ('Test-Run') {
steps{
script
{
sh 'docker rm -f con-client || true'
sh 'docker container run -d --name con-client --net exam-net -p 8081:5000 img-client'
sh 'docker rm -f con-storage || true'
sh '''
docker container run -d --name con-storage --net exam-net -e MYSQL_ROOT_PASSWORD='ExamPa$$w0rd' img-storage
'''
sh 'docker rm -f con-generator || true'
sh 'docker container run -d --name con-generator --net exam-net img-generator'
}
}
}
stage ('Test') {
steps{
script
{
echo 'Test #1 - reachability'
sh 'echo $(curl --write-out "%{http_code}" --silent --output /dev/null http://192.168.111.202:8081/) | grep 200'
}
}
}
stage('Login')
{
steps
{
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
stage('Push')
{
steps
{
sh 'docker image tag img-storage yordanovsstoyan/storage'
sh 'docker push yordanovsstoyan/storage'
sh 'docker image tag img-client yordanovsstoyan/client'
sh 'docker push yordanovsstoyan/client'
sh 'docker image tag img-generator yordanovsstoyan/generator'
sh 'docker push yordanovsstoyan/generator'
}
}
stage ('Deploy'){
steps {
sh 'docker rm -f con-client || true'
sh 'docker container run -d --name con-client --net exam-net -p 80:5000 yordanovsstoyan/client'
sh 'docker rm -f con-storage || true'
sh '''
docker container run -d --name con-storage --net exam-net -e MYSQL_ROOT_PASSWORD='ExamPa$$w0rd' yordanovsstoyan/storage
'''
sh 'docker rm -f con-generator || true'
sh 'docker container run -d --name con-generator --net exam-net yordanovsstoyan/generator'
}
}
}
}