-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
53 lines (53 loc) · 2.14 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
pipeline {
agent any
environment {
DOCKERHUB_USER = "natsutoppan"
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"
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 dockerkvs_apptest pytest -v test_app.py"
sh "docker -H ssh://${BUILD_HOST} container exec dockerkvs_webtest pytest -v test_static.py"
sh "docker -H ssh://${BUILD_HOST} container exec dockerkvs_webtest pytest -v test_selenium.py"
sh "docker-compose -H ssh://${BUILD_HOST} -f docker-compose.build.yml down"
}
}
stage('Register') {
steps {
sh "docker -H ssh://${BUILD_HOST} tag dockerkvs_web ${DOCKERHUB_USER}/dockerkvs_web:${BUILD_TIMESTAMP}"
sh "docker -H ssh://${BUILD_HOST} tag dockerkvs_app ${DOCKERHUB_USER}/dockerkvs_app:${BUILD_TIMESTAMP}"
sh "docker -H ssh://${BUILD_HOST} push ${DOCKERHUB_USER}/dockerkvs_web:${BUILD_TIMESTAMP}"
sh "docker -H ssh://${BUILD_HOST} push ${DOCKERHUB_USER}/dockerkvs_app:${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"
}
}
}
}