Skip to content

[Misc] ctz intergration #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 50 additions & 13 deletions lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -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.")
}
Expand All @@ -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'.`)

Expand Down Expand Up @@ -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'))
}
Expand Down
Loading