csc-webhooks/csccp.js

36 lines
967 B
JavaScript

const exec = require('await-exec')
const express = require('express')
const app = express()
const port = 2344
app.get('/cscclassprofilestaging', async (req, res) => {
const buildId = req.query.ref;
const name = `${buildId}-cscclassprofilestaging`
const publicUrl = `${name}-snedadah.k8s.csclub.cloud`
const image = `registry.cloud.csclub.uwaterloo.ca/snedadah/csc-class-profile-staging:${buildId}`
console.log("branch is " + req.query.ref, req.query);
await call(`kubectl delete deployment ${name}`);
await call(`kubectl create deployment ${name} --image ${image} --port=80`);
await call(`kubectl expose deployment ${name}`);
await call(`kubectl create ingress ${name} --rule='${publicUrl}/*=${name}:80'`);
console.log("Deploying on " + publicUrl);
res.send(publicUrl);
})
async function call(cmd){
let out
try{
out = await exec(cmd);
}catch(e)
{
console.log(e, out)
}
}
app.listen(port, () => {
console.log(`Listening on port ${port}`)
})