Skip to content

Commit

Permalink
Switch to @cap-js/postgres for local development and Cloud Foundry de…
Browse files Browse the repository at this point in the history
…ployment (#376)

* update dependencies

* strip down configuration

* updated dependency

* working local with @cap-js/postgres

* working Cloud Foundry deployment
  • Loading branch information
gregorwolf authored Jul 8, 2023
1 parent a32f884 commit 9b1b690
Show file tree
Hide file tree
Showing 20 changed files with 2,728 additions and 11,747 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16
v18
45 changes: 4 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@ Before you start please install all required dependencies using:
npm ci
```

To run the example with a local PostgreSQL DB in docker create a `default-env.json` file with the following content:

```JSON
{
"VCAP_SERVICES": {
"postgres": [
{
"name": "pg-beershop-database",
"label": "postgres",
"tags": ["plain", "db", "relational", "database"],
"credentials": {
"host": "localhost",
"port": "5432",
"database": "beershop",
"user": "postgres",
"password": "postgres"
}
}
]
}
}
```

Start the PostgreSQL database and [Adminer](https://www.adminer.org/) using:

```
Expand All @@ -57,31 +34,17 @@ Now deploy the database schema using [cds-dbm](https://github.com/mikezaschka/cd
npm run deploy:pg
```

The deploy will not automatically load any data which is made available via local CSV files. We need to perform an additional step for that to happen.

In order to perform a full data load you can execute the command:

```
npm run deploy:pg:data:full
```

Later on you can perform delta data loads with the command:

```
npm run deploy:pg:data:delta
```

So perform an initial full data load with the above command. This action should upload 3 CSV files with data.
The deploy will automatically load any data which is made available via local CSV files.

Then open [http://localhost:8080/](http://localhost:8080/) and login by selecting System _PostgreSQL_, Server: _beershop-postgresql_, Username _postgres_ and Password _postgres_. The database _beershop_ should already exist as you've just deployed it and the tables should contain data. If you have issues with the deployment you can run the SQL commands via adminer. You find them in the file _beershop.sql_.
Then open [http://localhost:8080/](http://localhost:8080/) and login by selecting System _PostgreSQL_, Server: _beershop-postgresql_, Username _postgres_ and Password _postgres_. The database _postgres_ should already exist as you've just deployed it and the tables should contain data.

Now you can start the CAP application by using:

```
cds run
cds watch --profile pg
```

Then open <http://localhost:4004/beershop/Beers> in the browser and you should see an ODATA response with 11 beers:
Then open <http://localhost:4004/odata/v4/beershop/Beers> in the browser and you should see an ODATA response with 11 beers:

```JSON
{
Expand Down
2 changes: 1 addition & 1 deletion app/Beers-display/webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"ach": "CA-UI5-FE",
"dataSources": {
"mainService": {
"uri": "/beershop/",
"uri": "/odata/v4/beershop/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
Expand Down
2 changes: 1 addition & 1 deletion app/Breweries-manage/webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"ach": "CA-UI5-FE",
"dataSources": {
"mainService": {
"uri": "/beershop-admin/",
"uri": "/odata/v4/beershop-admin/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
Expand Down
2 changes: 1 addition & 1 deletion app/TypeChecksWithDraft-manage/webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"ach": "CA-UI5-FE",
"dataSources": {
"mainService": {
"uri": "/beershop-admin/",
"uri": "/odata/v4/beershop-admin/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
Expand Down
2 changes: 1 addition & 1 deletion app/beers-manage/webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"description": "{{appDescription}}",
"dataSources": {
"mainService": {
"uri": "/beershop-admin/",
"uri": "/odata/v4/beershop-admin/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
Expand Down
30 changes: 14 additions & 16 deletions app/breweries-manage-v2/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
## Application Details
| |
| ------------- |
|**Generation Date and Time**<br>Thu Jul 14 2022 13:12:16 GMT+0200 (Central European Summer Time)|
|**App Generator**<br>@sap/generator-fiori-elements|
|**App Generator Version**<br>1.6.3|
|**Generation Platform**<br>Visual Studio Code|
|**Floorplan Used**<br>List Report Object Page V2|
|**Service Type**<br>OData Url|
|**Service URL**<br>http://localhost:4004/v2/beershop-admin/

| |
| ------------------------------------------------------------------------------------------------ |
| **Generation Date and Time**<br>Thu Jul 14 2022 13:12:16 GMT+0200 (Central European Summer Time) |
| **App Generator**<br>@sap/generator-fiori-elements |
| **App Generator Version**<br>1.6.3 |
| **Generation Platform**<br>Visual Studio Code |
| **Floorplan Used**<br>List Report Object Page V2 |
| **Service Type**<br>OData Url |

|**Service URL**<br>http://localhost:4004/odata/v4/beershop-admin/
|**Module Name**<br>breweries-manage-v2|
|**Application Title**<br>Manage Breweries|
|**Namespace**<br>csw|
Expand All @@ -20,24 +22,20 @@

## breweries-manage-v2



### Starting the generated app

- This app has been generated using the SAP Fiori tools - App Generator, as part of the SAP Fiori tools suite. In order to launch the generated app, simply run the following from the generated app root folder:
- This app has been generated using the SAP Fiori tools - App Generator, as part of the SAP Fiori tools suite. In order to launch the generated app, simply run the following from the generated app root folder:

```
npm start
```

- It is also possible to run the application using mock data that reflects the OData Service URL supplied during application generation. In order to run the application with Mock Data, run the following from the generated app root folder:
- It is also possible to run the application using mock data that reflects the OData Service URL supplied during application generation. In order to run the application with Mock Data, run the following from the generated app root folder:

```
npm run start-mock
```

#### Pre-requisites:

1. Active NodeJS LTS (Long Term Support) version and associated supported NPM version. (See https://nodejs.org)


1. Active NodeJS LTS (Long Term Support) version and associated supported NPM version. (See https://nodejs.org)
22 changes: 18 additions & 4 deletions app/xs-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@
"service": "sap-approuter-userapi"
},
{
"source": "/beershop-admin/(.*)$",
"target": "/beershop-admin/$1",
"source": "/odata/v4/beershop-admin/(.*)$",
"target": "/odata/v4/beershop-admin/$1",
"authenticationType": "xsuaa",
"destination": "srv_api",
"csrfProtection": true
},
{
"source": "/beershop/(.*)$",
"target": "/beershop/$1",
"source": "/odata/v4/beershop/(.*)$",
"target": "/odata/v4/beershop/$1",
"authenticationType": "xsuaa",
"destination": "srv_api",
"csrfProtection": true
},
{
"source": "/odata/v2/beershop-admin/(.*)$",
"target": "/odata/v2/beershop-admin/$1",
"authenticationType": "xsuaa",
"destination": "srv_api",
"csrfProtection": true
},
{
"source": "/odata/v2/beershop/(.*)$",
"target": "/odata/v2/beershop/$1",
"authenticationType": "xsuaa",
"destination": "srv_api",
"csrfProtection": true
Expand Down
18 changes: 9 additions & 9 deletions mta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ build-parameters:
commands:
- npm install
- cds build --production
- ./pg-build.sh
# - mkdir -p gen/db-with-express
# - npm run copy:db:gen
# - npm run copy:db:template

modules:
# DB Deploy with combined apt and Node.JS buildpack
- name: pg-beershop-db-deployer-apt
type: custom
path: gen/db
- name: pg-beershop-db-deployer
type: nodejs
path: gen/pg
parameters:
buildpacks: [https://github.com/cloudfoundry/apt-buildpack#v0.2.10, nodejs_buildpack]
no-route: true
no-start: true
disk-quota: 3GB
memory: 512MB
disk-quota: 1GB
memory: 256MB
tasks:
- name: deploy-to-postgresql
command: ./deploy.sh
disk-quota: 3GB
memory: 512MB
command: npm start
disk-quota: 1GB
memory: 256MB
build-parameters:
ignore: ["node_modules/"]
requires:
Expand Down
Loading

0 comments on commit 9b1b690

Please sign in to comment.