forked from virusseq/portal-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
170 lines (158 loc) · 4.23 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
String podSpec = '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: node
image: node:16
tty: true
securityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
- name: dind-daemon
image: docker:18.06-dind
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ''
volumeMounts:
- name: dind-storage
mountPath: /var/lib/docker
- name: docker
image: docker:18-git
command:
- cat
tty: true
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: HOME
value: /home/jenkins/agent
securityContext:
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
volumes:
- name: dind-storage
emptyDir: {}
'''
pipeline {
agent {
kubernetes {
yaml podSpec
}
}
environment {
dockerImgRepo = 'ghcr.io/cancogen-virus-seq/portal'
githubRepo = 'cancogen-virus-seq/portal'
commit = sh(
returnStdout: true,
script: 'git describe --always'
).trim()
version = sh(
returnStdout: true,
script: 'cat ./package.json | ' +
'grep "version" | ' +
'cut -d : -f2 | ' +
"sed \'s:[\",]::g\'"
).trim()
}
options {
timeout(time: 30, unit: 'MINUTES')
timestamps()
}
stages {
stage('Build images') {
steps {
container('docker') {
sh "docker build \
--build-arg APP_COMMIT=${commit} \
--build-arg APP_VERSION=${version} \
--network=host \
-f Dockerfile \
-t portal:${commit} ."
}
}
}
// attempt to publish github tag before images to prevent overwriting existing ones.
stage('Publish Git Version Tag') {
when {
branch 'main'
}
steps {
container('docker') {
withCredentials([usernamePassword(
credentialsId: 'argoGithub',
passwordVariable: 'GIT_PASSWORD',
usernameVariable: 'GIT_USERNAME'
)]) {
sh "git tag ${version}"
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${githubRepo} --tags"
}
}
}
}
stage('Publish images') {
when {
anyOf {
branch 'develop'
branch 'main'
// branch 'test'
branch 'arrangerV3'
}
}
steps {
container('docker') {
withCredentials([usernamePassword(
credentialsId:'argoContainers',
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)]) {
sh 'docker login ghcr.io -u $USERNAME -p $PASSWORD'
script {
if (env.BRANCH_NAME ==~ /(main)/) { // push latest and version tags
sh "docker tag portal:${commit} ${dockerImgRepo}:${version}"
sh "docker push ${dockerImgRepo}:${version}"
sh "docker tag portal:${commit} ${dockerImgRepo}:latest"
sh "docker push ${dockerImgRepo}:latest"
} else { // push commit tags
sh "docker tag portal:${commit} ${dockerImgRepo}:${commit}"
sh "docker push ${dockerImgRepo}:${commit}"
}
if (env.BRANCH_NAME ==~ /(develop)/) { // push edge tag
sh "docker tag portal:${commit} ${dockerImgRepo}:edge"
sh "docker push ${dockerImgRepo}:edge"
}
}
}
}
}
}
stage('Deploy to cancogen-virus-seq-dev') {
when {
anyOf {
branch 'develop'
branch 'arrangerV3'
// branch 'test'
}
}
steps {
script {
// we don't want the build to be tagged as failed because it could not be deployed.
try {
build(job: 'virusseq/update-app-version', parameters: [
string(name: 'BUILD_BRANCH', value: env.BRANCH_NAME),
string(name: 'CANCOGEN_ENV', value: 'dev'),
string(name: 'NEW_APP_VERSION', value: "${commit}"),
string(name: 'TARGET_RELEASE', value: 'portalv3'),
])
} catch (err) {
echo 'The app built successfully, but could not be deployed'
}
}
}
}
}
}