@madgex/fert 5.0.2 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -8
- package/bin/cli.js +4 -1
- package/bin/commands/_service-command-bootstrap.js +20 -5
- package/bin/commands/configs.js +0 -1
- package/bin/commands/publish.js +8 -20
- package/bin/utils/configs.js +35 -24
- package/bin/utils/index.js +2 -0
- package/package.json +1 -1
- package/delivery/jenkinsfile +0 -93
package/README.md
CHANGED
|
@@ -198,7 +198,7 @@ Templates & CSS may be processed using the [CSS Modules](https://github.com/css-
|
|
|
198
198
|
## Publish
|
|
199
199
|
|
|
200
200
|
From root, run for all services or a specific service:
|
|
201
|
-
`fert publish --target=
|
|
201
|
+
`fert publish --target=production` | `fert publish --target=production --service-name=jobseekers-frontend`
|
|
202
202
|
|
|
203
203
|
Run for 1 service from the service folder:
|
|
204
204
|
`cd services/jobseekers-frontend`
|
|
@@ -208,10 +208,10 @@ Run for 1 service from the service folder:
|
|
|
208
208
|
|
|
209
209
|
`fert publish --target [target]`
|
|
210
210
|
|
|
211
|
-
| Option |
|
|
212
|
-
| ----------- |
|
|
213
|
-
| `--target` | Where to publish the `dist` directory assets.<br/>`dev` \| `
|
|
214
|
-
| `--dry-run` | Dry run, dont actually upload anything
|
|
211
|
+
| Option | |
|
|
212
|
+
| ----------- | ---------------------------------------------------------------------------------- |
|
|
213
|
+
| `--target` | Where to publish the `dist` directory assets.<br/>`dev` \| `production` (`string`) |
|
|
214
|
+
| `--dry-run` | Dry run, dont actually upload anything |
|
|
215
215
|
|
|
216
216
|
Send all files and directories created in the `dist` directory to either development or production versions of the Asset Store API. Files uploaded to the Asset Store API are available via a CloudFront-based CDN.
|
|
217
217
|
|
|
@@ -316,7 +316,19 @@ These options are available no matter the command used.
|
|
|
316
316
|
|
|
317
317
|
# CI/CD
|
|
318
318
|
|
|
319
|
-
|
|
319
|
+
All branding repos use a common jekinsfile and Dockerfile to build/deploy, and will use this FERT tool.
|
|
320
|
+
|
|
321
|
+
- Here is the jenkinsfile all branding repos use: https://github.com/wiley/madgex-jenkins-shared-library/blob/master/vars/clientRepoDeploymentPipeline.groovy .
|
|
322
|
+
- And the Dockerfile they all use [is in this repo](shared/Dockerfile.brandingRepoPublish).
|
|
323
|
+
|
|
324
|
+
Each change that's pushed to a branch will trigger:
|
|
325
|
+
|
|
326
|
+
1. a build (`npm run build` inside the [Dockerfile](shared/Dockerfile.brandingRepoPublish) as a common entry point), which creates a `dist` folder full of assets ready to upload.
|
|
327
|
+
2. The [jenkinsfile](https://github.com/wiley/madgex-jenkins-shared-library/blob/master/vars/clientRepoDeploymentPipeline.groovy) pipeline will run `fert publish` to send all built assets to the Asset Store API.
|
|
328
|
+
3. The [jenkinsfile](https://github.com/wiley/madgex-jenkins-shared-library/blob/master/vars/clientRepoDeploymentPipeline.groovy) pipeline will run `fert configs --publish`, Uploading the branding repo's client `/configs` to the configuration-api.
|
|
329
|
+
|
|
330
|
+
> [!NOTE]
|
|
331
|
+
> `master` branch will go to `production`. All other branches will go to `jb dev`.
|
|
320
332
|
|
|
321
333
|
## `npm scripts`
|
|
322
334
|
|
|
@@ -330,5 +342,3 @@ Here are the default npm scripts in a Fert-scaffolded project.
|
|
|
330
342
|
}
|
|
331
343
|
}
|
|
332
344
|
```
|
|
333
|
-
|
|
334
|
-
Its expected that a Jenkins pipeline will run `fert publish` to send all built assets to the Asset Store API.
|
package/bin/cli.js
CHANGED
|
@@ -37,7 +37,10 @@ const run = () => {
|
|
|
37
37
|
|
|
38
38
|
cli
|
|
39
39
|
.command('publish', 'Publish the project')
|
|
40
|
-
.option(
|
|
40
|
+
.option(
|
|
41
|
+
'--target <env>',
|
|
42
|
+
'Environment to publish to, "dev" or "production"'
|
|
43
|
+
)
|
|
41
44
|
.option('--service-name <serviceName>', '[string] run a single service')
|
|
42
45
|
.option('--dry-run', 'Dry run, dont actually upload anything')
|
|
43
46
|
.action((...args) => serivceCommandBootstrap('publish', ...args));
|
|
@@ -9,6 +9,7 @@ const commandDevSever = require('./dev-server.js');
|
|
|
9
9
|
const commandBuild = require('./build.js');
|
|
10
10
|
const commandPublish = require('./publish.js');
|
|
11
11
|
const { FERT_SERVICE_CONFIG_FILENAME } = require('../../constants.js');
|
|
12
|
+
const { log } = require('../utils/logging.js');
|
|
12
13
|
|
|
13
14
|
const commandMap = {
|
|
14
15
|
dev: commandDevSever,
|
|
@@ -54,13 +55,27 @@ module.exports.serivceCommandBootstrap = async function serivceCommandBootstrap(
|
|
|
54
55
|
}
|
|
55
56
|
// not single service - try to find and load all services
|
|
56
57
|
const serviceConfigs = await loadServiceConfigFiles();
|
|
58
|
+
|
|
59
|
+
if (!serviceConfigs.length) {
|
|
60
|
+
log.error('No services found\n');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
57
64
|
console.log(
|
|
58
|
-
`🔦 ${chalk.green('Running multi service mode')},
|
|
65
|
+
`🔦 ${chalk.green('Running multi service mode')}, calling ${chalk.cyan(command)} on ${chalk.cyan(serviceConfigs.length)} ${serviceConfigs.length === 1 ? 'service' : 'services'} [${serviceConfigs.map((i) => chalk.cyanBright(i?.serviceConfig?.serviceName || 'Unknown')).join(', ')}]`
|
|
59
66
|
);
|
|
67
|
+
|
|
60
68
|
for (const { serviceConfig } of serviceConfigs) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
try {
|
|
70
|
+
await commandMap[command]({
|
|
71
|
+
...options,
|
|
72
|
+
serviceName: serviceConfig.serviceName,
|
|
73
|
+
});
|
|
74
|
+
} catch (err) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Failed to run command ${command} on service ${serviceConfig.serviceName}: ${err.message}`,
|
|
77
|
+
{ cause: err }
|
|
78
|
+
);
|
|
79
|
+
}
|
|
65
80
|
}
|
|
66
81
|
};
|
package/bin/commands/configs.js
CHANGED
package/bin/commands/publish.js
CHANGED
|
@@ -5,10 +5,6 @@ const { resolveConfig } = require('../utils');
|
|
|
5
5
|
const { log } = require('../utils/logging');
|
|
6
6
|
const getAwsParam = require('./publish-tasks/get-aws-parameter');
|
|
7
7
|
const AssetStoreUploader = require('./publish-tasks/asset-store-uploader');
|
|
8
|
-
const {
|
|
9
|
-
updateProjectConfigs,
|
|
10
|
-
validateLocalConfigs,
|
|
11
|
-
} = require('../utils/configs.js');
|
|
12
8
|
const {
|
|
13
9
|
getCloudFrontDistributionsForDomain,
|
|
14
10
|
} = require('../utils/lookup-cf-distribution-ids');
|
|
@@ -23,7 +19,12 @@ const {
|
|
|
23
19
|
|
|
24
20
|
module.exports = async (options) => {
|
|
25
21
|
const fertConfig = await resolveConfig(options);
|
|
26
|
-
const validTargets = ['dev', 'prod'];
|
|
22
|
+
const validTargets = ['dev', 'prod', 'production'];
|
|
23
|
+
|
|
24
|
+
// handle legacy options
|
|
25
|
+
if (options.target === 'prod') {
|
|
26
|
+
options.target = 'production';
|
|
27
|
+
}
|
|
27
28
|
|
|
28
29
|
if (!validTargets.includes(options.target)) {
|
|
29
30
|
throw Error(
|
|
@@ -36,8 +37,8 @@ module.exports = async (options) => {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
const templateCtx = {
|
|
39
|
-
env: options.target === '
|
|
40
|
-
Environment_Name: options.target
|
|
40
|
+
env: options.target === 'dev' ? 'jb.dev' : 'job',
|
|
41
|
+
Environment_Name: options.target,
|
|
41
42
|
fertConfig,
|
|
42
43
|
};
|
|
43
44
|
|
|
@@ -82,19 +83,6 @@ module.exports = async (options) => {
|
|
|
82
83
|
if (!options.dryRun) {
|
|
83
84
|
uploadResult = await assetStore.uploadDir(localDir);
|
|
84
85
|
}
|
|
85
|
-
// validate & upload local configs to configuration API
|
|
86
|
-
if (!options.dryRun) {
|
|
87
|
-
await updateProjectConfigs({
|
|
88
|
-
workingDir: fertConfig.rootDir,
|
|
89
|
-
clientPropertyId: fertConfig.clientPropertyId,
|
|
90
|
-
environment: fertConfig.currBranch === 'master' ? 'production' : 'dev',
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
await validateLocalConfigs({
|
|
94
|
-
workingDir: fertConfig.rootDir,
|
|
95
|
-
clientPropertyId: fertConfig.clientPropertyId,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
86
|
|
|
99
87
|
log.success(
|
|
100
88
|
`Publish complete in ${((uploadResult?.duration || 1) / 1000).toFixed(0)}s\n`
|
package/bin/utils/configs.js
CHANGED
|
@@ -3,7 +3,6 @@ const path = require('node:path');
|
|
|
3
3
|
const Hoek = require('@hapi/hoek');
|
|
4
4
|
const { log } = require('../utils/logging');
|
|
5
5
|
const chalk = require('chalk');
|
|
6
|
-
const ora = require('ora');
|
|
7
6
|
const { CONFIG_DIR } = require('../../constants');
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -12,7 +11,7 @@ const { CONFIG_DIR } = require('../../constants');
|
|
|
12
11
|
* @param {Object} options - required, The options object.
|
|
13
12
|
* @param {string} options.workingDir - required, Working dir for configs - should usually be 'root' where fert.config.js is
|
|
14
13
|
* @param {string} options.clientPropertyId - required, clientPropertyId
|
|
15
|
-
* @param {boolean} options.throwable -
|
|
14
|
+
* @param {boolean} [options.throwable=false] - Whether to throw validation errors or just log them.
|
|
16
15
|
*
|
|
17
16
|
* @returns {Promise<void>} - Returns a promise that resolves if all configurations are valid.
|
|
18
17
|
* @throws {Error} - Throws an error if any configuration is invalid.
|
|
@@ -153,7 +152,6 @@ const updateProjectConfigs = async ({
|
|
|
153
152
|
Hoek.assert(workingDir, 'workingDir is required');
|
|
154
153
|
|
|
155
154
|
const dir = path.join(workingDir, CONFIG_DIR);
|
|
156
|
-
let spinner;
|
|
157
155
|
|
|
158
156
|
if (!fs.existsSync(dir)) {
|
|
159
157
|
log.debug(`Directory does not exist: ${dir}`);
|
|
@@ -164,22 +162,22 @@ const updateProjectConfigs = async ({
|
|
|
164
162
|
try {
|
|
165
163
|
await validateLocalConfigs({ clientPropertyId, workingDir });
|
|
166
164
|
const api = await getConfigAPI({ clientPropertyId, environment });
|
|
167
|
-
|
|
165
|
+
|
|
166
|
+
log.info('Updating configs…');
|
|
168
167
|
|
|
169
168
|
const localConfigs = loadLocalConfigs(workingDir);
|
|
170
169
|
const { toRemove, toSet } = collateConfigs(api, localConfigs);
|
|
171
170
|
|
|
172
|
-
|
|
173
|
-
await setConfigs(api, toSet,
|
|
174
|
-
await removeConfigs(api, toRemove, spinner);
|
|
171
|
+
// Will throw on first failure
|
|
172
|
+
await Promise.all([setConfigs(api, toSet), removeConfigs(api, toRemove)]);
|
|
175
173
|
|
|
176
174
|
const { host } = new URL(api.options.apiUrl);
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
log.info(``);
|
|
176
|
+
log.info(`Project configs applied to ${chalk.bold(host)}`);
|
|
179
177
|
return true;
|
|
180
178
|
} catch (error) {
|
|
181
|
-
|
|
182
|
-
log.error(error);
|
|
179
|
+
log.info(``);
|
|
180
|
+
log.error('Failed to apply project configs', error);
|
|
183
181
|
throw error;
|
|
184
182
|
}
|
|
185
183
|
};
|
|
@@ -241,32 +239,45 @@ const getUnsetKeysWithDefaults = (defaults = {}, config = {}) => {
|
|
|
241
239
|
};
|
|
242
240
|
|
|
243
241
|
const removeConfigs = async (api, toRemove) => {
|
|
244
|
-
const
|
|
245
|
-
(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
242
|
+
const operations = Object.entries(toRemove).flatMap(([configName, keys]) =>
|
|
243
|
+
keys.map(async (key) => {
|
|
244
|
+
try {
|
|
245
|
+
await api.deleteConfig(configName, key);
|
|
246
|
+
log.success(
|
|
247
|
+
`Successfully removed ${chalk.bold(key)} from ${chalk.bold(configName)}`
|
|
248
|
+
);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
log.error(
|
|
251
|
+
`Failed to remove ${chalk.bold(key)} from ${chalk.bold(configName)}:`,
|
|
252
|
+
error
|
|
253
|
+
);
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
})
|
|
253
257
|
);
|
|
254
258
|
|
|
255
|
-
|
|
259
|
+
return Promise.all(operations);
|
|
256
260
|
};
|
|
257
261
|
|
|
258
262
|
const setConfigs = async (api, toSet) => {
|
|
259
|
-
const
|
|
263
|
+
const operations = Object.entries(toSet).flatMap(([configName, config]) =>
|
|
260
264
|
Object.entries(config).map(async ([key, value]) => {
|
|
261
265
|
try {
|
|
262
266
|
await api.setConfig(configName, key, value);
|
|
267
|
+
log.success(
|
|
268
|
+
`Successfully set ${chalk.bold(key)} in ${chalk.bold(configName)}`
|
|
269
|
+
);
|
|
263
270
|
} catch (error) {
|
|
264
|
-
log.error(
|
|
271
|
+
log.error(
|
|
272
|
+
`Failed to set ${chalk.bold(key)} in ${chalk.bold(configName)}:`,
|
|
273
|
+
error
|
|
274
|
+
);
|
|
275
|
+
throw error;
|
|
265
276
|
}
|
|
266
277
|
})
|
|
267
278
|
);
|
|
268
279
|
|
|
269
|
-
|
|
280
|
+
return Promise.all(operations);
|
|
270
281
|
};
|
|
271
282
|
|
|
272
283
|
module.exports = {
|
package/bin/utils/index.js
CHANGED
package/package.json
CHANGED
package/delivery/jenkinsfile
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env groovy
|
|
2
|
-
library 'jenkins-shared-library'
|
|
3
|
-
|
|
4
|
-
def productName = 'rollout-tool' // the name of the product to which this service belongs (jobboard/insights/employerbranding/core-services)
|
|
5
|
-
|
|
6
|
-
def (subProductName, branchName) = "${env.JOB_NAME}".tokenize( '/' )
|
|
7
|
-
def siteName = "$productName/$subProductName"
|
|
8
|
-
def repositoryUri = "426517516965.dkr.ecr.eu-west-1.amazonaws.com"
|
|
9
|
-
|
|
10
|
-
pipeline {
|
|
11
|
-
agent {
|
|
12
|
-
any {
|
|
13
|
-
customWorkspace "workspace/${env.JOB_NAME}/${branchName}".replace('%2F', '-')
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
options {
|
|
18
|
-
timeout(time: 1, unit: 'HOURS')
|
|
19
|
-
disableConcurrentBuilds()
|
|
20
|
-
skipStagesAfterUnstable()
|
|
21
|
-
skipDefaultCheckout()
|
|
22
|
-
buildDiscarder(logRotator(daysToKeepStr: '10', numToKeepStr: '3'))
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
environment {
|
|
26
|
-
NPM_TOKEN = credentials('MDS_NPM_TOKEN')
|
|
27
|
-
AWS_CREDENTIALS_ID = "${params.ENVIRONMENTS == 'jb.dev' ? 'rollout-tool-consumer-key-parameter-store-jb-dev' : 'rollout-tool-consumer-key-parameter-store-production'}"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
stages {
|
|
31
|
-
stage('SCM') {
|
|
32
|
-
steps {
|
|
33
|
-
notifySlack('STARTED', 'fed-services-builds', 'jenkins-slack-token')
|
|
34
|
-
checkout scm
|
|
35
|
-
notifyBitbucketWithState('INPROGRESS')
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
stage('Build') {
|
|
40
|
-
steps {
|
|
41
|
-
script {
|
|
42
|
-
withCredentials([
|
|
43
|
-
usernamePassword(credentialsId: 'github-lerna-write', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME'),
|
|
44
|
-
[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: "${env.AWS_CREDENTIALS_ID}"]
|
|
45
|
-
]){
|
|
46
|
-
|
|
47
|
-
docker.build("madgex/front-end-rollout-tool", "--no-cache --build-arg NPM_TOKEN=$env.NPM_TOKEN --build-arg GIT_USERNAME=$GIT_USERNAME --build-arg GIT_PASSWORD=$GIT_PASSWORD .")
|
|
48
|
-
|
|
49
|
-
sh """
|
|
50
|
-
docker run --rm -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY madgex/front-end-rollout-tool:latest npm run publish -- --environment=${params.ENVIRONMENTS} --clientPropertyId=${params.CLIENT_PROPERTY_ID}
|
|
51
|
-
|
|
52
|
-
"""
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
stage('Call branding service') {
|
|
58
|
-
steps {
|
|
59
|
-
script {
|
|
60
|
-
build job: 'madgex-branding-service', parameters: [
|
|
61
|
-
string(name: 'CLIENT_PROPERTY_ID', value: params.CLIENT_PROPERTY_ID),
|
|
62
|
-
string(name: 'DESIGN_SYSTEM_VERSION', value: params.DESIGN_SYSTEM_VERSION),
|
|
63
|
-
string(name: 'ENVIRONMENTS', value: params.ENVIRONMENTS),
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
post {
|
|
72
|
-
failure {
|
|
73
|
-
script {
|
|
74
|
-
notifyBitbucketWithState('FAILURE')
|
|
75
|
-
// This channel is only for failures
|
|
76
|
-
notifySlack(currentBuild.result, 'pipeline-alerts-fed', 'jenkins-slack-token')
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
success {
|
|
80
|
-
script {
|
|
81
|
-
notifyBitbucketWithState('SUCCESS')
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
always {
|
|
85
|
-
script {
|
|
86
|
-
// Necessary to get emailer to send out on success
|
|
87
|
-
currentBuild.result = currentBuild.currentResult
|
|
88
|
-
}
|
|
89
|
-
notifySlack(currentBuild.result, 'fed-services-builds', 'jenkins-slack-token')
|
|
90
|
-
cleanWs deleteDirs: true
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|