Skip to content

Commit

Permalink
Helm Chart (#227)
Browse files Browse the repository at this point in the history
* Helm Chart
* Add "bash" for Windows users
* Improve UI doc
* Ignore Helm chart
  • Loading branch information
uwe-klinger authored Jul 15, 2022
1 parent fc1054e commit 5932451
Show file tree
Hide file tree
Showing 12 changed files with 625 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ dist/
.classpath
# .vscode/*
# IMPORTANT: Do not exclude .vscode please!

# Local dev
.env
.values.yaml
.cdsrc-private.json

# Exclude Helm chart for this example
/chart
172 changes: 172 additions & 0 deletions README-Kyma-Runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Deployment to SAP Business Technology Platform - Kyma Runtime

- [Deployment to SAP Business Technology Platform - Kyma Runtime](#deployment-to-sap-business-technology-platform---kyma-runtime)
- [Preconditions](#preconditions)
- [Add Deployment Files](#add-deployment-files)
- [Configuration](#configuration)
- [Prepare Kubernetes Namespace](#prepare-kubernetes-namespace)
- [Create container registry secret](#create-container-registry-secret)
- [Create a secret for your HDI container](#create-a-secret-for-your-hdi-container)
- [Build - Node.js](#build---nodejs)
- [Build - Java](#build---java)
- [Build HTML5 application deployer image](#build-html5-application-deployer-image)
- [Push docker images](#push-docker-images)
- [Deployment](#deployment)
- [Access the UI](#access-the-ui)

**TIP:** You can find more information in the [Deploy Your CAP Application on SAP BTP Kyma Runtime](https://developers.sap.com/mission.btp-deploy-cap-kyma.html) tutorial and in the [Deploy to Kyma/K8s](https://cap.cloud.sap/docs/guides/deployment/deploy-to-kyma) guide of the CAP documentation.

## Preconditions

- BTP Subaccount with Kyma Runtime
- BTP Subaccount with Cloud Foundry Space
- HANA Cloud instance available for your Cloud Foundry space
- BTP Entitlements for: *HANA HDI Services & Container* plan *hdi-shared*, *Launchpad Service* plan *standard*
- Container Registry
- Command Line Tools: `kubectl`, `kubectl-oidc_login`, `pack`, `docker`, `helm`, `cf`
- Logged into Kyma Runtime (with `kubectl` CLI), Cloud Foundry space (with `cf` CLI) and Container Registry (with `docker login`)
- `@sap/cds-dk` >= 6.0.1

## Add Deployment Files

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

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

```bash
cds add helm
cds add helm:html5_apps_deployer
```

## Configuration

This project contains a pre-configured configuration file `deployment/kyma/values.yaml`, you just need to do the following changes in this file:

- `<your-container-registry>` - full-qualified hostname of your container registry
- `domain`- full-qualified domain name used to access applications in your Kyma cluster

## Prepare Kubernetes Namespace

1. Export the kubeconfig.yaml

```
set KUBECONFIG=~/.kube/cap-kyma-app-config
```
2. Setting the namespace
```
kubectl config set-context --current --namespace=<<NAMESPACE>>
```
### Create container registry secret
Create a secret `container-registry` with credentials to access the container registry:
```
bash deployment/kyma/scripts/create-container-registry-secret.sh
```
The *Docker Server* is the full-qualified hostname of your container registry.
### Create a secret for your HDI container
```
bash deployment/kyma/scripts/create-db-secret.sh sflight-db
```
## Build - Node.js
Do the following steps if you want to deploy the **Node.js** application.
The `CDS_ENV=node` env variable needs to be provided to build for Node.js. The application will be built for Java by default.
```
CDS_ENV=node cds build --production
```
**Build data base deployer image:**
```
pack build $YOUR_CONTAINER_REGISTRY/sflight-hana-deployer \
--path gen/db \
--buildpack gcr.io/paketo-buildpacks/nodejs:0.16.1 \
--builder paketobuildpacks/builder:base
```
(Replace `$YOUR_CONTAINER_REGISTRY` with the full-qualified hostname of your container registry)
**Build image for CAP service:**
```
pack build \
$YOUR_CONTAINER_REGISTRY/sflight-srv \
--path "gen/srv" \
--buildpack gcr.io/paketo-buildpacks/nodejs \
--builder paketobuildpacks/builder:base
```
## Build - Java
Do the following steps if you want to deploy the **Java** application.
**Build data base deployer image:**
```
cds build --production
```
```
pack build $YOUR_CONTAINER_REGISTRY/sflight-hana-deployer \
--path db \
--buildpack gcr.io/paketo-buildpacks/nodejs:0.16.1 \
--builder paketobuildpacks/builder:base
```
(Replace `$YOUR_CONTAINER_REGISTRY` the full-qualified hostname of your container registry)
**Build image for CAP service:**
```
mvn package
```
```
pack build $YOUR_CONTAINER_REGISTRY/sflight-srv \
--path srv/target/*-exec.jar \
--buildpack gcr.io/paketo-buildpacks/sap-machine \
--buildpack gcr.io/paketo-buildpacks/java \
--builder paketobuildpacks/builder:base \
--env SPRING_PROFILES_ACTIVE=cloud
```
## Build HTML5 application deployer image
```
bash deployment/kyma/scripts/build-ui-image.sh
```
## Push docker images
You can push all the docker images to your docker registry, using:
```
docker push $YOUR_CONTAINER_REGISTRY/sflight-hana-deployer
docker push $YOUR_CONTAINER_REGISTRY/sflight-srv
docker push $YOUR_CONTAINER_REGISTRY/sflight-html5-deployer
```
## Deployment
```
helm upgrade sflight ./chart --install -f deployment/kyma/values.yaml
```
## Access the UI
1. Create Launchpad Service subscription in the BTP Cockpit
2. Create a role collection `sflight`
3. Add role `admin` of `sflight.tXYZ` application to role collection
4. Add your user to the role collection
5. Goto **HTML5 Applications**
6. Start HTML5 application `sapfecaptravel`
Additionally, you can add the UI to a Launchpad Service site like it is described in in the last two steps of [this tutorial](https://developers.sap.com/tutorials/btp-app-kyma-launchpad-service.html#9aab2dd0-18ea-4ccd-bc44-24e87c845740).
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The configuration file `mta.yaml` is for the Node.js backend of the app. If you
- Create a [trial account on SAP BTP](https://www.sap.com/products/business-technology-platform/trial.html). See this [tutorial](https://developers.sap.com/tutorials/hcp-create-trial-account.html) for more information. Alternatively, you can use a sub-account in a productive environment.
- Subscribe to the [SAP Launchpad Service](https://developers.sap.com/tutorials/cp-portal-cloud-foundry-getting-started.html).
- Create an [SAP HANA Cloud Service instance](https://developers.sap.com/tutorials/btp-app-hana-cloud-setup.html#08480ec0-ac70-4d47-a759-dc5cb0eb1d58) or use an existing one.

#### Local Machine

- Install the Cloud Foundry command line interface (CLI). See this [tutorial](https://developers.sap.com/tutorials/cp-cf-download-cli.html) for more details.
Expand Down Expand Up @@ -135,6 +135,10 @@ You need to have access to a HANA Cloud instance and SAP BTP.
The running application is now connected to its own HDI container/schema. Please keep in mind that the credentials for
that HDI container are stored locally on your filesystem (default-env.json).

## Deployment to SAP Business Technology Platform - Kyma Runtime

The deployment to Kyma Runtime is explained in file [README-Kyma-Runtime.md](./README-Kyma-Runtime.md).

## Creating an SAP Fiori App from Scratch

If you want to implement an SAP Fiori app, follow these tutorials:
Expand Down
9 changes: 9 additions & 0 deletions db/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "deploy",
"dependencies": {
"@sap/hdi-deploy": "^4"
},
"scripts": {
"start": "node node_modules/@sap/hdi-deploy/deploy.js"
}
}
67 changes: 67 additions & 0 deletions deployment/kyma/scripts/build-ui-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

set -e
cd "$(dirname "$(npm root)")"
DIR="$(pwd)"

npm install --no-save yaml

function value() {
node "$DIR/deployment/kyma/scripts/value.js" "$1"
}

function image() {
local REPOSITORY="$(value "$1.image.repository")"
local TAG="$(value "$1.image.tag")"
if [ "$TAG" != "" ]; then
echo "$REPOSITORY:$TAG"
else
echo "$REPOSITORY"
fi
}

rm -rf gen/ui
mkdir -p gen/ui/resources

CLOUD_SERVICE="$(value html5_apps_deployer.cloudService)"
DESTINATIONS="$(value html5_apps_deployer.backendDestinations)"

IMAGE="$(image html5_apps_deployer)"

for APP in app/*; do
if [ -f "$APP/webapp/manifest.json" ]; then
echo "Build $APP..."
echo

rm -rf "gen/$APP"
mkdir -p "gen/app"
cp -r "$APP" gen/app
pushd >/dev/null "gen/$APP"

node "$DIR/deployment/kyma/scripts/prepareUiFiles.js" $CLOUD_SERVICE $DESTINATIONS
npm install
npx ui5 build preload --clean-dest --config ui5-deploy.yaml --include-task=generateManifestBundle generateCachebusterInfo
cd dist
rm manifest-bundle.zip
mv *.zip "$DIR/gen/ui/resources"

popd >/dev/null
fi
done

cd gen/ui

echo
echo "HTML5 Apps:"
ls -l resources
echo

cat >package.json <<EOF
{
"name": "ui-deployer",
"scripts": { "start": "node node_modules/@sap/html5-app-deployer/index.js" }
}
EOF

npm install @sap/html5-app-deployer
pack build $IMAGE --path . --buildpack gcr.io/paketo-buildpacks/nodejs --builder paketobuildpacks/builder:base
28 changes: 28 additions & 0 deletions deployment/kyma/scripts/create-container-registry-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

read -p "Docker Server: " DOCKER_SERVER

read -p "User ($USER): " DOCKER_USER
if [ "$DOCKER_USER" == "" ]; then
DOCKER_USER="$USER"
fi

if [ "$EMAIL" == "" ]; then
read -p "EMail: " DOCKER_EMAIL
else
read -p "EMail ($EMAIL): " DOCKER_EMAIL
if [ "$DOCKER_EMAIL" == "" ]; then
DOCKER_EMAIL="$EMAIL"
fi
fi

read -sp "API Key: " API_KEY

echo
echo

kubectl create secret docker-registry container-registry \
"--docker-server=$DOCKER_SERVER" \
"--docker-username=$DOCKER_USER" \
"--docker-email=$DOCKER_EMAIL" \
"--docker-password=$API_KEY"
52 changes: 52 additions & 0 deletions deployment/kyma/scripts/create-db-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -e
cd "$(dirname "$(dirname "$0")")"

npm install --no-save yaml

function value() {
node ./scripts/value.js "$1"
}

NAME="$1"
if [ "$NAME" == "" ]; then
NAME="$(value srv.bindings.db.fromSecret)"
if [ "$NAME" == "" -o "$NAME" == "<nil>" ]; then
echo >&2 "[ERROR] Please either specify the name for the DB secret or maintain it in the Helm chart"
exit 1
fi
fi

SECRET_HEADER="$(cat <<EOF
apiVersion: v1
kind: Secret
metadata:
name: $NAME
type: Opaque
stringData:
type: hana
label: hana
EOF
)"

cf 2>/dev/null >/dev/null service $NAME || cf create-service hana hdi-shared $NAME
while true; do
STATUS="$(cf 2>/dev/null service $NAME | grep status: | head -n 1)"
echo $STATUS
if [[ "$STATUS" = *succeeded* ]]; then
break
fi
sleep 1
done

cf create-service-key $NAME $NAME-key

node "$(dirname "$0")/format-kyma-secret.js" -- "$(echo "$SECRET_HEADER")" "$(cf service-key $NAME $NAME-key)" | kubectl apply -f -
echo
echo "HANA DB Kubernetes secret '$NAME' created."
echo
echo "You can view it using:"
echo
echo "kubectl get secret $NAME -o yaml"
exit 0
9 changes: 9 additions & 0 deletions deployment/kyma/scripts/format-kyma-secret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const key=JSON.parse(process.argv[4].replace(/^.*/, ""));
const credentials=key.credentials /* new cfcli? */ || key;
console.log(process.argv[3]);
console.log(Object.keys(credentials).map(k => {
if (credentials[k].match(/\n/s))
return (` ${k}: |\n${credentials[k]}`).replace(/\n/gs,"\n ")
else
return ` ${k}: "${credentials[k]}"`
}).join("\n"))
Loading

0 comments on commit 5932451

Please sign in to comment.