Skip to content

Commit e608c89

Browse files
authored
Merge pull request #481 from kubero-dev/feature/frontend-single-file-templates
Feature / Use singlefile templates
2 parents ff46b7a + 9730dd4 commit e608c89

File tree

7 files changed

+26
-78
lines changed

7 files changed

+26
-78
lines changed

client/src/components/apps/form.vue

+4-5
Original file line numberDiff line numberDiff line change
@@ -1653,10 +1653,9 @@ export default defineComponent({
16531653
this.loadClusterIssuers();
16541654
this.getDomains();
16551655
1656-
if (this.$route.query.template && this.$route.query.catalogId) {
1657-
const catalogId = this.$route.query.catalogId as string;
1656+
if (this.$route.query.template) {
16581657
const template = this.$route.query.template as string;
1659-
this.loadTemplate(catalogId, template);
1658+
this.loadTemplate(template);
16601659
}
16611660
16621661
//this.buildPipeline = this.$vuetify.buildPipeline
@@ -1709,8 +1708,8 @@ export default defineComponent({
17091708
this.letsecryptClusterIssuer = response.data.id;
17101709
});
17111710
},
1712-
loadTemplate(catalogId: string, template: string) {
1713-
axios.get('/api/templates/'+catalogId+'/'+template).then(response => {
1711+
loadTemplate(template: string) {
1712+
axios.get('/api/templates/'+template).then(response => {
17141713
17151714
this.appname = response.data.name;
17161715
this.containerPort = response.data.image.containerPort;

client/src/components/settings/form-templates.vue

+9-17
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343
<v-row>
4444
<v-col
4545
cols="12"
46-
md="10"
46+
md="6"
4747
>
48-
<v-text-field
49-
v-model="catalog.templateBasePath"
50-
label="Template Base Path"
48+
<v-select
49+
v-model="catalog.index.format"
50+
:items="['json']"
51+
label="Index Format"
5152
required
52-
density="compact"
53-
></v-text-field>
53+
></v-select>
5454
</v-col>
5555
</v-row>
56-
<v-row>
56+
<v-row justify="space-between">
5757
<v-col
5858
cols="12"
5959
md="10"
@@ -67,19 +67,12 @@
6767
</v-col>
6868
</v-row>
6969
<v-row justify="space-between">
70+
7071
<v-col
7172
cols="12"
72-
md="6"
73+
md="10"
7374
>
74-
<v-select
75-
v-model="catalog.index.format"
76-
:items="['json']"
77-
label="Index Format"
78-
required
79-
></v-select>
8075
</v-col>
81-
82-
8376
<v-col
8477
cols="12"
8578
md="2"
@@ -156,7 +149,6 @@ export default defineComponent({
156149
this.settings.kubero.config.templates.catalogs.push({
157150
name: '',
158151
description: '',
159-
templateBasePath: '',
160152
index: {
161153
url: '',
162154
format: 'json'

client/src/components/templates/index.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
color="primary"
110110
dark
111111
:disabled="!pipeline || !phase"
112-
@click="openInstall(clickedTemplate.dirname, pipeline, phase, catalogId)"
112+
@click="openInstall(clickedTemplate.template, pipeline, phase)"
113113
>
114114
Load template
115115
</v-btn>
@@ -153,6 +153,7 @@ type Template = {
153153
website: string,
154154
screenshots: string[],
155155
dirname: string,
156+
template: string,
156157
}
157158
158159
type Templates = {
@@ -209,9 +210,10 @@ export default defineComponent({
209210
}
210211
this.dialog = false;
211212
},
212-
openInstall(templatename: string, pipeline: string, phase: string, catalogId: number) {
213+
openInstall(templateurl: string, pipeline: string, phase: string) {
213214
// redirect to install page
214-
this.$router.push({ name: 'App Form', params: { pipeline: pipeline, phase: phase, app: 'new'}, query: { template: templatename, catalogId: catalogId }})
215+
const templateurlB64 = btoa(templateurl);
216+
this.$router.push({ name: 'App Form', params: { pipeline: pipeline, phase: phase, app: 'new'}, query: { template: templateurlB64 }})
215217
216218
},
217219
openInstallDialog(template: Template) {

server/src/kubero.ts

-5
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,6 @@ export class Kubero {
858858
{
859859
name: 'Kubero',
860860
description: 'Kubero Templates',
861-
templateBasePath: 'https://raw.githubusercontent.com/kubero-dev/kubero/main/services/',
862861
index: {
863862
url: 'https://raw.githubusercontent.com/kubero-dev/templates/main/index.json',
864863
format: 'json',
@@ -1458,10 +1457,6 @@ export class Kubero {
14581457
return this.config.templates;
14591458
}
14601459

1461-
public async getTemplateBasePath(catalogId: number) {
1462-
return this.config.templates.catalogs[catalogId].templateBasePath;
1463-
}
1464-
14651460
public getTemplateEnabled() {
14661461
return this.config.templates.enabled;
14671462
}

server/src/modules/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class KuberoConfig {
9494
{
9595
name: string;
9696
description: string;
97-
templateBasePath: string;
97+
templateBasePath?: string; // deprecated v2.4.4
9898
index: {
9999
url: string;
100100
format: string;

server/src/routes/templates.ts

+6-46
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,18 @@ export const auth = new Auth();
88
auth.init();
99
export const authMiddleware = auth.getAuthMiddleware();
1010
export const bearerMiddleware = auth.getBearerMiddleware();
11-
/*
12-
// load all services from github repo
13-
Router.get('/services', authMiddleware, async function (req: Request, res: Response) {
14-
// #swagger.tags = ['UI']
15-
// #swagger.summary = 'Get all services'
16-
17-
axios.get('https://raw.githubusercontent.com/kubero-dev/kubero/main/services/index.yaml')
18-
});
19-
20-
21-
// load a specific service from github repo
22-
Router.get('/services/:name', authMiddleware, async function (req: Request, res: Response) {
23-
// #swagger.tags = ['UI']
24-
// #swagger.summary = 'Get a specific service'
25-
// #deprecated = true // since v1.11.0
26-
27-
const serviceName = req.params.name.replace(/[^\w.-]+/g, '');
28-
29-
const service = await axios.get('https://raw.githubusercontent.com/kubero-dev/kubero/main/services/' + serviceName + '/app.yaml')
30-
.catch((err) => {
31-
res
32-
.status(500)
33-
.send(err);
34-
});
35-
if (service) {
36-
const ret = YAML.parse(service.data);
37-
res.send(ret.spec);
38-
}
39-
});
40-
*/
4111

4212
// load a specific service from github repo
43-
Router.get('/templates/:catalogId/:template', authMiddleware, async function (req: Request, res: Response) {
13+
Router.get('/templates/:template', authMiddleware, async function (req: Request, res: Response) {
4414
// #swagger.tags = ['UI']
4515
// #swagger.summary = 'Get a specific template'
16+
// #swagger.description = 'Get a specific template from a catalog'
17+
// #swagger.parameters['template'] = { description: 'A base64 encoded URL', type: 'string' }
4618

47-
const templateName = req.params.template.replace(/[^\w.-]+/g, '');
48-
const templateBasePath = await req.app.locals.kubero.getTemplateBasePath(parseInt(req.params.catalogId));
19+
// decode the base64 encoded URL
20+
const templateUrl = Buffer.from(req.params.template, 'base64').toString('ascii');
4921

50-
const template = await axios.get(templateBasePath + templateName + '/app.yaml')
22+
const template = await axios.get(templateUrl)
5123
.catch((err) => {
5224
res
5325
.status(500)
@@ -58,15 +30,3 @@ Router.get('/templates/:catalogId/:template', authMiddleware, async function (re
5830
res.send(ret.spec);
5931
}
6032
});
61-
62-
// load a specific service from github repo
63-
Router.get('/templates/:catalogId', authMiddleware, async function (req: Request, res: Response) {
64-
// #swagger.tags = ['UI']
65-
// #swagger.summary = 'Get a specific template'
66-
67-
const templateBasePath = await req.app.locals.kubero.getTemplateBasePath(parseInt(req.params.catalogId));
68-
69-
70-
axios.get(templateBasePath + '/index.yaml')
71-
});
72-

server/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export interface IKuberoConfig {
384384
{
385385
name: string;
386386
description: string;
387-
templateBasePath: string;
387+
templateBasePath?: string; // deprecated v2.4.4
388388
index: {
389389
url: string;
390390
format: string;

0 commit comments

Comments
 (0)