Skip to content

Commit 7ea372a

Browse files
authored
Merge pull request #414 from bcgov/1.4
Version 2.0
2 parents f71009d + 1d8f165 commit 7ea372a

823 files changed

Lines changed: 68525 additions & 111922 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
/.vscode/launch.json
3+
/debug.log

.jenkins/.pipeline/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v10.15.2

.jenkins/.pipeline/build.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const task = require('./lib/build.js')
3+
const settings = require('./lib/config.js')
4+
5+
task(Object.assign(settings, { phase: 'build'}))

.jenkins/.pipeline/clean.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const settings = require('./lib/config.js')
3+
const task = require('./lib/clean.js')
4+
5+
task(Object.assign(settings, { phase: settings.options.env}));

.jenkins/.pipeline/deploy.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
const settings = require('./lib/config.js')
3+
const task = require('./lib/deploy.js')
4+
5+
task(Object.assign(settings, { phase: settings.options.env}));

.jenkins/.pipeline/lib/build.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
const {OpenShiftClientX} = require('@bcgov/pipeline-cli')
3+
const path = require('path');
4+
5+
module.exports = (settings)=>{
6+
const phases=settings.phases
7+
const options = settings.options
8+
const oc=new OpenShiftClientX(Object.assign({'namespace':phases.build.namespace}, options));
9+
const phase='build'
10+
var objects = []
11+
12+
const templatesLocalBaseUrl =oc.toFileUrl(path.resolve(__dirname, '../../openshift'))
13+
14+
objects.push(...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/build-master.yaml`, {
15+
'param':{
16+
'NAME': phases[phase].name,
17+
'SUFFIX': phases[phase].suffix,
18+
'VERSION': phases[phase].tag,
19+
'SOURCE_REPOSITORY_URL': oc.git.http_url,
20+
'SOURCE_REPOSITORY_REF': oc.git.ref
21+
}
22+
}));
23+
24+
objects.push(...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/build-slave.yaml`, {
25+
'param':{
26+
'NAME': phases[phase].name,
27+
'SUFFIX': phases[phase].suffix,
28+
'VERSION': phases[phase].tag,
29+
'SOURCE_IMAGE_STREAM_TAG': `${phases[phase].name}:${phases[phase].tag}`,
30+
'SLAVE_NAME':'main'
31+
}
32+
}));
33+
34+
oc.applyRecommendedLabels(objects, phases[phase].name, phase, phases[phase].changeId, phases[phase].instance)
35+
oc.applyAndBuild(objects)
36+
}

.jenkins/.pipeline/lib/clean.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"use strict";
2+
const { OpenShiftClientX } = require("@bcgov/pipeline-cli");
3+
4+
const getTargetPhases = (env, phases) => {
5+
let target_phase = [];
6+
for (const phase in phases) {
7+
if (env.match(/^(all|transient)$/) && phases[phase].transient) {
8+
target_phase.push(phase);
9+
} else if (env === phase) {
10+
target_phase.push(phase);
11+
break;
12+
}
13+
}
14+
15+
return target_phase;
16+
};
17+
18+
module.exports = settings => {
19+
const phases = settings.phases;
20+
const options = settings.options;
21+
const oc = new OpenShiftClientX(Object.assign({ namespace: phases.build.namespace }, options));
22+
const target_phases = getTargetPhases(options.env, phases);
23+
24+
target_phases.forEach(k => {
25+
if (phases.hasOwnProperty(k)) {
26+
const phase = phases[k];
27+
28+
let buildConfigs = oc.get("bc", {
29+
selector: `app=${phase.instance},env-id=${phase.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
30+
namespace: phase.namespace,
31+
});
32+
buildConfigs.forEach(bc => {
33+
if (bc.spec.output.to.kind == "ImageStreamTag") {
34+
oc.delete([`ImageStreamTag/${bc.spec.output.to.name}`], {
35+
"ignore-not-found": "true",
36+
wait: "true",
37+
namespace: phase.namespace,
38+
});
39+
}
40+
});
41+
42+
let deploymentConfigs = oc.get("dc", {
43+
selector: `app=${phase.instance},env-id=${phase.changeId},env-name=${k},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
44+
namespace: phase.namespace,
45+
});
46+
deploymentConfigs.forEach(dc => {
47+
dc.spec.triggers.forEach(trigger => {
48+
if (
49+
trigger.type == "ImageChange" &&
50+
trigger.imageChangeParams.from.kind == "ImageStreamTag"
51+
) {
52+
oc.delete([`ImageStreamTag/${trigger.imageChangeParams.from.name}`], {
53+
"ignore-not-found": "true",
54+
wait: "true",
55+
namespace: phase.namespace,
56+
});
57+
}
58+
});
59+
});
60+
61+
oc.raw("delete", ["all"], {
62+
selector: `app=${phase.instance},env-id=${phase.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
63+
wait: "true",
64+
namespace: phase.namespace,
65+
});
66+
oc.raw(
67+
"delete",
68+
["pvc,Secret,configmap,endpoints,RoleBinding,role,ServiceAccount,Endpoints"],
69+
{
70+
selector: `app=${phase.instance},env-id=${phase.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
71+
wait: "true",
72+
namespace: phase.namespace,
73+
},
74+
);
75+
}
76+
});
77+
};

.jenkins/.pipeline/lib/config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"use strict";
2+
const options = require("@bcgov/pipeline-cli").Util.parseArguments();
3+
const changeId = options.pr; //aka pull-request
4+
const version = "1.0.0";
5+
const name = "jenkins";
6+
7+
const phases = {
8+
build: {
9+
namespace: "tran-schoolbus-tools",
10+
name: `${name}`,
11+
phase: "build",
12+
changeId: changeId,
13+
suffix: `-build-${changeId}`,
14+
instance: `${name}-build-${changeId}`,
15+
version: `${version}-${changeId}`,
16+
tag: `build-${version}-${changeId}`,
17+
},
18+
dev: {
19+
namespace: "tran-schoolbus-tools",
20+
name: `${name}`,
21+
phase: "dev",
22+
changeId: changeId,
23+
suffix: `-dev-${changeId}`,
24+
instance: `${name}-dev-${changeId}`,
25+
version: `${version}-${changeId}`,
26+
tag: `dev-${version}-${changeId}`,
27+
},
28+
prod: {
29+
namespace: "tran-schoolbus-tools",
30+
name: `${name}`,
31+
phase: "prod",
32+
changeId: changeId,
33+
suffix: `-prod`,
34+
instance: `${name}-prod`,
35+
version: `${version}`,
36+
tag: `prod-${version}`,
37+
},
38+
};
39+
40+
// This callback forces the node process to exit as failure.
41+
process.on("unhandledRejection", (reason) => {
42+
console.log(reason);
43+
process.exit(1);
44+
});
45+
46+
module.exports = exports = { phases, options };

.jenkins/.pipeline/lib/deploy.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
const {OpenShiftClientX} = require('@bcgov/pipeline-cli')
3+
const path = require('path');
4+
5+
module.exports = (settings)=>{
6+
const phases = settings.phases
7+
const options = settings.options
8+
const phase=options.env
9+
const changeId = phases[phase].changeId
10+
const oc=new OpenShiftClientX(Object.assign({'namespace':phases[phase].namespace}, options));
11+
var objects = []
12+
13+
const templatesLocalBaseUrl =oc.toFileUrl(path.resolve(__dirname, '../../openshift'))
14+
15+
objects.push(...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/deploy-master.yaml`, {
16+
'param':{
17+
'NAME': phases[phase].name,
18+
'SUFFIX': phases[phase].suffix,
19+
'VERSION': phases[phase].tag,
20+
'ENV_NAME': phases[phase].phase,
21+
'ROUTE_HOST': `${phases[phase].name}${phases[phase].suffix}-${phases[phase].namespace}.pathfinder.gov.bc.ca`
22+
}
23+
}))
24+
25+
objects.push(...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/deploy-slave.yaml`, {
26+
'param':{
27+
'NAME': phases[phase].name,
28+
'SUFFIX': phases[phase].suffix,
29+
'VERSION': phases[phase].tag,
30+
'SLAVE_NAME': 'build',
31+
'SLAVE_LABELS': 'build deploy test ui-test',
32+
'SLAVE_EXECUTORS': '3',
33+
'CPU_REQUEST': '300m',
34+
'CPU_LIMIT': '500m',
35+
'MEMORY_REQUEST': '2Gi',
36+
'MEMORY_LIMIT': '2Gi'
37+
}
38+
}))
39+
40+
oc.applyRecommendedLabels(objects, phases[phase].name, phase, `${changeId}`, phases[phase].instance)
41+
oc.importImageStreams(objects, phases[phase].tag, phases.build.namespace, phases.build.tag)
42+
oc.applyAndDeploy(objects, phases[phase].instance)
43+
44+
}

.jenkins/.pipeline/npmw

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
set +x
3+
type -t nvm && nvm deactivate
4+
export NVM_DIR="$(git rev-parse --show-toplevel)/.nvm"
5+
if [ ! -f "$NVM_DIR/nvm.sh" ]; then
6+
mkdir -p "${NVM_DIR}"
7+
curl -sSL -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash &>/dev/null
8+
fi
9+
source "$NVM_DIR/nvm.sh" &>/dev/null
10+
METHOD=script nvm install --no-progress &>/dev/null
11+
nvm use &>/dev/null
12+
exec npm "$@"

0 commit comments

Comments
 (0)