diff --git a/csccp.js b/csccp.js index 9249ef7..47b197d 100644 --- a/csccp.js +++ b/csccp.js @@ -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}`) }) diff --git a/deployTemplate.yaml b/deployTemplate.yaml new file mode 100644 index 0000000..0846a2c --- /dev/null +++ b/deployTemplate.yaml @@ -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: {}