forked from jose-correia/brain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
65 lines (56 loc) · 1.37 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
pipeline {
agent any
environment {
DOTENV_FILE_ID = credentials('brain-environment-variables')
}
stages {
stage('Build Docker image') {
steps {
sh 'cp -n ${DOTENV_FILE_ID} .'
sh 'docker build --tag jeec_brain:latest .'
}
}
stage('Migrate Database') {
when {
beforeInput true
branch 'master'
}
input {
message "Run database migration?"
}
steps {
script {
sh '''
echo "Starting database migration..."
docker-compose up db_migration
echo "Database migrated successfuly!!"
'''
}
}
}
stage('Deploy Production') {
when {
beforeInput true
branch 'master'
}
input {
message "Deploy to production?"
}
steps {
script {
sh '''
if [ "$(docker ps -q -a -f name=jeec_brain)" ];then
echo "Stopping old jeec_brain Docker container..."
docker stop jeec_brain
docker rm jeec_brain
echo "Old jeec_brain Docker container stopped!"
fi
echo "Starting new Docker container..."
docker-compose up -d jeec_brain
echo "Docker container started!"
'''
}
}
}
}
}