Skip to content

Commit f0c8020

Browse files
authoredApr 14, 2023
Merge pull request #685 from overture-stack/ghcr-migration
Ghcr migration
2 parents b9a832c + c57ee02 commit f0c8020

File tree

1 file changed

+189
-43
lines changed

1 file changed

+189
-43
lines changed
 

‎Jenkinsfile

+189-43
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
def commit = "UNKNOWN"
2-
def version = "UNKNOWN"
3-
def chartversion = "3.1.0"
1+
def chartversion = "3.1.1"
42

53
pipeline {
64
agent {
@@ -29,11 +27,6 @@ spec:
2927
volumeMounts:
3028
- name: docker-graph-storage
3129
mountPath: /var/lib/docker
32-
- name: helm
33-
image: alpine/helm:2.12.3
34-
command:
35-
- cat
36-
tty: true
3730
- name: docker
3831
image: docker:18-git
3932
tty: true
@@ -50,17 +43,45 @@ spec:
5043
"""
5144
}
5245
}
46+
47+
environment {
48+
gitHubRegistry = 'ghcr.io'
49+
gitHubRepo = 'overture-stack/ego'
50+
gitHubImageName = "${gitHubRegistry}/${gitHubRepo}"
51+
dockerHubImageName = 'overture/ego'
52+
DEPLOY_TO_DEV = false
53+
PUBLISH_IMAGE = false
54+
55+
commit = sh(
56+
returnStdout: true,
57+
script: 'git describe --always'
58+
).trim()
59+
60+
version = readMavenPom().getVersion()
61+
slackNotificationsUrl = credentials('OvertureSlackJenkinsWebhookURL')
62+
63+
}
64+
65+
parameters {
66+
booleanParam(
67+
name: 'DEPLOY_TO_DEV',
68+
defaultValue: "${env.DEPLOY_TO_DEV}",
69+
description: 'Deploys your branch to argo-dev'
70+
)
71+
booleanParam(
72+
name: 'PUBLISH_IMAGE',
73+
defaultValue: "${env.PUBLISH_IMAGE ?: params.DEPLOY_TO_DEV}",
74+
description: 'Publishes an image with {git commit} tag'
75+
)
76+
}
77+
78+
options {
79+
timeout(time: 30, unit: 'MINUTES')
80+
timestamps()
81+
}
82+
83+
5384
stages {
54-
stage('Prepare') {
55-
steps {
56-
script {
57-
commit = sh(returnStdout: true, script: 'git describe --always').trim()
58-
}
59-
script {
60-
version = readMavenPom().getVersion()
61-
}
62-
}
63-
}
6485
stage('Test') {
6586
environment {
6687
SELENIUM_TEST_TYPE = 'BROWSERSTACK'
@@ -77,10 +98,19 @@ spec:
7798
}
7899
}
79100
}
101+
102+
stage('Build image') {
103+
steps {
104+
container('docker') {
105+
sh "docker build --network=host -f Dockerfile . -t ${gitHubImageName}:${commit}"
106+
}
107+
}
108+
}
109+
80110
stage('Build Artifact & Publish') {
81111
when {
82112
anyOf {
83-
branch "master"
113+
branch "main"
84114
branch "develop"
85115
}
86116
}
@@ -93,45 +123,113 @@ spec:
93123
}
94124
}
95125
}
96-
stage('Build & Publish Develop') {
126+
127+
stage('Publish images') {
97128
when {
98-
branch "develop"
129+
anyOf {
130+
branch 'develop'
131+
branch 'main'
132+
expression { return params.PUBLISH_IMAGE }
133+
}
99134
}
100135
steps {
101136
container('docker') {
102-
withCredentials([usernamePassword(credentialsId:'OvertureDockerHub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
103-
sh 'docker login -u $USERNAME -p $PASSWORD'
137+
withCredentials([usernamePassword(
138+
credentialsId:'OvertureBioGithub',
139+
passwordVariable: 'PASSWORD',
140+
usernameVariable: 'USERNAME'
141+
)]) {
142+
sh "docker login ${gitHubRegistry} -u $USERNAME -p $PASSWORD"
143+
144+
script {
145+
if (env.BRANCH_NAME ==~ 'main') { //push edge and commit tags
146+
sh "docker tag ${gitHubImageName}:${commit} ${gitHubImageName}:${version}"
147+
sh "docker push ${gitHubImageName}:${version}"
148+
149+
sh "docker tag ${gitHubImageName}:${commit} ${gitHubImageName}:latest"
150+
sh "docker push ${gitHubImageName}:latest"
151+
} else { // push commit tag
152+
sh "docker push ${gitHubImageName}:${commit}"
153+
}
154+
155+
if (env.BRANCH_NAME ==~ 'develop') { // push edge tag
156+
sh "docker tag ${gitHubImageName}:${commit} ${gitHubImageName}:edge"
157+
sh "docker push ${gitHubImageName}:edge"
158+
}
159+
}
160+
}
161+
}
162+
container('docker') {
163+
withCredentials([usernamePassword(
164+
credentialsId:'OvertureDockerHub',
165+
passwordVariable: 'PASSWORD',
166+
usernameVariable: 'USERNAME'
167+
)]) {
168+
sh "docker login -u $USERNAME -p $PASSWORD"
169+
170+
script {
171+
if (env.BRANCH_NAME ==~ 'main') { //push edge and commit tags
172+
sh "docker tag ${gitHubImageName}:${commit} ${dockerHubImageName}:${version}"
173+
sh "docker push ${dockerHubImageName}:${version}"
174+
175+
sh "docker tag ${gitHubImageName}:${commit} ${dockerHubImageName}:latest"
176+
sh "docker push ${dockerHubImageName}:latest"
177+
} else { // push commit tag
178+
sh "docker tag ${gitHubImageName}:${commit} ${dockerHubImageName}:${commit}"
179+
sh "docker push ${dockerHubImageName}:${commit}"
180+
}
181+
182+
if (env.BRANCH_NAME ==~ 'develop') { // push edge tag
183+
sh "docker tag ${gitHubImageName}:${commit} ${dockerHubImageName}:edge"
184+
sh "docker push ${dockerHubImageName}:edge"
185+
}
186+
}
104187
}
105-
sh "docker build --network=host -f Dockerfile . -t overture/ego:edge -t overture/ego:${commit}"
106-
sh "docker push overture/ego:${commit}"
107-
sh "docker push overture/ego:edge"
108188
}
109189
}
110190
}
111191

112-
stage('Release & tag') {
113-
when {
114-
branch "master"
115-
}
116-
steps {
117-
container('docker') {
118-
withCredentials([usernamePassword(credentialsId: 'OvertureBioGithub', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
119-
sh "git tag ${version}"
120-
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/overture-stack/ego --tags"
121-
}
122-
withCredentials([usernamePassword(credentialsId:'OvertureDockerHub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
123-
sh 'docker login -u $USERNAME -p $PASSWORD'
192+
stage('Publish tag to github') {
193+
when {
194+
branch 'main'
195+
}
196+
steps {
197+
container('node') {
198+
withCredentials([
199+
usernamePassword(
200+
credentialsId: 'OvertureBioGithub',
201+
passwordVariable: 'GIT_PASSWORD',
202+
usernameVariable: 'GIT_USERNAME'
203+
),
204+
]) {
205+
script {
206+
// we still want to run the platform deploy even if this fails, hence try-catch
207+
try {
208+
sh "git tag ${version}"
209+
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${gitHubRepo} --tags"
210+
sh "curl \
211+
-X POST \
212+
-H 'Content-type: application/json' \
213+
--data '{ \
214+
\"text\":\"New ${gitHubRepo} published succesfully: v.${version}\
215+
\n[Build ${env.BUILD_NUMBER}] (${env.BUILD_URL})\" \
216+
}' \
217+
${slackNotificationsUrl}"
218+
} catch (err) {
219+
echo 'There was an error while publishing packages'
220+
}
221+
}
124222
}
125-
sh "docker build --network=host -f Dockerfile . -t overture/ego:latest -t overture/ego:${version}"
126-
sh "docker push overture/ego:${version}"
127-
sh "docker push overture/ego:latest"
128223
}
129224
}
130225
}
131226

132227
stage('Deploy to Overture QA') {
133228
when {
134-
branch "develop"
229+
anyOf {
230+
branch 'develop'
231+
expression { return params.DEPLOY_TO_DEV }
232+
}
135233
}
136234
steps {
137235
build(job: "/Overture.bio/provision/helm", parameters: [
@@ -148,7 +246,9 @@ spec:
148246

149247
stage('Deploy to Overture Staging') {
150248
when {
151-
branch "master"
249+
anyOf {
250+
branch 'main'
251+
}
152252
}
153253
steps {
154254
build(job: "/Overture.bio/provision/helm", parameters: [
@@ -162,6 +262,52 @@ spec:
162262
])
163263
}
164264
}
265+
}
266+
267+
post {
268+
fixed {
269+
script {
270+
if (env.BRANCH_NAME ==~ /(develop|main|test\S*)/) {
271+
sh "curl \
272+
-X POST \
273+
-H 'Content-type: application/json' \
274+
--data '{ \
275+
\"text\":\"Build Fixed: ${env.JOB_NAME}#${commit} \
276+
\n[Build ${env.BUILD_NUMBER}] (${env.BUILD_URL})\" \
277+
}' \
278+
${slackNotificationsUrl}"
279+
}
280+
}
281+
}
165282

283+
success {
284+
script {
285+
if (env.BRANCH_NAME ==~ /(test\S*)/) {
286+
sh "curl \
287+
-X POST \
288+
-H 'Content-type: application/json' \
289+
--data '{ \
290+
\"text\":\"Build tested: ${env.JOB_NAME}#${commit} \
291+
\n[Build ${env.BUILD_NUMBER}] (${env.BUILD_URL})\" \
292+
}' \
293+
${slackNotificationsUrl}"
294+
}
295+
}
296+
}
297+
298+
unsuccessful {
299+
script {
300+
if (env.BRANCH_NAME ==~ /(develop|main|test\S*)/) {
301+
sh "curl \
302+
-X POST \
303+
-H 'Content-type: application/json' \
304+
--data '{ \
305+
\"text\":\"Build Failed: ${env.JOB_NAME}#${commit} \
306+
\n[Build ${env.BUILD_NUMBER}] (${env.BUILD_URL})\" \
307+
}' \
308+
${slackNotificationsUrl}"
309+
}
310+
}
311+
}
166312
}
167313
}

0 commit comments

Comments
 (0)
Please sign in to comment.