|
|
|
@ -3,20 +3,40 @@ const express = require('express') |
|
|
|
|
const app = express() |
|
|
|
|
const port = 2344 |
|
|
|
|
|
|
|
|
|
require('dotenv').config(); |
|
|
|
|
if(!process.env.authToken){ |
|
|
|
|
console.error("No Auth token set!! – fill out .env-example and rename to .env!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
app.get('/cscclassprofilestaging', async (req, res) => { |
|
|
|
|
console.log("Recieved build request", req); |
|
|
|
|
|
|
|
|
|
const buildId = req.query.ref; |
|
|
|
|
const name = `${buildId}-cscclassprofilestaging` |
|
|
|
|
const name = `${buildId}-csc-class-profile-staging` |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!req.headers.authorization) { |
|
|
|
|
console.log("No auth!"); |
|
|
|
|
return res.status(403).json({ error: 'No credentials sent!' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(req.headers.authorization != process.env.authToken){ |
|
|
|
|
console.log("Invalid auth!"); |
|
|
|
|
return res.status(401).json({error: 'Invalid Auth Token!'}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Doing deploy for for branch: " + req.query.ref); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
console.log("Deployed to " + publicUrl); |
|
|
|
|
|
|
|
|
|
res.send(publicUrl); |
|
|
|
|
}) |
|
|
|
|