-
Notifications
You must be signed in to change notification settings - Fork 45
/
Jenkinsfile
95 lines (81 loc) · 3.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
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
discardOldBuilds()
stage('Checkout') {
node('superstellar-docker-17.12') {
withCleanup {
checkout scm
stash 'source'
}
}
}
stage('Build & Test') {
parallel(
backend: {
node('superstellar-docker-17.12') {
withCleanup {
unstash 'source'
sh "docker build -t superstellar-backend-builder:${env.BUILD_NUMBER} --target builder -f docker/backend/Dockerfile ."
sh "docker build -t superstellar-backend-test:${env.BUILD_NUMBER} --build-arg VERSION=${env.BUILD_NUMBER} -f docker/backend/Dockerfile.test_image ."
sh "docker run --rm superstellar-backend-test:${env.BUILD_NUMBER}"
masterBranchOnly {
stage('Build & Publish backend') {
sh "docker build -t superstellar-backend:${env.BUILD_NUMBER} -f docker/backend/Dockerfile ."
sh "docker tag superstellar-backend:${env.BUILD_NUMBER} gcr.io/kubernetes-playground-195112/superstellar-backend:${env.BUILD_NUMBER}"
withDockerLoggedIntoGCR {
sh "docker push gcr.io/kubernetes-playground-195112/superstellar-backend:${env.BUILD_NUMBER}"
}
}
}
}
}
},
frontend: {
node('superstellar-docker-17.12') {
withCleanup {
unstash 'source'
docker.build("superstellar-frontend:${env.BUILD_NUMBER}", "-f docker/frontend/Dockerfile.production .")
masterBranchOnly {
stage('Publish frontend') {
sh "docker tag superstellar-frontend:${env.BUILD_NUMBER} gcr.io/kubernetes-playground-195112/superstellar-frontend:${env.BUILD_NUMBER}"
withDockerLoggedIntoGCR {
sh "docker push gcr.io/kubernetes-playground-195112/superstellar-frontend:${env.BUILD_NUMBER}"
}
}
}
}
}
}
)
}
masterBranchOnly {
stage(name: 'Deploy') {
milestone 1
node('superstellar-docker-17.12') {
withCleanup {
unstash 'source'
sh "docker build -t superstellar-deployment:${env.BUILD_NUMBER} -f docker/deployment/Dockerfile ."
withCredentials([file(credentialsId: '5bc94dd2-0a14-4bba-bfd9-f628512b3158', variable: 'FILE')]) {
sh 'cp $FILE deployment_volume/service_account.json'
sh "docker run -v ${pwd()}/deployment_volume:/deployment_volume superstellar-deployment:${env.BUILD_NUMBER} /deployment_volume/script.sh ${env.BUILD_NUMBER}"
}
}
}
}
}
stage('Cleanup') {
node('superstellar-docker-17.12') {
withCleanup {
sh 'yes | docker system prune -a --volumes'
}
}
}
def withDockerLoggedIntoGCR(Closure cl) {
withCredentials([file(credentialsId: '5bc94dd2-0a14-4bba-bfd9-f628512b3158', variable: 'FILE')]) {
sh 'cat $FILE | docker login -u _json_key --password-stdin https://gcr.io'
}
cl()
}
def masterBranchOnly(Closure cl) {
if (env.BRANCH_NAME == 'master') {
cl()
}
}