Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
feat(build): add support for deployCmd option and copy over undeploy.…
Browse files Browse the repository at this point in the history
…json
  • Loading branch information
mikezaschka committed Nov 25, 2020
1 parent 4e46ec7 commit 5d0f2d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/build/postgres-cf/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import foss from '@sap/cds-foss'
const fs = foss('fs-extra')
import { chmodSync } from "fs"
import { chmodSync, existsSync } from 'fs'
import path from 'path'
const BuildTaskHandlerOData = require('@sap/cds/lib/build/buildTaskHandlerOData')
const { BuildMessage, BuildError } = require('@sap/cds/lib/build/util')
Expand All @@ -12,6 +12,7 @@ const FILE_NAME_MANIFEST_YML = 'manifest.yml'
const DEFAULT_COMPILE_DEST_FOLDER = path.normalize('src/gen')
const FILE_EXT_CSV = '.csv'
const FILE_NAME_PACKAGE_JSON = 'package.json'
const DEPLOY_CMD = 'npx cds-dbm deploy --load-via delta'

class PostgresCfModuleBuilder extends BuildTaskHandlerOData {
constructor(task, buildOptions) {
Expand All @@ -22,6 +23,8 @@ class PostgresCfModuleBuilder extends BuildTaskHandlerOData {
}

init() {
this.task.options.deployCmd = this.task.options.deployCmd || DEPLOY_CMD

this.task.options.compileDest = path.resolve(
this.task.dest,
this.task.options.compileDest || DEFAULT_COMPILE_DEST_FOLDER
Expand Down Expand Up @@ -56,9 +59,18 @@ class PostgresCfModuleBuilder extends BuildTaskHandlerOData {
const aptFile = path.join(__dirname, 'template', 'apt.yml')
await this.copy(aptFile).to(path.join(this.task.dest, 'apt.yml'))

const migrationOptions = cds.env['migrations']['db']
if (migrationOptions.deploy.undeployFile && existsSync(path.join(src, migrationOptions.deploy.undeployFile))) {
await this.copy(path.join(src, migrationOptions.deploy.undeployFile)).to(
path.join(this.task.dest, 'undeploy.json')
)
}

const deployFile = path.join(__dirname, 'template', 'deploy.sh')
await this.copy(deployFile).to(path.join(this.task.dest, 'deploy.sh'))
chmodSync(path.join(this.task.dest, 'deploy.sh'), "777")
const targetDeployFile = path.join(this.task.dest, 'deploy.sh')
await this.copy(deployFile).to(targetDeployFile)
fs.appendFileSync(targetDeployFile, this.task.options.deployCmd)
chmodSync(targetDeployFile, '777')
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/build/postgres-cf/template/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export PATH=$PATH:/home/vcap/deps/1/bin
mkdir -p /home/vcap/.postgresql
export POSTGRESQL_ROOT_CERT="/home/vcap/.postgresql/root.crt"
echo $VCAP_SERVICES | jq --raw-output '."postgresql-db"[0].credentials.sslrootcert' > $POSTGRESQL_ROOT_CERT
# env
npx cds-dbm deploy --load-via delta
# Execution cmd will be inserted in the next line
2 changes: 1 addition & 1 deletion src/build/postgres-cf/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"deploy": {
"tmpFile": "tmp/_autodeploy.json",
"undeployFile": "db/undeploy.json"
"undeployFile": "undeploy.json"
}
}
}
Expand Down

0 comments on commit 5d0f2d3

Please sign in to comment.