Added new system of generating yaml templates

This commit is contained in:
Shahan Nedadahandeh 2022-06-18 15:12:42 -04:00
parent d09fe277e3
commit 95d7c68256
2 changed files with 39 additions and 5 deletions

View File

@ -9,7 +9,7 @@ if(!process.env.authToken){
}
app.get('/cscclassprofilestaging', async (req, res) => {
console.log("Received build request", req);
console.log("Received build request");
const buildId = req.query.ref;
const name = `${buildId}-csc-class-profile-staging`
@ -17,7 +17,6 @@ app.get('/cscclassprofilestaging', async (req, res) => {
const image = `registry.cloud.csclub.uwaterloo.ca/snedadah/csc-class-profile-staging:${buildId}`
if (!req.headers.authorization) {
console.log("No auth!");
return res.status(403).json({ error: 'No credentials sent!' });
@ -30,14 +29,20 @@ app.get('/cscclassprofilestaging', async (req, res) => {
console.log("Doing deploy for for branch: " + req.query.ref);
// command for generating deplyoment template
//await call(`kubectl create deployment ${name} --image ${image} --port=80 -o yaml --dry-run > test.yaml`);
console.log(`${(new Date()).toUTCString()} - Doing deploy for for branch: ${req.query.ref}`);
// try deleting incase it already exists
await call(`kubectl delete deployment ${name}`);
await call(`kubectl create deployment ${name} --image ${image} --port=80`);
// replace variables in template with correct name and image
await call(`cat deployTemplate.yaml | sed "s@__NAME__@${name}@g" | sed "s@__IMAGE__@${image}@g" | kubectl apply -f -`);
await call(`kubectl expose deployment ${name}`);
await call(`kubectl create ingress ${name} --rule='${publicUrl}/*=${name}:80'`);
console.log("Deployed to " + publicUrl);
console.log("Deployed to " + publicUrl);
res.send(publicUrl);
})
@ -45,11 +50,13 @@ async function call(cmd){
let out
try{
out = await exec(cmd);
console.log(out)
}catch(e)
{
console.log(e, out)
}
}
app.listen(port, () => {
console.log(`Listening on port ${port}`)
})

27
deployTemplate.yaml Normal file
View File

@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: __NAME__
name: __NAME__
spec:
replicas: 1
selector:
matchLabels:
app: __NAME__
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: __NAME__
spec:
containers:
- image: __IMAGE__
name: csc-class-profile-staging
ports:
- containerPort: 80
resources: {}
imagePullPolicy: Always
status: {}