1
+ import groovy.transform.Field
2
+
3
+ @Field
4
+ def shOutput = " "
5
+ def buildxPushTags = " "
6
+
1
7
pipeline {
2
8
agent {
3
9
label ' docker-multiarch'
@@ -16,6 +22,8 @@ pipeline {
16
22
COMPOSE_FILE = ' docker/docker-compose.ci.yml'
17
23
COMPOSE_INTERACTIVE_NO_CLI = 1
18
24
BUILDX_NAME = " ${ COMPOSE_PROJECT_NAME} "
25
+ DOCS_BUCKET = ' jc21-npm-site'
26
+ DOCS_CDN = ' EN1G6DEWZUTDT'
19
27
}
20
28
stages {
21
29
stage(' Environment' ) {
@@ -26,7 +34,7 @@ pipeline {
26
34
}
27
35
steps {
28
36
script {
29
- env . BUILDX_PUSH_TAGS = " -t docker.io/jc21/${ IMAGE} :${ BUILD_VERSION} -t docker.io/jc21/${ IMAGE} :${ MAJOR_VERSION} -t docker.io/jc21/${ IMAGE} :latest"
37
+ buildxPushTags = " -t docker.io/jc21/${ IMAGE} :${ BUILD_VERSION} -t docker.io/jc21/${ IMAGE} :${ MAJOR_VERSION} -t docker.io/jc21/${ IMAGE} :latest"
30
38
}
31
39
}
32
40
}
@@ -39,7 +47,7 @@ pipeline {
39
47
steps {
40
48
script {
41
49
// Defaults to the Branch name, which is applies to all branches AND pr's
42
- env . BUILDX_PUSH_TAGS = " -t docker.io/jc21/${ IMAGE} :github-${ BRANCH_LOWER} "
50
+ buildxPushTags = " -t docker.io/jc21/${ IMAGE} :github-${ BRANCH_LOWER} "
43
51
}
44
52
}
45
53
}
@@ -54,35 +62,28 @@ pipeline {
54
62
}
55
63
}
56
64
}
57
- stage(' Frontend ' ) {
65
+ stage(' Build and Test ' ) {
58
66
steps {
59
- sh ' ./scripts/frontend-build'
67
+ script {
68
+ // Frontend and Backend
69
+ def shStatusCode = sh(label : ' Checking and Building' , returnStatus : true , script : '''
70
+ set -e
71
+ ./scripts/ci/frontend-build > ${WORKSPACE}/tmp-sh-build 2>&1
72
+ ./scripts/ci/test-and-build > ${WORKSPACE}/tmp-sh-build 2>&1
73
+ ''' )
74
+ shOutput = readFile " ${ env.WORKSPACE} /tmp-sh-build"
75
+ if (shStatusCode != 0 ) {
76
+ error " ${ shOutput} "
77
+ }
78
+ }
60
79
}
61
- }
62
- stage(' Backend' ) {
63
- steps {
64
- echo ' Checking Syntax ...'
65
- sh ' docker pull nginxproxymanager/nginx-full:certbot-node'
66
- // See: https://github.com/yarnpkg/yarn/issues/3254
67
- sh ''' docker run --rm \\
68
- -v "$(pwd)/backend:/app" \\
69
- -v "$(pwd)/global:/app/global" \\
70
- -w /app \\
71
- nginxproxymanager/nginx-full:certbot-node \\
72
- sh -c "yarn install && yarn eslint . && rm -rf node_modules"
73
- '''
74
-
75
- echo ' Docker Build ...'
76
- sh ''' docker build --pull --no-cache --squash --compress \\
77
- -t "${IMAGE}:ci-${BUILD_NUMBER}" \\
78
- -f docker/Dockerfile \\
79
- --build-arg TARGETPLATFORM=linux/amd64 \\
80
- --build-arg BUILDPLATFORM=linux/amd64 \\
81
- --build-arg BUILD_VERSION="${BUILD_VERSION}" \\
82
- --build-arg BUILD_COMMIT="${BUILD_COMMIT}" \\
83
- --build-arg BUILD_DATE="$(date '+%Y-%m-%d %T %Z')" \\
84
- .
85
- '''
80
+ post {
81
+ always {
82
+ sh ' rm -f ${WORKSPACE}/tmp-sh-build'
83
+ }
84
+ failure {
85
+ npmGithubPrComment(" CI Error:\n\n ```\n ${ shOutput} \n ```" , true )
86
+ }
86
87
}
87
88
}
88
89
stage(' Integration Tests Sqlite' ) {
@@ -164,10 +165,8 @@ pipeline {
164
165
}
165
166
steps {
166
167
withCredentials([usernamePassword(credentialsId : ' jc21-dockerhub' , passwordVariable : ' dpass' , usernameVariable : ' duser' )]) {
167
- // Docker Login
168
- sh " docker login -u '${ duser} ' -p '${ dpass} '"
169
- // Buildx with push from cache
170
- sh " ./scripts/buildx --push ${ BUILDX_PUSH_TAGS} "
168
+ sh ' docker login -u "${duser}" -p "${dpass}"'
169
+ sh " ./scripts/buildx --push ${ buildxPushTags} "
171
170
}
172
171
}
173
172
}
@@ -181,26 +180,7 @@ pipeline {
181
180
}
182
181
}
183
182
steps {
184
- withCredentials([[$class : ' AmazonWebServicesCredentialsBinding' , accessKeyVariable : ' AWS_ACCESS_KEY_ID' , credentialsId : ' npm-s3-docs' , secretKeyVariable : ' AWS_SECRET_ACCESS_KEY' ]]) {
185
- sh """ docker run --rm \\
186
- --name \$ {COMPOSE_PROJECT_NAME}-docs-upload \\
187
- -e S3_BUCKET=jc21-npm-site \\
188
- -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \\
189
- -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \\
190
- -v \$ (pwd):/app \\
191
- -w /app \\
192
- jc21/ci-tools \\
193
- scripts/docs-upload /app/docs/.vuepress/dist/
194
- """
195
-
196
- sh """ docker run --rm \\
197
- --name \$ {COMPOSE_PROJECT_NAME}-docs-invalidate \\
198
- -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \\
199
- -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \\
200
- jc21/ci-tools \\
201
- aws cloudfront create-invalidation --distribution-id EN1G6DEWZUTDT --paths '/*'
202
- """
203
- }
183
+ npmDocsRelease(" $DOCS_BUCKET " , " $DOCS_CDN " )
204
184
}
205
185
}
206
186
stage(' PR Comment' ) {
@@ -214,7 +194,7 @@ pipeline {
214
194
}
215
195
steps {
216
196
script {
217
- def comment = pullRequest . comment( " This is an automated message from CI: \n\n Docker Image for build ${ BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/jc21/${ IMAGE} ) as `jc21/${ IMAGE} :github-${ BRANCH_LOWER} `\n\n **Note:** ensure you backup your NPM instance before testing this PR image! Especially if this PR contains database changes." )
197
+ npmGithubPrComment( " Docker Image for build ${ BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/jc21/${ IMAGE} ) as `jc21/${ IMAGE} :github-${ BRANCH_LOWER} `\n\n **Note:** ensure you backup your NPM instance before testing this PR image! Especially if this PR contains database changes." , true )
218
198
}
219
199
}
220
200
}
0 commit comments