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'
@@ -8,14 +14,16 @@ pipeline {
8
14
ansiColor(' xterm' )
9
15
}
10
16
environment {
11
- IMAGE = " nginx-proxy-manager"
17
+ IMAGE = ' nginx-proxy-manager'
12
18
BUILD_VERSION = getVersion()
13
- MAJOR_VERSION = " 2 "
14
- BRANCH_LOWER = " ${ BRANCH_NAME.toLowerCase().replaceAll('/ ', '-')} "
19
+ MAJOR_VERSION = ' 2 '
20
+ BRANCH_LOWER = " ${ BRANCH_NAME.toLowerCase().replaceAll('\\\\', '-').replaceAll('/', '-').replaceAll('\\. ', '-')} "
15
21
COMPOSE_PROJECT_NAME = " npm_${ BRANCH_LOWER} _${ BUILD_NUMBER} "
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,55 +62,52 @@ 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' ) {
89
90
steps {
90
91
// Bring up a stack
91
92
sh ' docker-compose up -d fullstack-sqlite'
92
- sh ' ./scripts/wait-healthy $(docker-compose ps -q fullstack-sqlite) 120'
93
+ sh ' ./scripts/wait-healthy $(docker-compose ps --all -q fullstack-sqlite) 120'
94
+ // Stop and Start it, as this will test it's ability to restart with existing data
95
+ sh ' docker-compose stop fullstack-sqlite'
96
+ sh ' docker-compose start fullstack-sqlite'
97
+ sh ' ./scripts/wait-healthy $(docker-compose ps --all -q fullstack-sqlite) 120'
93
98
94
99
// Run tests
95
100
sh ' rm -rf test/results'
96
101
sh ' docker-compose up cypress-sqlite'
97
102
// Get results
98
- sh ' docker cp -L "$(docker-compose ps -q cypress-sqlite):/test/results" test/'
103
+ sh ' docker cp -L "$(docker-compose ps --all - q cypress-sqlite):/test/results" test/'
99
104
}
100
105
post {
101
106
always {
102
107
// Dumps to analyze later
103
108
sh ' mkdir -p debug'
104
- sh ' docker-compose logs fullstack-sqlite | gzip > debug/docker_fullstack_sqlite.log.gz '
105
- sh ' docker-compose logs db | gzip > debug/docker_db.log.gz '
109
+ sh ' docker-compose logs fullstack-sqlite > debug/docker_fullstack_sqlite.log'
110
+ sh ' docker-compose logs db > debug/docker_db.log'
106
111
// Cypress videos and screenshot artifacts
107
112
dir(path : ' test/results' ) {
108
113
archiveArtifacts allowEmptyArchive : true , artifacts : ' **/*' , excludes : ' **/*.xml'
@@ -115,20 +120,20 @@ pipeline {
115
120
steps {
116
121
// Bring up a stack
117
122
sh ' docker-compose up -d fullstack-mysql'
118
- sh ' ./scripts/wait-healthy $(docker-compose ps -q fullstack-mysql) 120'
123
+ sh ' ./scripts/wait-healthy $(docker-compose ps --all - q fullstack-mysql) 120'
119
124
120
125
// Run tests
121
126
sh ' rm -rf test/results'
122
127
sh ' docker-compose up cypress-mysql'
123
128
// Get results
124
- sh ' docker cp -L "$(docker-compose ps -q cypress-mysql):/test/results" test/'
129
+ sh ' docker cp -L "$(docker-compose ps --all - q cypress-mysql):/test/results" test/'
125
130
}
126
131
post {
127
132
always {
128
133
// Dumps to analyze later
129
134
sh ' mkdir -p debug'
130
- sh ' docker-compose logs fullstack-mysql | gzip > debug/docker_fullstack_mysql.log.gz '
131
- sh ' docker-compose logs db | gzip > debug/docker_db.log.gz '
135
+ sh ' docker-compose logs fullstack-mysql > debug/docker_fullstack_mysql.log'
136
+ sh ' docker-compose logs db > debug/docker_db.log'
132
137
// Cypress videos and screenshot artifacts
133
138
dir(path : ' test/results' ) {
134
139
archiveArtifacts allowEmptyArchive : true , artifacts : ' **/*' , excludes : ' **/*.xml'
@@ -164,10 +169,8 @@ pipeline {
164
169
}
165
170
steps {
166
171
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} "
172
+ sh ' docker login -u "${duser}" -p "${dpass}"'
173
+ sh " ./scripts/buildx --push ${ buildxPushTags} "
171
174
}
172
175
}
173
176
}
@@ -181,26 +184,7 @@ pipeline {
181
184
}
182
185
}
183
186
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
- }
187
+ npmDocsRelease(" $DOCS_BUCKET " , " $DOCS_CDN " )
204
188
}
205
189
}
206
190
stage(' PR Comment' ) {
@@ -214,7 +198,7 @@ pipeline {
214
198
}
215
199
steps {
216
200
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." )
201
+ 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
202
}
219
203
}
220
204
}
0 commit comments