-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
49 lines (49 loc) · 1.74 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
pipeline {
agent any
environment {
DOCKERHUB_USER = "hender14"
BUILD_HOST = "[email protected]"
PROD_HOST = "[email protected]"
BUILD_TIMESTAMP = sh(script: "date +%Y%m%d-%H%M%S", returnStdout: true).trim()
}
stages {
stage('Pre Check') {
steps {
sh "test -f ~/.docker/config.json"
sh "cat ~/.docker/config.json | grep docker.io"
}
}
stage('Build') {
steps {
sh "cat docker-compose.build.yml"
sh "docker-compose -H ssh://${BUILD_HOST} -f docker-compose.build.yml down"
sh "docker -H ssh://${BUILD_HOST} volume prune -f"
sh "docker-compose -H ssh://${BUILD_HOST} -f docker-compose.build.yml build --no-cache"
sh "docker-compose -H ssh://${BUILD_HOST} -f docker-compose.build.yml up -d"
sh "docker-compose -H ssh://${BUILD_HOST} -f docker-compose.build.yml ps"
}
}
stage('Test') {
steps {
sh "docker -H ssh://${BUILD_HOST} container exec django_web python manage.py test"
sh "docker-compose -H ssh://${BUILD_HOST} -f docker-compose.build.yml down"
}
}
stage('Register') {
steps {
sh "docker -H ssh://${BUILD_HOST} tag django_web ${DOCKERHUB_USER}/django_web:${BUILD_TIMESTAMP}"
sh "docker -H ssh://${BUILD_HOST} push ${DOCKERHUB_USER}/django_web:${BUILD_TIMESTAMP}"
}
}
stage('Deploy') {
steps {
sh "cat docker-compose.prod.yml"
sh "echo 'DOCKERHUB_USER=${DOCKERHUB_USER}' > .env"
sh "echo 'BUILD_TIMESTAMP=${BUILD_TIMESTAMP}' >> .env"
sh "cat .env"
sh "docker-compose -H ssh://${PROD_HOST} -f docker-compose.prod.yml up -d"
sh "docker-compose -H ssh://${PROD_HOST} -f docker-compose.prod.yml ps"
}
}
}
}