cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Deploy CAP with PostgreSQL on SAP BTP in cloud foundry

yosra_hassad0
Explorer
3,977

Hi all,

I am trying to deploy CAP project with PostgreSQL unfortunately the deployment fails when trying to deploy the DB deployer with this following error :

 [APP/TASK/deploy_to_postgresql/0]  :TypeError: Cannot read properties of undefined (reading 'username') at getCredentialsForClient (/home/vcap/deps/0/node_modules/cds-dbm/dist/adapter/PostgresAdapter.js:13:28)

my mta.yaml

## Generated mta.yaml based on template version 0.4.0
## appName = devtoberfest
## language=nodejs; multiTenant=false
## approuter=
_schema-version: "3.1"
ID: devtoberfest
version: 1.0.0
description: "A simple CAP project."
parameters:
enable-parallel-deployments: true
build-parameters:
before-all:
- builder: custom
commands:
- npm install
- npx -p @sap/cds-dk cds build
modules:
# --------------------- SERVER MODULE ------------------------
- name: devtoberfest-srv
# ------------------------------------------------------------
type: nodejs
path: gen/srv
provides:
- name: srv-api # required by consumers of CAP services (e.g. approuter)
properties:
srv-url: ${default-url}
requires:
- name: devtoberfest-database
- name: devtoberfest-uaa
- name: devtoberfest-db-deployer
type: custom
path: gen/db
parameters:
buildpacks: [https://github.com/cloudfoundry/apt-buildpack#v0.2.2, nodejs_buildpack]
no-route: true
no-start: true
disk-quota: 2GB
memory: 512MB
tasks:
- name: deploy_to_postgresql
command: chmod 755 deploy.sh && ./deploy.sh
disk-quota: 2GB
memory: 512MB
requires:
- name: devtoberfest-database
resources:
- name: devtoberfest-database
parameters:
path: ./pg-options.json
service: postgresql-db
service-plan: trial
skip-service-updates:
parameters: true
type: org.cloudfoundry.managed-service
- name: devtoberfest-uaa
type: org.cloudfoundry.managed-service
parameters:
path: ./xs-security.json
service: xsuaa
service-name: devtoberfest-uaa
service-plan: application

package.json

{
"name": "postgres",
"version": "1.0.0",
"description": "A simple CAP project.",
"repository": "<Add your repository here>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@sap/cds": "^5",
"@sap/cds-dk": "^4.9.2",
"@sap/cds-odata-v2-adapter-proxy": "^1.8.4",
"cds-dbm": "^0.0.36",
"cds-pg": "^0.1.28",
"express": "^4",
"fs": "0.0.1-security",
"handlebars": "^4.7.7",
"hdb": "^0.18.3",
"nodemailer": "^4.0.1",
"passport": "^0.5.2",
"path": "^0.12.7"
},
"devDependencies": {
"sqlite3": "^5.0.2"
},
"scripts": {
"start": "cds run",
"start:docker": "docker-compose up"
},
"eslintConfig": {
"extends": "eslint:recommended",
"env": {
"es2020": true,
"node": true,
"jest": true,
"mocha": true
},
"globals": {
"SELECT": true,
"INSERT": true,
"UPDATE": true,
"DELETE": true,
"CREATE": true,
"DROP": true,
"CDL": true,
"CQL": true,
"CXL": true,
"cds": true
},
"rules": {
"no-console": "off",
"require-atomic-updates": "off"
}
},
"cds": {
"build": {
"tasks": [
{
"for": "node-cf",
"src": "srv"
},
{
"use": "cds-dbm/dist/build/postgres-cf",
"for": "postgres-cf",
"src": "db",
"options": {
"deployCmd": "npx cds-dbm deploy --load-via delta --auto-undeploy"
}
}
]
},
"requires": {
"db": {
"kind": "database"
},
"uaa": {
"kind": "xsuaa"
},
"database": {
"impl": "cds-pg",
"model": [
"srv"
]
}
},
"migrations": {
"db": {
"schema": {
"default": "public",
"clone": "_cdsdbm_clone",
"reference": "_cdsdbm_ref"
},
"deploy": {
"tmpFile": "tmp/_autodeploy.json",
"undeployFile": "db/undeploy.json"
}
}
}
}
}

PS: I attached the db deployer log.I am grateful if anyone can help me to fix it.

Regards,Yosra

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
SAP Mentor
SAP Mentor

Can you please check if the deployment of pg-beershop works? I've just tried in my trial account and have no issues.

yosra_hassad0
Explorer
0 Likes

Thanks Gregor for your help. It works now for me.

gregorw
SAP Mentor
SAP Mentor
0 Likes

Would be great if you share what you needed to correct.

yosra_hassad0
Explorer
0 Likes

Adding service-tags: - plain to the service devtoberfest-database solve the issue.

PS: I added the mta updated.

Answers (4)

Answers (4)

devangelgb
Explorer
0 Likes

Hi @yosra_hassad0

When I deploy my app to btp o locally Which return this error.

Can you help me.

Regards,

yagbdeveloper70

devangelgb
Explorer
0 Likes

Hi yosra_hassad0,

When i try to get some enteties. the app retuned this error. I don't understand, how to solve this.

Could you help me.

Regards,

yagbdeveloper70

SebastianEsch
Active Participant
0 Likes

Hi harshad47,

you can update your service instance in Cloud Foundry via the command-line:
cf update-service mydb -t "list, of, tags"

Kind regards,

Sebastian

hash47
Explorer
0 Likes

Hi gregorwolf and yosra_hassad0 ,

I am also facing the same issue. But in my case I am creating the database first manually using BTP cockpit. In mta.yaml I am just updating the database service.

resources:
# --------------------- DATABASE MODULE ----------------------  
  - name: xxx-xxxx-xxxxx-database
# ------------------------------------------------------------
    type: org.cloudfoundry.existing-service

Can you please help?

Kind Regards,

Harshad