-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJenkinsfile
146 lines (133 loc) · 7.1 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
def nodeInstallationName = 'NodeJS 18.12.0'
/* groovylint-disable DuplicateStringLiteral */
/* groovylint-disable-next-line CompileStatic */
pipeline {
agent any
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '5', numToKeepStr: '5')
disableConcurrentBuilds()
}
stages {
stage('ci') {
agent {
label 'jenkins-build-agent'
}
tools { nodejs nodeInstallationName }
environment {
NODE_ENV = 'test'
NODE_PORT = 3131
ARANGO_DB_HOST_DOMAIN = 'arangotest.digiteched.com'
ARANGO_DB_HOST_SCHEME = 'https'
ARANGO_DB_HOST_PORT = 443
ARANGO_DB_ROOT_PASSWORD = credentials('arango-test-root-password')
ARANGO_DB_USER = 'dbuser'
ARANGO_DB_USER_PASSWORD = credentials('arango-test-db-user-password')
ARANGO_DB_NAME = 'staging'
AUTH0_ISSUER_URL = 'https://foo.auth0.com/'
AUTH0_AUDIENCE = 'https://bar.mydomain.ca'
BASE_DIGITAL_ASSET_URL = 'https://www.myaudio.com:5555/media?id='
GLOBAL_PREFIX = 'api'
SHOULD_ENABLE_LEGACY_GAMES_ENDPOINT = 'false'
}
when {
branch 'PR-*'
}
steps {
configFileProvider([configFile(fileId:'42feff14-78da-45fc-a8ee-5f98213a313f', \
targetLocation: 'apps/coscrad-frontend/src/auth_config.json')]) {
echo 'PR opened or updated...'
echo "NODE ENV: ${NODE_ENV}"
echo 'node version:'
sh 'node -v'
echo 'npm version'
sh 'npm -v'
echo 'Installing dependencies'
sh 'npm ci --legacy-peer-deps'
echo 'Running lint on all COSCRAD projects'
sh 'npm run lint:coscrad'
/**
* Note that the sample content config is actually valid for
* our staging build.
**/
echo 'copying sample content config for test build'
/* groovylint-disable-next-line LineLength */
sh 'cp apps/coscrad-frontend/src/configurable-front-matter/data/content.config.SAMPLE.ts apps/coscrad-frontend/src/configurable-front-matter/data/content.config.ts'
echo 'Building COSCRAD'
echo 'with node version'
sh 'node --version'
sh 'npm run build:coscrad:prod'
echo 'testing coscrad-frontend'
sh 'npx nx test coscrad-frontend --skip-nx-cache'
echo 'testing api (coscrad back-end)'
/**
* While the test falls back to `process.env` whenever there is
* no value from `test.env` we have added an empty `test.env`
* as a hack because by some quirk the mock config implementation
* fails when no file is found.
**/
echo 'creating empty test.env file'
/* groovylint-disable-next-line LineLength */
sh 'touch apps/api/src/app/config/test.env'
sh 'npx nx test api --skip-nx-cache'
}
}
}
stage('deploy to staging') {
agent {
label 'jenkins-build-agent'
}
tools { nodejs nodeInstallationName }
environment {
NODE_ENV = 'staging'
NODE_PORT = 3131
ARANGO_DB_HOST_DOMAIN = 'arangotest.digiteched.com'
ARANGO_DB_HOST_SCHEME = 'https'
ARANGO_DB_HOST_PORT = 443
ARANGO_DB_ROOT_PASSWORD = credentials('arango-test-root-password')
ARANGO_DB_USER = 'dbuser'
ARANGO_DB_USER_PASSWORD = credentials('arango-test-db-user-password')
ARANGO_DB_NAME = 'staging'
AUTH0_ISSUER_URL = 'https://foo.auth0.com/'
AUTH0_AUDIENCE = 'https://bar.mydomain.ca'
BASE_DIGITAL_ASSET_URL = 'https://www.myaudio.com:5555/media?id='
GLOBAL_PREFIX = 'api'
SHOULD_ENABLE_LEGACY_GAMES_ENDPOINT = 'false'
}
when {
branch 'integration'
}
steps {
configFileProvider([configFile(fileId:'42feff14-78da-45fc-a8ee-5f98213a313f', \
targetLocation: 'apps/coscrad-frontend/src/auth_config.json')]) {
echo 'Merged to integration'
echo "NODE ENV: ${NODE_ENV}"
echo 'Installing dependencies'
sh 'npm ci --legacy-peer-deps'
echo 'Building COSCRAD'
echo 'with node version'
sh 'node --version'
/**
* Note that the sample content config is actually valid for
* our staging build.
**/
echo 'copying sample content config for test build'
/* groovylint-disable-next-line LineLength */
sh 'cp apps/coscrad-frontend/src/configurable-front-matter/data/content.config.SAMPLE.ts apps/coscrad-frontend/src/configurable-front-matter/data/content.config.ts'
sh 'npm run build:coscrad:prod'
sh 'npx nx run api:build:cli'
}
}
post {
success {
archiveArtifacts artifacts: 'dist/**, node_modules/**', followSymlinks: false
// Deploy front-end build to staging
sshPublisher(
publishers: [sshPublisherDesc(configName: '[email protected]', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'rm -rf /var/www/html && mv build/dist/apps/coscrad-frontend /var/www/html && rm -rf build', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'build', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'dist/**')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
// Deploy back-end build to staging
sshPublisher(
publishers: [sshPublisherDesc(configName: '[email protected]', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'rm -rf archive ; mv build archive; touch archive/dist/apps/api/staging.env; PATH=$PATH://home/coscradmin/.nvm/versions/node/v18.16.0/bin pm2 restart main; echo API restarted', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'build', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'dist/**, node_modules/**')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
}