@sap/cds-dk
Version:
Command line client and development toolkit for the SAP Cloud Application Programming Model
64 lines (54 loc) • 1.8 kB
JavaScript
const cds = require('../../..')
const { rimraf, exists, readFileSync, yaml } = cds.utils
const { join } = require('path')
const { readProject } = require('../../projectReader')
const { merge } = require('../../merge')
module.exports = class HelmUnifiedRuntimeTemplate extends require('../helm') {
static help() {
return 'Kyma deployment using Unified Runtime Helm charts'
}
options() {
return {
'internal-unified-runtime-charts': {
type: 'boolean'
}
}
}
async canRun() {
const hasInProduction = HelmUnifiedRuntimeTemplate.hasInProduction()
if (cds.cli.options.force) {
await rimraf(join('chart'))
return true
} else if (exists(join(cds.root, 'chart')) && !hasInProduction) {
throw `Chart already exists. Use --force to overwrite.`
}
return true
}
static hasInProduction() {
if (cds.cli.options?.add?.has('helm-unified-runtime')) return true
if (exists(join(cds.root, 'chart', 'Chart.yaml'))) {
const chartFile = readFileSync(join(cds.root, 'chart', 'Chart.yaml'), 'utf8')
const chartYaml = yaml.parseDocument(chartFile).toJS()
return chartYaml.annotations?.['app.kubernetes.io/managed-by'] === 'cds-dk/helm'
&& chartYaml.dependencies?.find(dep => dep.name === 'web-application')?.repository !== undefined
}
return false
}
async _mergeDependency(name, alias) {
const project = readProject()
await merge({
dependencies: [{
name,
alias,
version: '>0.0.0',
repository: 'https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz'
}]
}).into('chart/Chart.yaml', {
with: project,
additions: [{
in: 'dependencies',
where: { alias }
}]}
)
}
}