-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.groovy
116 lines (111 loc) · 3.48 KB
/
Jenkinsfile.groovy
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
def githubRegistry = "ghcr.io"
def githubRepo = "supercluster-covid-data-portal/api"
def commit = "UNKNOWN"
def version = "UNKNOWN"
pipeline {
agent {
kubernetes {
label 'api-executor'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: node
image: node:12.13.1
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: {}
"""
}
}
stages {
stage('Prepare') {
steps {
script {
commit = sh(returnStdout: true, script: 'git describe --always').trim()
}
script {
version = sh(returnStdout: true, script: 'cat ./package.json | grep version | cut -d \':\' -f2 | sed -e \'s/"//\' -e \'s/",//\'').trim()
}
}
}
stage('Build & Publish Development Changes') {
when {
branch 'develop'
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId:'argoContainers', usernameVariable: 'GITHUB_APP', passwordVariable: 'GITHUB_ACCESS_TOKEN', )]) {
sh 'echo $GITHUB_ACCESS_TOKEN | docker login ghcr.io -u $GITHUB_APP --password-stdin'
}
sh "docker build --network=host -f Dockerfile . -t ${githubRegistry}/${githubRepo}:${commit} -t ${githubRegistry}/${githubRepo}:edge"
sh "docker push ${githubRegistry}/${githubRepo}:${commit}"
sh "docker push ${githubRegistry}/${githubRepo}:edge"
}
}
}
stage('deploy to supercluster-covid-data-portal') {
when {
branch "develop"
}
steps {
build(job: "supercluster/update-app-version", parameters: [
[$class: 'StringParameterValue', name: 'SUPERCLUSTER_ENV', value: 'dev' ],
[$class: 'StringParameterValue', name: 'TARGET_RELEASE', value: 'api'],
[$class: 'StringParameterValue', name: 'NEW_APP_VERSION', value: "${commit}" ]
])
}
}
stage('Release & Tag') {
when {
anyOf {
branch 'main'
}
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId: 'supercluster-jenkins', passwordVariable: 'GITHUB_ACCESS_TOKEN', usernameVariable: 'GITHUB_APP')]) {
sh "git tag ${version}"
sh "git push https://x-access-token:${GITHUB_ACCESS_TOKEN}@github.com/${githubRepo} --tags"
}
withCredentials([usernamePassword(credentialsId:'argoContainers', passwordVariable: 'GITHUB_ACCESS_TOKEN', usernameVariable: 'GITHUB_APP', )]) {
sh 'echo $GITHUB_ACCESS_TOKEN | docker login ghcr.io -u $GITHUB_APP --password-stdin'
}
sh "docker build --network=host -f Dockerfile . -t ${githubRegistry}/${githubRepo}:${version} -t ${githubRegistry}/${githubRepo}:latest"
sh "docker push ${githubRegistry}/${githubRepo}:${version}"
sh "docker push ${githubRegistry}/${githubRepo}:latest"
}
}
}
}
}