Skip to content

Commit

Permalink
Merge pull request #583 from bcgov/2.0
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
ychung-mot authored Apr 13, 2021
2 parents 27ba0c2 + 3f0bf0f commit dfb3b8c
Show file tree
Hide file tree
Showing 26 changed files with 264 additions and 303 deletions.
82 changes: 51 additions & 31 deletions .jenkins/.pipeline/lib/build.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
'use strict';
const {OpenShiftClientX} = require('@bcgov/pipeline-cli')
const path = require('path');
"use strict";
const { OpenShiftClientX } = require("@bcgov/pipeline-cli");
const path = require("path");

module.exports = (settings)=>{
const phases=settings.phases
const options = settings.options
const oc=new OpenShiftClientX(Object.assign({'namespace':phases.build.namespace}, options));
const phase='build'
var objects = []
module.exports = (settings) => {
const phases = settings.phases;
const options = settings.options;
const oc = new OpenShiftClientX(
Object.assign({ namespace: phases.build.namespace }, options)
);
const phase = "build";
var objects = [];

const templatesLocalBaseUrl =oc.toFileUrl(path.resolve(__dirname, '../../openshift'))
const templatesLocalBaseUrl = oc.toFileUrl(
path.resolve(__dirname, "../../openshift")
);

objects.push(...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/build-master.yaml`, {
'param':{
'NAME': phases[phase].name,
'SUFFIX': phases[phase].suffix,
'VERSION': phases[phase].tag,
'SOURCE_REPOSITORY_URL': oc.git.http_url,
'SOURCE_REPOSITORY_REF': oc.git.ref
}
}));
objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/build-master.yaml`,
{
param: {
NAME: phases[phase].name,
SUFFIX: phases[phase].suffix,
VERSION: phases[phase].tag,
SOURCE_REPOSITORY_URL: oc.git.http_url,
SOURCE_REPOSITORY_REF: oc.git.ref,
},
}
)
);

objects.push(...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/build-slave.yaml`, {
'param':{
'NAME': phases[phase].name,
'SUFFIX': phases[phase].suffix,
'VERSION': phases[phase].tag,
'SOURCE_IMAGE_STREAM_TAG': `${phases[phase].name}:${phases[phase].tag}`,
'SLAVE_NAME':'main'
}
}));
objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/build-slave.yaml`,
{
param: {
NAME: phases[phase].name,
SUFFIX: phases[phase].suffix,
VERSION: phases[phase].tag,
SOURCE_IMAGE_STREAM_TAG: `${phases[phase].name}:${phases[phase].tag}`,
SLAVE_NAME: "main",
},
}
)
);

oc.applyRecommendedLabels(objects, phases[phase].name, phase, phases[phase].changeId, phases[phase].instance)
oc.applyAndBuild(objects)
}
oc.applyRecommendedLabels(
objects,
phases[phase].name,
phase,
phases[phase].changeId,
phases[phase].instance
);
oc.applyAndBuild(objects);
};
33 changes: 20 additions & 13 deletions .jenkins/.pipeline/lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ const getTargetPhases = (env, phases) => {
return target_phase;
};

module.exports = settings => {
module.exports = (settings) => {
const phases = settings.phases;
const options = settings.options;
const oc = new OpenShiftClientX(Object.assign({ namespace: phases.build.namespace }, options));
const oc = new OpenShiftClientX(
Object.assign({ namespace: phases.build.namespace }, options)
);
const target_phases = getTargetPhases(options.env, phases);

target_phases.forEach(k => {
target_phases.forEach((k) => {
if (phases.hasOwnProperty(k)) {
const phase = phases[k];

let buildConfigs = oc.get("bc", {
selector: `app=${phase.instance},env-id=${phase.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
namespace: phase.namespace,
});
buildConfigs.forEach(bc => {
buildConfigs.forEach((bc) => {
if (bc.spec.output.to.kind == "ImageStreamTag") {
oc.delete([`ImageStreamTag/${bc.spec.output.to.name}`], {
"ignore-not-found": "true",
Expand All @@ -43,17 +45,20 @@ module.exports = settings => {
selector: `app=${phase.instance},env-id=${phase.changeId},env-name=${k},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
namespace: phase.namespace,
});
deploymentConfigs.forEach(dc => {
dc.spec.triggers.forEach(trigger => {
deploymentConfigs.forEach((dc) => {
dc.spec.triggers.forEach((trigger) => {
if (
trigger.type == "ImageChange" &&
trigger.imageChangeParams.from.kind == "ImageStreamTag"
) {
oc.delete([`ImageStreamTag/${trigger.imageChangeParams.from.name}`], {
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
});
oc.delete(
[`ImageStreamTag/${trigger.imageChangeParams.from.name}`],
{
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
}
);
}
});
});
Expand All @@ -65,12 +70,14 @@ module.exports = settings => {
});
oc.raw(
"delete",
["pvc,Secret,configmap,endpoints,RoleBinding,role,ServiceAccount,Endpoints"],
[
"pvc,Secret,configmap,endpoints,RoleBinding,role,ServiceAccount,Endpoints",
],
{
selector: `app=${phase.instance},env-id=${phase.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
wait: "true",
namespace: phase.namespace,
},
}
);
}
});
Expand Down
6 changes: 3 additions & 3 deletions .jenkins/.pipeline/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const name = "jenkins";

const phases = {
build: {
namespace: "tran-schoolbus-tools",
namespace: "e82e9a-tools",
name: `${name}`,
phase: "build",
changeId: changeId,
Expand All @@ -16,7 +16,7 @@ const phases = {
tag: `build-${version}-${changeId}`,
},
dev: {
namespace: "tran-schoolbus-tools",
namespace: "e82e9a-tools",
name: `${name}`,
phase: "dev",
changeId: changeId,
Expand All @@ -26,7 +26,7 @@ const phases = {
tag: `dev-${version}-${changeId}`,
},
prod: {
namespace: "tran-schoolbus-tools",
namespace: "e82e9a-tools",
name: `${name}`,
phase: "prod",
changeId: changeId,
Expand Down
102 changes: 63 additions & 39 deletions .jenkins/.pipeline/lib/deploy.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
'use strict';
const {OpenShiftClientX} = require('@bcgov/pipeline-cli')
const path = require('path');
"use strict";
const { OpenShiftClientX } = require("@bcgov/pipeline-cli");
const path = require("path");

module.exports = (settings)=>{
const phases = settings.phases
const options = settings.options
const phase=options.env
const changeId = phases[phase].changeId
const oc=new OpenShiftClientX(Object.assign({'namespace':phases[phase].namespace}, options));
var objects = []
module.exports = (settings) => {
const phases = settings.phases;
const options = settings.options;
const phase = options.env;
const changeId = phases[phase].changeId;
const oc = new OpenShiftClientX(
Object.assign({ namespace: phases[phase].namespace }, options)
);
var objects = [];

const templatesLocalBaseUrl =oc.toFileUrl(path.resolve(__dirname, '../../openshift'))
const templatesLocalBaseUrl = oc.toFileUrl(
path.resolve(__dirname, "../../openshift")
);

objects.push(...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/deploy-master.yaml`, {
'param':{
'NAME': phases[phase].name,
'SUFFIX': phases[phase].suffix,
'VERSION': phases[phase].tag,
'ENV_NAME': phases[phase].phase,
'ROUTE_HOST': `${phases[phase].name}${phases[phase].suffix}-${phases[phase].namespace}.pathfinder.gov.bc.ca`
}
}))
objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/deploy-master.yaml`,
{
param: {
NAME: phases[phase].name,
SUFFIX: phases[phase].suffix,
VERSION: phases[phase].tag,
ENV_NAME: phases[phase].phase,
ROUTE_HOST: `${phases[phase].name}${phases[phase].suffix}-${phases[phase].namespace}.apps.silver.devops.gov.bc.ca`,
},
}
)
);

objects.push(...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/deploy-slave.yaml`, {
'param':{
'NAME': phases[phase].name,
'SUFFIX': phases[phase].suffix,
'VERSION': phases[phase].tag,
'SLAVE_NAME': 'build',
'SLAVE_LABELS': 'build deploy test ui-test',
'SLAVE_EXECUTORS': '3',
'CPU_REQUEST': '300m',
'CPU_LIMIT': '500m',
'MEMORY_REQUEST': '2Gi',
'MEMORY_LIMIT': '2Gi'
}
}))
objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/deploy-slave.yaml`,
{
param: {
NAME: phases[phase].name,
SUFFIX: phases[phase].suffix,
VERSION: phases[phase].tag,
SLAVE_NAME: "build",
SLAVE_LABELS: "build deploy test ui-test",
SLAVE_EXECUTORS: "3",
CPU_REQUEST: "300m",
CPU_LIMIT: "500m",
MEMORY_REQUEST: "2Gi",
MEMORY_LIMIT: "2Gi",
},
}
)
);

oc.applyRecommendedLabels(objects, phases[phase].name, phase, `${changeId}`, phases[phase].instance)
oc.importImageStreams(objects, phases[phase].tag, phases.build.namespace, phases.build.tag)
oc.applyAndDeploy(objects, phases[phase].instance)

}
oc.applyRecommendedLabels(
objects,
phases[phase].name,
phase,
`${changeId}`,
phases[phase].instance
);
oc.importImageStreams(
objects,
phases[phase].tag,
phases.build.namespace,
phases.build.tag
);
oc.applyAndDeploy(objects, phases[phase].instance);
};
4 changes: 2 additions & 2 deletions .jenkins/openshift/build-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ parameters:
value: v1.0.0
- name: SOURCE_IMAGE_STREAM_NAMESPACE
required: true
value: bcgov
value: e82e9a-tools
- name: SOURCE_IMAGE_STREAM_TAG
required: true
value: jenkins-basic:v2-latest
value: jenkins-basic:55
- name: SOURCE_REPOSITORY_URL
required: true
- name: SOURCE_REPOSITORY_REF
Expand Down
2 changes: 1 addition & 1 deletion .jenkins/openshift/deploy-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ objects:
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/lib/jenkins/jobs
- mountPath: /var/jenkins-data
name: jenkins-jobs
readOnly: false
- mountPath: /var/run/pod
Expand Down
10 changes: 5 additions & 5 deletions .pipeline/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ module.exports = (settings) => {

objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/pdf-build-config.yaml`,
`${templatesLocalBaseUrl}/client-build-config.yaml`,
{
param: {
PROJECT_NAME: `${phases[phase].name}`,
NAME: `${settings.phases[phase].name}-pdf`,
NAME: `${settings.phases[phase].name}-client`,
SUFFIX: settings.phases[phase].suffix,
VERSION: settings.phases[phase].tag,
SOURCE_REPOSITORY_URL: `${oc.git.uri}`,
Expand All @@ -61,10 +60,11 @@ module.exports = (settings) => {

objects.push(
...oc.processDeploymentTemplate(
`${templatesLocalBaseUrl}/client-build-config.yaml`,
`${templatesLocalBaseUrl}/pdf-build-config.yaml`,
{
param: {
NAME: `${settings.phases[phase].name}-client`,
PROJECT_NAME: `${phases[phase].name}`,
NAME: `${settings.phases[phase].name}-pdf`,
SUFFIX: settings.phases[phase].suffix,
VERSION: settings.phases[phase].tag,
SOURCE_REPOSITORY_URL: `${oc.git.uri}`,
Expand Down
Loading

0 comments on commit dfb3b8c

Please sign in to comment.