Skip to content
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

Unified runtime #197

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
236 changes: 84 additions & 152 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,106 +260,33 @@ Before you can access the UI using the (tenant-specific) URL to the bookshop(-mt
- Logged into Kyma Runtime (with `kubectl` CLI), Cloud Foundry space (with `cf` CLI) and Container Registry (with `docker login`)
- `@sap/cds-dk` >= 6.6.0

### Add Deployment Files

CAP tooling provides you a Helm chart for deployment to Kyma.

For single tenant deployment, replace the `requires` section in _`.cdsrc.json`_ with:

```
"requires": {
"auth": {
"kind": "xsuaa"
},
"approuter": {
"kind": "cloudfoundry"
},
"db": {
"kind": "hana-cloud"
}
},
```

**In addition** remove `"profile": "with-mtx-sidecar"` from `.cdsrc.json` and delete the `mtx` folder in root.

For multi tenant deployment, replace the `requires` section in _`.cdsrc.json`_ with:

```
"requires": {
"multitenancy": true,
"extensibility": true,
"toggles": true,
"auth": {
"kind": "xsuaa"
},
"approuter": {
"kind": "cloudfoundry"
}
},
```

Add the CAP Helm chart with the required features to this project:

```bash
cds add helm
```

#### Use API_BUSSINESS_PARTNER Remote Service (optional, single tenant only)

You can try the `API_BUSINESS_PARTNER` service with a real S/4HANA system with the following configuration:

1. Create either an on-premise or cloud destination in your subaccount.

2. Add configuration required for the destination service by executing the following command.

```bash
cds add destination
```

3. Set the profiles `cloud` and `destination` active in your `values.yaml` file:

```yaml
srv:
...
env:
SPRING_PROFILES_ACTIVE: cloud,destination
```

4. For on-premise only: Add the connectivity service to your Helm chart:

```bash
cds add connectivity
```

Note: `cds add helm` will not add configuration required to create a Connectivity Service Instance. This Service Instance should be created by the Kyma Cluster Administrator. For more information regarding configuration of Connectivity Instance, please check the [documentation](https://cap.cloud.sap/docs/guides/deployment/deploy-to-kyma#connectivity-service).

*See also: [API_BUSINESS_PARTNER Remote Service and Spring Profiles](#api_business_partner-remote-service-and-spring-profiles)*

### Prepare Kubernetes Namespace

#### Create container registry secret

Create a secret `container-registry` with credentials to access the container registry:
Create a secret `image-pull-secret` with credentials to access the container registry:

```
bash ./scripts/create-container-registry-secret.sh
```

The *Docker Server* is the full qualified hostname of your container registry.

#### Create a HDI container / Service Manager Instance and a Secret
#### Create a HDI container / Service Manager Instance and a Secret (optional)

This step is only required if you're using a BTP Trial account. If you're using a production or a free tier account then you can create HDI Container from Kyma directly by adding a [mapping to your Kyma namespace in your HANA Cloud Instance](https://blogs.sap.com/2022/12/15/consuming-sap-hana-cloud-from-the-kyma-environment/) and skip this step.
**Only required if you're using a BTP Trial account**.

If you're using a production or a free tier account you can create HDI Container from Kyma directly by adding a [mapping to your Kyma namespace in your HANA Cloud Instance](https://blogs.sap.com/2022/12/15/consuming-sap-hana-cloud-from-the-kyma-environment/). Then **skip this step and continue with [Build](#build)**.

##### Single Tenant

```
bash ./scripts/create-db-secret.sh bookshop-db
bash ./scripts/create-db-secret.sh bookshop-hdi
```

It will create a HDI container `bookshop-db` instance on your currently targeted Cloud Foundry space and a secret `bookshop-db` with the credentials in your current Kubernetes namespace.
It will create a HDI container `bookshop-hdi` instance on your currently targeted Cloud Foundry space and a secret `bookshop-hdi` with the credentials in your current Kubernetes namespace.

Make the following changes to your _`chart/values.yaml`_.
Make the following changes to your _`helm/single-tenant/values.yaml`_.

```diff
srv:
Expand All @@ -369,26 +296,27 @@ srv:
+ fromSecret: bookshop-db
...

hana-deployer:
hdi-deployer:
bindings:
hana:
- serviceInstanceName: hana
bookshop-hdi:
- serviceInstanceName: bookshop-hdi
+ fromSecret: bookshop-db

...
- hana:
- bookshop-hdi:
- serviceOfferingName: hana
- servicePlanName: hdi-shared
```

Make the following changes to your _`chart/Chart.yaml`_.
Make the following changes to your _`helm/single-tenant/Chart.yaml`_.

```diff
dependencies:
...
- - name: service-instance
- alias: hana
- repository: https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz/
- version: ">0.0.0"
- alias: bookshop-hdi
...
```

Expand All @@ -400,7 +328,7 @@ bash ./scripts/create-sm-secret.sh bookshop-sm

It will create a Service Manager `bookshop-sm` instance on your currently targeted Cloud Foundry space and a secret `bookshop-sm` with the credentials in your current Kubernetes namespace.

Make the following changes to your _`chart/values.yaml`_.
Make the following changes to your _`helm/multi-tenant/values.yaml`_.

```diff
srv:
Expand All @@ -422,14 +350,15 @@ sidecar:
- servicePlanName: container
```

Make the following changes to your _`chart/Chart.yaml`_.
Make the following changes to your _`helm/multi-tenant/Chart.yaml`_.

```diff
dependencies:
...
- - name: service-instance
- alias: service-manager
- repository: https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz/
- version: ">0.0.0"
- alias: service-manager
...
```

Expand All @@ -439,7 +368,7 @@ dependencies:
cds build --production
```

**Build image for CAP service:**
**Build & publish container images for CAP service:**

```bash
mvn clean package -DskipTests=true
Expand All @@ -450,116 +379,119 @@ pack build $YOUR_CONTAINER_REGISTRY/bookshop-srv \
--path srv/target/*-exec.jar \
--buildpack gcr.io/paketo-buildpacks/sap-machine \
--buildpack gcr.io/paketo-buildpacks/java \
--builder paketobuildpacks/builder-jammy-base \
--builder paketobuildpacks/builder:base \
--env SPRING_PROFILES_ACTIVE=cloud \
--env BP_JVM_VERSION=17
--env BP_JVM_VERSION=17 \
--publish
```

(Replace `$YOUR_CONTAINER_REGISTRY` with the full-qualified hostname of your container registry)

**Build Approuter Image:**
**Build & publish Approuter Image:**

```bash
pack build $YOUR_CONTAINER_REGISTRY/bookshop-approuter \
--path app \
--buildpack gcr.io/paketo-buildpacks/nodejs \
--builder paketobuildpacks/builder-jammy-base \
--env BP_NODE_RUN_SCRIPTS=""
--builder paketobuildpacks/builder:base \
--env BP_NODE_RUN_SCRIPTS="" \
--publish
```

**Build database deployer image (single tenant only):**
**Build & publish database deployer image (single tenant only):**

```bash
pack build $YOUR_CONTAINER_REGISTRY/bookshop-hana-deployer \
pack build $YOUR_CONTAINER_REGISTRY/bookshop-hdi-deployer \
--path db \
--buildpack gcr.io/paketo-buildpacks/nodejs \
--builder paketobuildpacks/builder-jammy-base \
--env BP_NODE_RUN_SCRIPTS=""
--builder paketobuildpacks/builder:base \
--env BP_NODE_RUN_SCRIPTS="" \
--publish
```

**Build sidecar image (multi tenant only):**
**Build & publish sidecar image (multi tenant only):**

```bash
pack build $YOUR_CONTAINER_REGISTRY/bookshop-sidecar \
--path mtx/sidecar/gen \
--buildpack gcr.io/paketo-buildpacks/nodejs \
--builder paketobuildpacks/builder-jammy-base \
--env BP_NODE_RUN_SCRIPTS=""
--builder paketobuildpacks/builder:base \
--env BP_NODE_RUN_SCRIPTS="" \
--publish
```

### Push container images

You can push all the container images to your container registry, using:
### Configuration

```bash
docker push $YOUR_CONTAINER_REGISTRY/bookshop-srv
Complete the configuration in the
- _`helm/single-tenant/values.yaml`_ file if you're going for a **single-tenant deployment**, or the
- _`helm/multi-tenant/values.yaml`_ file if you're going for a **multi-tenant deployment**

docker push $YOUR_CONTAINER_REGISTRY/bookshop-approuter
```

#### Single Tenant
#### For both single- and multi-tenant deployment
1. Change value of `global.domain` key to your cluster domain.
2. Change value of `global.image.registry` to the URL of your container registry.
3. Change value of `global.imagePullSecret.name` to the image registry secret created in [Create container registry secret](#create-container-registry-secret) step if you haven't used the name `image-pull-secret`.

```bash
docker push $YOUR_CONTAINER_REGISTRY/bookshop-hana-deployer
```yaml
global:
domain: # <kyma_cluster_domain> e.g. c-865b338.stage.kyma.ondemand.com
imagePullSecret:
name: image-pull-secret # <image_pull_secret> e.g. image-pull-secret
image:
registry: # <container_image_registry> e.g. cdsjava.common.repositories.cloud.sap
```

#### Multi Tenant

```bash
docker push $YOUR_CONTAINER_REGISTRY/bookshop-sidecar
4. Set `srv.image.repository` and `srv.image.tag` to the image path and tag you used in the `pack build` command for the `bookshop-srv`.
```yaml
srv:
image:
repository: # <image_path> e.g. bookshop/bookshop-srv
tag: latest # <tag> e.g. latest
```

### Configuration

Make the following changes in the _`chart/values.yaml`_ file.

1. Change value of `global.domain` key to your cluster domain.

2. Replace `<your-cluster-domain>` in `xsuaa.parameters.oauth2-configuration.redirect-uris` with your cluster domain.

3. Replace `<your-container-registry>` with your container registry.
5. Set `approuter.image.repository` and `approuter.image.tag` to the image path and tag you used in the `pack build` command for the `bookshop-approuter`.
```yaml
approuter:
image:
repository: # <image_path> e.g. bookshop/bookshop-approuter
tag: # <tag> e.g. latest
```

4. Make the following change to add backend destinations required by Approuter.
#### For single-tenant deployment only

```diff
- backendDestinations: {}
+ backendDestinations:
+ backend:
+ service: srv
+ mtx-api:
+ service: srv
6. In the `helm/single-tenant/values.yaml` file, set `hdi-deployer.image.repository` and `hdi-deployer.image.tag` to the image path and tag you used in the `pack build` command for the `bookshop-hdi-deployer`.
```yaml
hdi-deployer:
image:
repository: # <image_repository> e.g. bookshop/bookshop-hdi-deployer
tag: # <tag> e.g. latest
```

5. Add your image registry secret created in [Create container registry secret](#create-container-registry-secret) step.
#### For multi-tenant deployment only

```diff
global:
domain: null
- imagePullSecret: {}
+ imagePullSecret:
+ name: container-registry
6. In the `helm/multi-tenant/values.yaml` file, set `sidecar.image.repository` and `sidecar.image.tag` to the image path and tag you used in the `pack build` command for the `bookshop-sidecar`.
```yaml
sidecar:
image:
repository: # <image_path> e.g. bookshop/bookshop-sidecar
tag: # <tag> e.g. latest
```

6. If the application is deployed multiple times in the same cluster, make sure to adapt the values of `xsappname` and `appName` under `saasRegistryParameters` in `values/Chart.yaml`

### Deployment

Deploy the helm chart using the following command:
Deploy the helm chart using the following command from the project root directory:

#### Single Tenant
#### Single-Tenant

```bash
helm install bookshop ./chart --set-file xsuaa.jsonParameters=xs-security.json
helm upgrade --install --namespace=<namespace> <release_name> ./helm/single-tenant --set-file xsuaa.jsonParameters=xs-security.json
```

Before you can access the UI you should make sure to [Setup Authorizations in SAP Business Technology Platform](#setup-authorizations-in-sap-business-technology-platform).

Click on the approuter url logged by the `helm install` to access the UI.
URL to access the UI: `https://<release_name>-approuter-<namespace>.<cluster_domain>`

#### Multi Tenant
#### Multi-Tenant

```bash
helm install bookshop ./chart --set-file xsuaa.jsonParameters=xs-security-mt.json
helm upgrade --install --namespace=<namespace> <release_name> ./helm/multi-tenant --set-file xsuaa.jsonParameters=xs-security-mt.json
```

In case of multi tenant, you'll have to subscribe to the application from a different subaccount. You can follow the steps mentioned [here](https://cap.cloud.sap/docs/guides/deployment/as-saas#subscribe) to access the application.
Expand Down
21 changes: 21 additions & 0 deletions helm/multi-tenant/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
dependencies:
- name: web-application
repository: https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz/
version: 1.15.0
- name: web-application
repository: https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz/
version: 1.15.0
- name: web-application
repository: https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz/
version: 1.15.0
- name: service-instance
repository: https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz/
version: 1.5.0
- name: service-instance
repository: https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz/
version: 1.5.0
- name: service-instance
repository: https://int.repositories.cloud.sap/artifactory/virtual-unified-runtime-helm-dmz/
version: 1.5.0
digest: sha256:f472cd80725ccc634a6b708e0988592d106befb2a556e6132c4a52dd83511e62
generated: "2024-06-14T16:17:25.549919+02:00"
Loading