forked from Frenly-web3/Frenly_front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
173 lines (155 loc) · 5.01 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
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
pipeline {
agent any
environment {
REGISTRY_HOST = credentials('docker-registry-host')
REGISTRY_HOST_REMOTE = credentials('docker-registry-domain')
JENKINS_SERVER = credentials('jenkins-server')
GIT_REPO_NAME = env.GIT_URL.replaceFirst(/^.*\/([^\/]+?).git$/, '$1').toLowerCase().trim()
SLACK_CHANNEL = 'C042KE1SV0A'
}
stages {
stage ('Check build') {
when { changeRequest() }
steps {
build_pr('unistory-node', 16)
}
}
stage('Build') {
when {
allOf {
not {
changeRequest()
}
anyOf {
branch 'master'
branch 'main'
branch 'dev'
branch 'development'
}
}
}
steps {
build_image()
script {
if (env.BRANCH_NAME == "master" || env.BRANCH_NAME == "main") {
notify_slack('Production build success')
}
}
}
}
stage('Start') {
parallel {
stage('Prod') {
when {
allOf {
not {
changeRequest()
}
anyOf {
branch 'main'
branch 'master'
}
}
}
stages {
stage('Approve') {
input {
message 'Deploy this build?'
ok 'Yes'
submitter ', alukashenko, nbobkov'
}
environment {
LOKI = credentials('LOKI')
DOCKER = credentials('DOCKER')
SSH_PROFILE = ''
COMPOSE_PROJECT_NAME = 'frenly'
FOLDER = 'frontend'
DOMAIN = ''
PRODUCTION_URL = ''
ENV_FILE = '.env.production'
}
steps {
sh '''
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $SSH_PROFILE bash -c "'
mkdir -p $FOLDER
'"
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no docker-compose.prod.yml $SSH_PROFILE:$FOLDER
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${ENV_FILE} $SSH_PROFILE:$FOLDER
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $SSH_PROFILE \
bash -c "'
cd $FOLDER
echo GIT_REPO_NAME=$GIT_REPO_NAME >> ${ENV_FILE}
echo REGISTRY_HOST_REMOTE=$REGISTRY_HOST_REMOTE >> ${ENV_FILE}
echo BRANCH_NAME=$BRANCH_NAME >> ${ENV_FILE}
echo COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME >> ${ENV_FILE}
echo LOKI_USR=$LOKI_USR >> ${ENV_FILE}
echo LOKI_PSW=$LOKI_PSW >> ${ENV_FILE}
echo DOMAIN=$DOMAIN >> ${ENV_FILE}
echo $DOCKER_PSW > .docker_password
cat .docker_password | docker login $REGISTRY_HOST_REMOTE -u $DOCKER_USR --password-stdin
docker compose -f docker-compose.prod.yml --env-file ${ENV_FILE} pull
docker compose -f docker-compose.prod.yml --env-file ${ENV_FILE} up -d
'"
git restore ${ENV_FILE}
'''
notify_slack("Production deployment success")
}
}
}
}
stage('Dev') {
when {
allOf {
not {
changeRequest()
}
anyOf {
branch 'dev'
branch 'development'
}
}
}
environment {
COMPOSE_PROJECT_NAME = 'frenly'
ENV_FILE = '.development.env'
}
steps {
script {
sh """
echo REGISTRY_HOST=${REGISTRY_HOST} >> ${ENV_FILE}
echo GIT_REPO_NAME=${GIT_REPO_NAME} >> ${ENV_FILE}
echo BRANCH_NAME=${BRANCH_NAME} >> ${ENV_FILE}
echo COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} >> ${ENV_FILE}
if [ "\$(docker-compose port traefik 80)" ]; then
IMAGE_PREVIOUS_PORT="\$(docker-compose port traefik 80 | egrep "[0-9]+\$" -o)"
fi
if [ -z "\${IMAGE_PREVIOUS_PORT}" ]; then
WEB_PORT=80 \
docker-compose --env-file ${ENV_FILE} up -d
else
WEB_PORT="\${IMAGE_PREVIOUS_PORT}:80" \
docker-compose --env-file ${ENV_FILE} up -d
fi
"""
}
notify_slack("Traefik startup success")
}
}
}
}
}
post {
failure {
script {
if (
env.BRANCH_NAME == "dev" ||
env.BRANCH_NAME == "development" ||
env.BRANCH_NAME == "master" ||
env.BRANCH_NAME == "main"
) {
notify_slack('Build failure')
}
}
}
}
}