-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Jenkinsfile.Deploy
116 lines (113 loc) · 3.97 KB
/
Jenkinsfile.Deploy
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
pipeline {
agent { label "sweetheart" }
environment {
MYHOME = "$HOME/Documents/django-whatsapp-web-clone"
}
stages {
stage("Pod Svc") {
steps {
sh "podman pod create -n prod-pod -p 6379:6379 -p 8083:8083 -p 5432:5432 -p 8085:8080"
}
}
stage("Redis Svc") {
steps {
// when the build is completed the svc still running but network port is dropped,
// this will help JENKINS_NODE_COOKIE=dontKillMe
sh """
JENKINS_NODE_COOKIE=dontKillMe podman run --pod=prod-pod -d --name redis-prod-svc \
--healthcheck-command 'CMD-SHELL redis-cli || exit 1' \
--healthcheck-start-period=2s \
--healthcheck-interval=10s \
--healthcheck-retries=3 \
registry.redhat.io/rhel8/redis-5:1-160.1647451816
"""
sh """
#!/bin/bash
while [ "`podman healthcheck run redis-prod-svc`" = "unhealthy" ]; do
sleep 3
done
"""
}
}
stage("PSQL Svc") {
steps {
// when the build is completed the svc still running but network port is dropped,
// this will help JENKINS_NODE_COOKIE=dontKillMe
sh """
JENKINS_NODE_COOKIE=dontKillMe podman run --pod=prod-pod -d --name psql-prod-svc \
--healthcheck-command 'CMD-SHELL pg_isready || exit 1' \
--healthcheck-start-period=2s \
--healthcheck-interval=10s \
--healthcheck-retries=3 \
--env-file=$MYHOME/.env.production \
registry.redhat.io/rhel8/postgresql-12:1-99.1647451835
"""
sh """
#!/bin/bash
while [ "`podman healthcheck run psql-prod-svc`" = "unhealthy" ]; do
sleep 10
done
"""
}
}
stage("App Svc") {
steps {
// when the build is completed the svc still running but network port is dropped,
// this will help JENKINS_NODE_COOKIE=dontKillMe
sh '''
JENKINS_NODE_COOKIE=dontKillMe podman run -u root --pod=prod-pod -d --name app-prod-svc \
--healthcheck-command "CMD-SHELL python manage.py test || exit 1" \
--healthcheck-interval=10s \
--healthcheck-start-period=10s \
--healthcheck-retries=3 \
--env-file=$MYHOME/.env.production -v $MYHOME:/opt/app-root/src/ \
registry.access.redhat.com/ubi8/python-38 bash -c "pip install -U pip && pip install -r requirements.txt && python manage.py migrate && python manage.py createsuperuser --no-input ; python manage.py runserver 0.0.0.0:8083"
'''
sh """
#!/bin/bash
while [ "`podman healthcheck run app-prod-svc`" = "unhealthy" ]; do
sleep 15
done
"""
}
}
stage("Nginx Svc") {
steps {
// when the build is completed the svc still running but network port is dropped,
// this will help JENKINS_NODE_COOKIE=dontKillMe
sh '''
JENKINS_NODE_COOKIE=dontKillMe podman run -u root -d --pod=prod-pod --name nginx-prod-svc \
--healthcheck-command "CMD-SHELL nginx -T || exit 1" \
--healthcheck-interval=5s \
--healthcheck-start-period=10s \
--healthcheck-retries=3 \
-v $MYHOME/nginx-cfg:/opt/app-root/etc/nginx.d/:Z \
-v $MYHOME:/opt/app-root/src/:Z \
registry.access.redhat.com/ubi8/nginx-118 nginx -g "daemon off;"
'''
sh """
#!/bin/bash
while [ "`podman healthcheck run nginx-prod-svc`" = "unhealthy" ]; do
sleep 3
done
"""
}
}
}
post {
// Clean after build
always {
cleanWs()
}
success {
echo "Build success"
}
failure {
echo "Build failed"
}
aborted {
echo "Build aborted"
sh "podman pod rm prod-pod -f"
}
}
}