Skip to content

Commit 28f5585

Browse files
committed
add simple Tag deployment route
1 parent 3efd690 commit 28f5585

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

src/kubero.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,4 +1194,18 @@ export class Kubero {
11941194
public getClusterIssuer() {
11951195
return this.config.clusterissuer;
11961196
}
1197+
1198+
public deployApp(pipelineName: string, phaseName: string, appName: string, tag: string) {
1199+
debug.debug('deploy App: '+appName+' in '+ pipelineName+' phase: '+phaseName);
1200+
1201+
const contextName = this.getContext(pipelineName, phaseName);
1202+
const namespace = pipelineName+'-'+phaseName;
1203+
1204+
if (contextName) {
1205+
this.kubectl.setCurrentContext(contextName);
1206+
this.kubectl.deployApp(namespace, appName, tag);
1207+
this._io.emit('updatedApps', "deplyment_started");
1208+
}
1209+
}
1210+
11971211
}

src/modules/kubectl.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { IPipeline, IKubectlPipeline, IKubectlPipelineList, IKubectlAppList, IKu
2828
import { App, KubectlApp } from './application';
2929
import { KubectlPipeline } from './pipeline';
3030
import { IAddon, IAddonMinimal } from './addons';
31+
import { version } from 'os';
3132

3233

3334
export class Kubectl {
@@ -909,4 +910,49 @@ export class Kubectl {
909910
}
910911
}
911912

913+
public async deployAppDisabled(namespace: string, app: string, tag: string): Promise<any> {
914+
915+
console.log("deploy app: " + app, ",namespace: " + namespace, ",tag: " + tag);
916+
}
917+
918+
public async deployApp(namespace: string, appName: string, tag: string) {
919+
920+
let deploymentName = appName+'-kuberoapp-web';
921+
console.log("deploy app: " + appName, ",namespace: " + namespace, ",tag: " + tag, ",deploymentName: " + deploymentName);
922+
923+
// format : https://jsonpatch.com/
924+
const patch = [
925+
{
926+
op: 'replace',
927+
path: '/spec/image/tag',
928+
value: tag,
929+
},
930+
];
931+
932+
const apiVersion = "v1alpha1"
933+
const group = "application.kubero.dev"
934+
const plural = "kuberoapps"
935+
936+
const options = { "headers": { "Content-type": 'application/json-patch+json' } };
937+
this.customObjectsApi.patchNamespacedCustomObject(
938+
group,
939+
apiVersion,
940+
namespace,
941+
plural,
942+
appName,
943+
patch,
944+
undefined,
945+
undefined,
946+
undefined,
947+
options
948+
).then(() => {
949+
debug.log(`Deployment ${deploymentName} in Pipeline ${namespace} updated`);
950+
}).catch(error => {
951+
if (error.body.message) {
952+
debug.log('ERROR: '+error.body.message);
953+
}
954+
debug.log('ERROR: '+error);
955+
});
956+
};
957+
912958
}

src/routes/apps.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,20 @@ Router.get('/apps', authMiddleware, async function (req: Request, res: Response)
317317
// #swagger.summary = 'Get a list of running apps'
318318
res.send(await req.app.locals.kubero.getAppStateList());
319319
});
320+
321+
// Used GET instead of POST to make it easier to use from the CLI
322+
// Not used in the UI yet
323+
Router.get('/cli/apps/:pipeline/:phase/:app/deploy/:tag', bearerMiddleware, async function (req: Request, res: Response) {
324+
// #swagger.tags = ['Apps']
325+
// #swagger.summary = 'Deploy a prebuilt app tag'
326+
/* #swagger.security = [{
327+
"bearerAuth": {
328+
"type": 'http',
329+
"scheme": 'bearer',
330+
"bearerFormat": 'JWT',
331+
}
332+
}] */
333+
334+
req.app.locals.kubero.deployApp(req.params.pipeline, req.params.phase, req.params.app, req.params.tag);
335+
res.send("deployed");
336+
});

swagger.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,63 @@
542542
}
543543
}
544544
},
545+
"/cli/apps/{pipeline}/{phase}/{app}/deploy/{tag}": {
546+
"get": {
547+
"tags": [
548+
"Apps"
549+
],
550+
"summary": "Deploy a prebuilt app tag",
551+
"description": "",
552+
"parameters": [
553+
{
554+
"name": "pipeline",
555+
"in": "path",
556+
"required": true,
557+
"schema": {
558+
"type": "string"
559+
}
560+
},
561+
{
562+
"name": "phase",
563+
"in": "path",
564+
"required": true,
565+
"schema": {
566+
"type": "string"
567+
}
568+
},
569+
{
570+
"name": "app",
571+
"in": "path",
572+
"required": true,
573+
"schema": {
574+
"type": "string"
575+
}
576+
},
577+
{
578+
"name": "tag",
579+
"in": "path",
580+
"required": true,
581+
"schema": {
582+
"type": "string"
583+
}
584+
}
585+
],
586+
"responses": {
587+
"200": {
588+
"description": "OK"
589+
}
590+
},
591+
"security": [
592+
{
593+
"bearerAuth": {
594+
"type": "http",
595+
"scheme": "bearer",
596+
"bearerFormat": "JWT"
597+
}
598+
}
599+
]
600+
}
601+
},
545602
"/auth/github": {
546603
"get": {
547604
"tags": [

0 commit comments

Comments
 (0)