diff --git a/lib/add.js b/lib/add.js index 1ac3ae4..f23f478 100644 --- a/lib/add.js +++ b/lib/add.js @@ -22,6 +22,10 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin { type: 'boolean', help: 'To add the templates folder to the chart folder.' }, + 'with-ctz': { + type: 'string', + help: 'To add the modules from containerize YAML as workloads in the chart. For information on ctz tool, refer to https://www.npmjs.com/package/ctz' + }, 'with-mta': { type: 'string', //help: 'Path to the mta.yaml file.' @@ -65,7 +69,7 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin { else if (exists('chart')) { let isCAPOpChart = isCAPOperatorChart('chart') - if(isCAPOpChart && !exists('chart/templates') && cds.cli.options['with-templates']){ + if (isCAPOpChart && !exists('chart/templates') && cds.cli.options['with-templates']) { await copy(join(__dirname, '../files/chart/templates')).to('chart/templates') console.log("Added 'templates' folder to the 'chart' folder.") } @@ -91,7 +95,38 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin { if (!cds.cli.options['with-mta'] && cds.cli.options['with-mta-extensions']) throw new Error(`mta YAML not provided. Please pass the mta YAML via option '--with-mta'.`) - if (cds.cli.options['with-mta']) { + if (cds.cli.options['with-ctz']) { + if (!exists(cds.cli.options['with-ctz'])) throw new Error(cds.cli.options['with-ctz'] + ` file does not exists.`) + + const containerizeYaml = yaml.parse(await read(join(cds.root, 'containerize.yaml'))) + let updateWorkloadMap = new Map() + + for (let module of containerizeYaml['modules']) { + let workload = { + name: module.name, + consumedBTPServices: [] + } + + let imagePath = containerizeYaml.repository + "/" + module.name + ":" + containerizeYaml.tag + if (module?.["build-parameters"]?.buildpack?.path.includes("gen/mtx/sidecar")) { + workload.jobDefinition = { + type: null, + image: imagePath + } + } else { + workload.deploymentDefinition = { + type: null, + image: imagePath + } + } + updateWorkloadMap.set(module.name, workload) + } + + await this.updateValuesYaml(new Map([ + ['workloads', updateWorkloadMap] + ])) + + } else if (cds.cli.options['with-mta']) { const { hasMta } = project if (!hasMta) throw new Error(`mta is not added to this project. Run 'cds add mta'.`) @@ -120,41 +155,43 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin { const valuesYaml = yaml.parse(await read(join(cds.root, 'chart/values.yaml'))) if (hasDestination) { - const destinationYaml = yaml.parse(Mustache.render( await read(join(__dirname, '../files/destination.yaml.hbs')), project)) + const destinationYaml = yaml.parse(Mustache.render(await read(join(__dirname, '../files/destination.yaml.hbs')), project)) await cds.add.merge(destinationYaml).into(valuesYaml) } if (hasHtml5Repo) { - const html5RepoYaml = yaml.parse(Mustache.render( await read(join(__dirname, '../files/html5Repo.yaml.hbs')), project)) + const html5RepoYaml = yaml.parse(Mustache.render(await read(join(__dirname, '../files/html5Repo.yaml.hbs')), project)) await cds.add.merge(html5RepoYaml).into(valuesYaml) } if (hasXsuaa) { - const xsuaaaYaml = yaml.parse(Mustache.render( await read(join(__dirname, '../files/xsuaa.yaml.hbs')), project)) + const xsuaaaYaml = yaml.parse(Mustache.render(await read(join(__dirname, '../files/xsuaa.yaml.hbs')), project)) await cds.add.merge(xsuaaaYaml).into(valuesYaml) await cds.add.merge(__dirname, '../files/xs-security.json.hbs').into('xs-security.json', { project, - additions: [{ in: 'scopes', where: { name: '$XSAPPNAME.Callback' }}, - { in: 'scopes', where: { name: '$XSAPPNAME.mtcallback' }}] - }) + additions: [{ in: 'scopes', where: { name: '$XSAPPNAME.Callback' } }, + { in: 'scopes', where: { name: '$XSAPPNAME.mtcallback' } }] + }) } if (hasApprouter || exists('approuter')) { - const approuterYaml = yaml.parse(Mustache.render( await read(join(__dirname, '../files/approuter.yaml.hbs')), project)) + const approuterYaml = yaml.parse(Mustache.render(await read(join(__dirname, '../files/approuter.yaml.hbs')), project)) await cds.add.merge(approuterYaml).into(valuesYaml) } if (hasMultitenancy) { - const saasRegistryYaml = yaml.parse(Mustache.render( await read(join(__dirname, '../files/saas-registry.yaml.hbs')), project)) + const saasRegistryYaml = yaml.parse(Mustache.render(await read(join(__dirname, '../files/saas-registry.yaml.hbs')), project)) await cds.add.merge(saasRegistryYaml).into(valuesYaml) - const serviceManagerYaml = yaml.parse(Mustache.render( await read(join(__dirname, '../files/service-manager.yaml.hbs')), project)) + const serviceManagerYaml = yaml.parse(Mustache.render(await read(join(__dirname, '../files/service-manager.yaml.hbs')), project)) await cds.add.merge(serviceManagerYaml).into(valuesYaml) } - const workloadsYaml = yaml.parse(Mustache.render( await read(join(__dirname, '../files/workloads.yaml.hbs')), project)) - await cds.add.merge(workloadsYaml).into(valuesYaml) + if (!cds.cli.options['with-ctz']) { + const workloadsYaml = yaml.parse(Mustache.render(await read(join(__dirname, '../files/workloads.yaml.hbs')), project)) + await cds.add.merge(workloadsYaml).into(valuesYaml) + } await write(yaml.stringify(valuesYaml)).to(join(cds.root, 'chart/values.yaml')) }