Skip to content

Commit

Permalink
Tracking pull request to merge release-0.1.0 to main (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuanfandevops authored Dec 20, 2021
1 parent d056d39 commit fedcbb8
Show file tree
Hide file tree
Showing 281 changed files with 14,131 additions and 1,202 deletions.
21 changes: 14 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
__pycache__/
.coverage
.DS_Store
.env
.idea/
.minio.sys/
.pyc
.sql.gz
.vscode/
*.py[cod]
build/
db.sqlite3
django/.coverage
django/staticfiles/
django/venv/
node_modules/
public/
package-lock.json
public/static/
react/node_modules/
TEST-*xml
venv/

db.sqlite3
.coverage
frontend/coverage/
backend/minio/
.sql.gz
coverage/
minio/minio_files/cthub/
decoder.env
5 changes: 5 additions & 0 deletions .pipeline/build-metabase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const task = require('./lib/build-metabase.js')
const settings = require('./lib/config.js')

task(Object.assign(settings, { phase: 'build'}))
5 changes: 5 additions & 0 deletions .pipeline/build-patroni.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const task = require('./lib/build-patroni.js')
const settings = require('./lib/config.js')

task(Object.assign(settings, { phase: 'build'}))
5 changes: 5 additions & 0 deletions .pipeline/clean-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const settings = require('./lib/config.js')
const task = require('./lib/clean-tools.js')

task(Object.assign(settings, { phase: settings.options.env}));
5 changes: 5 additions & 0 deletions .pipeline/deploy-knp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const settings = require('./lib/config.js')
const task = require('./lib/deploy-knp.js')

task(Object.assign(settings, { phase: settings.options.env}));
5 changes: 5 additions & 0 deletions .pipeline/deploy-metabase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const settings = require('./lib/config.js')
const task = require('./lib/deploy-metabase.js')

task(Object.assign(settings, { phase: settings.options.env}));
5 changes: 5 additions & 0 deletions .pipeline/deploy-patroni.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const settings = require('./lib/config.js')
const task = require('./lib/deploy-patroni.js')

task(Object.assign(settings, { phase: settings.options.env}));
24 changes: 24 additions & 0 deletions .pipeline/lib/build-metabase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"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";
let objects = [];
const templatesLocalBaseUrl = oc.toFileUrl(path.resolve(__dirname, "../../openshift"));

// The building of your cool app goes here ▼▼▼
objects = objects.concat(oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/templates/metabase/metabase-bc.yaml`, {}));

oc.applyRecommendedLabels(
objects,
phases[phase].name,
phase,
phases[phase].changeId,
phases[phase].instance,
);
oc.applyAndBuild(objects);
};
24 changes: 24 additions & 0 deletions .pipeline/lib/build-patroni.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"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";
let objects = [];
const templatesLocalBaseUrl = oc.toFileUrl(path.resolve(__dirname, "../../openshift"));

// The building of your cool app goes here ▼▼▼
objects = objects.concat(oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/templates/patroni-2.1.1/templates/build.yaml`, {}));

oc.applyRecommendedLabels(
objects,
phases[phase].name,
phase,
phases[phase].changeId,
phases[phase].instance,
);
oc.applyAndBuild(objects);
};
64 changes: 64 additions & 0 deletions .pipeline/lib/clean-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use strict";
const { OpenShiftClientX } = require("@bcgov/pipeline-cli");

// The clean tasks should be based on the following five labels added by BCDK pipeline
// namespace: '30b186-tools',
// transient: true,
// name: 'cthub',
// phase: 'build',
// changeId: '46',
// suffix: '-build-46',
// instance: 'cthub-build-46',
// version: '1.0.0-46',
// tag: 'build-1.0.0-46',
// ocpName: 'apps.silver.devops'

const getTargetPhases = (env, phases) => {
let target_phase = [];
for (const phase in phases) {
if (env.match(/^(all|transient)$/) && phases[phase].transient) {
target_phase.push(phase);
} else if (env === phase) {
target_phase.push(phase);
break;
}
}

return target_phase;
};

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

target_phases.forEach(k => {
if (phases.hasOwnProperty(k)) {

const phase = phases[k];
oc.namespace(phase.namespace);

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 => {
if (bc.spec.output.to.kind == "ImageStreamTag") {
oc.delete([`ImageStreamTag/${bc.spec.output.to.name}`], {
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
});
}
oc.delete([`BuildConfig/${bc.metadata.name}`], {
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
});
});

}
});
};
110 changes: 41 additions & 69 deletions .pipeline/lib/clean.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
"use strict";
const { OpenShiftClientX } = require("@bcgov/pipeline-cli");
const KeyCloakClient = require('./keycloak');

// The clean tasks should be based on the following five labels added by BCDK pipeline
// app: cthub-dev-45
// template-hash: 5ee0ba9e32efa8ac4d0ed2b9923ea2be3ddda2f4
// github-owner: bcgov
// env-name: dev
// app.kubernetes.io/component: database
// app.kubernetes.io/managed-by: template
// app-name: cthub
// app.kubernetes.io/name: patroni
// env-id: '45'
// github-repo: cthub

const getTargetPhases = (env, phases) => {
let target_phase = [];
Expand All @@ -23,30 +34,13 @@ module.exports = settings => {
const target_phases = getTargetPhases(options.env, phases);

target_phases.forEach(k => {

//k is dve, test or prod
if (phases.hasOwnProperty(k)) {

const phase = phases[k];
oc.namespace(phase.namespace);

if(k === 'dev') {
const kc = new KeyCloakClient(settings, oc);
kc.removeUris();
}

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 => {
if (bc.spec.output.to.kind == "ImageStreamTag") {
oc.delete([`ImageStreamTag/${bc.spec.output.to.name}`], {
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
});
}
});

let deploymentConfigs = oc.get("dc", {
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,
Expand All @@ -64,52 +58,35 @@ module.exports = settings => {
});
}
});
oc.delete([`DeploymentConfig/${dc.metadata.name}`], {
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
});
});
oc.raw(
"delete",
["Secret,configmap,endpoints,RoleBinding,role,ServiceAccount,Endpoints,service,route"],
{
selector: `app=${phase.instance},env-id=${phase.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
wait: "true",
namespace: phase.namespace,
}
);

//get all statefulsets before they are deleted
const statefulsets = oc.get("statefulset", {
selector: `app=${phase.instance},env-id=${phase.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
namespace: phase.namespace,
});

oc.raw("delete", ["all"], {
selector: `app=${phase.instance},env-id=${phase.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
wait: "true",
namespace: phase.namespace,
});
oc.raw(
"delete",
["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,
},
);

//remove all the PVCs associated with each statefulset, after they get deleted by above delete all operation
statefulsets.forEach(statefulset => {
//delete PVCs mounted for statfulset
oc.raw("delete", ["pvc"], {
selector: `statefulset=${statefulset.metadata.name}`,
//delete StatefulSet
oc.delete([`StatefulSet/${statefulset.metadata.name}`], {
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
});
/***
//delete PVCs mounted in statfulset
let statefulsetPVCs = oc.get("pvc", {
selector: `statefulset=${statefulset.metadata.name}`,
namespace: phase.namespace,
});
statefulsetPVCs.forEach(statefulsetPVC => {
oc.delete([`pvc/${statefulsetPVC.metadata.name}`], {
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
});
})
****/
});
//delete configmaps create by patroni
let patroniConfigmaps = oc.get("configmap", {
selector: `app.kubernetes.io/name=patroni,cluster-name=${statefulset.metadata.name}`,
Expand All @@ -126,25 +103,20 @@ module.exports = settings => {
namespace: phase.namespace,
},
);
}
});
};
//delete PVCs mounted for statfulset
oc.raw("delete", ["pvc"], {
selector: `app=${phase.instance},statefulset=${statefulset.metadata.name},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
"ignore-not-found": "true",
wait: "true",
namespace: phase.namespace,
});

//remove all custom security policies create for specific pull request
//const nsps = oc.get("networksecuritypolicies", {
// selector: `app=${phase.name}${phase.suffix}`,
// namespace: phase.namespace,
//});
//nsps.forEach(nsp => {
// oc.delete([`networksecuritypolicy/${nsp.metadata.name}`], {
// "ignore-not-found": "true",
// wait: "true",
// namespace: phase.namespace,
// });
//});
});

//remove all PR's network policies
const knps = oc.get("networkpolicies", {
selector: `app=${phase.name}${phase.suffix}`,
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,
});
knps.forEach(knp => {
Expand Down
Loading

0 comments on commit fedcbb8

Please sign in to comment.