SAP Cloud Application Programming Model (CAP) SFLIGHT Sample

repository·main·Indexed 42 days ago

https://github.com/sap-samples/cap-sflight

A sample application for the travel reference scenario built using the SAP Cloud Application Programming Model (CAP) and SAP Fiori Elements. It demonstrates SAP Fiori annotations and provides implementation examples for both Node.js and Java stacks, including deployment options for SAP BTP and Kyma Runtime.

Tokens
3.5K
Snippets
13
Records
16
Agent score
54%

What's inside CAP SFLIGHT

  1. Add Deployment Files for Kyma

    main

    To prepare the project for Kyma deployment, use the CAP CLI to add the necessary Helm chart and HTML5 repository features:

    cds add helm
    cds add html5-repo
  2. Run Integration Tests (OPA)

    main

    To start the OPA (Object Page Automation) integration tests, open the following URL in your browser after the application is running locally:

    http://localhost:4004/travel_processor/webapp/test/integration/Opa.qunit.html

    For further details on testing, refer to the SAP UI5 API documentation.

    http://localhost:4004/travel_processor/webapp/test/integration/Opa.qunit.html
  3. Build and Push Docker Images (Node.js)

    main

    To deploy a Node.js backend, ensure you set CDS_ENV=node during the build process.

    1. Build CAP Service and DB Deployer

    # Build the application
    CDS_ENV=node cds build --production
    
    # Build database deployer image
    pack build $YOUR_CONTAINER_REGISTRY/sflight-hana-deployer \
         --path gen/db \
         --buildpack gcr.io/paketo-buildpacks/nodejs \
         --builder paketobuildpacks/builder-jammy-base \
         --env BP_NODE_RUN_SCRIPTS=""
    
    # Build CAP service image
    pack build $YOUR_CONTAINER_REGISTRY/sflight-srv \
         --path "gen/srv" \
         --buildpack gcr.io/paketo-buildpacks/nodejs \
         --builder paketobuildpacks/builder-jammy-base \
         --env BP_NODE_RUN_SCRIPTS=""

    2. Build UI Image

    bash .github/deployment/kyma/scripts/build-ui-image.sh

    3. Push Images

    docker push $YOUR_CONTAINER_REGISTRY/sflight-hana-deployer
    docker push $YOUR_CONTAINER_REGISTRY/sflight-srv
    docker push $YOUR_CONTAINER_REGISTRY/sflight-html5-deployer
    # Node.js Build Example
    CDS_ENV=node cds build --production
    
    pack build $YOUR_CONTAINER_REGISTRY/sflight-srv \
         --path "gen/srv" \
         --buildpack gcr.io/paketo-buildpacks/nodejs \
         --builder paketobuildpacks/builder-jammy-base \
         --env BP_NODE_RUN_SCRIPTS=""
  4. Prerequisites for Kyma Deployment

    main

    Before deploying the CAP SFLIGHT application to SAP BTP Kyma Runtime, ensure you have the following resources and tools configured:

    BTP Resources

    • BTP Subaccount with Kyma Runtime.
    • BTP Subaccount with Cloud Foundry Space.
    • HANA Cloud instance available for your Cloud Foundry space.
    • BTP Entitlements for:
      • hdi-shared (HANA HDI Services & Container plan).
      • standard (Build Work Zone plan).

    Tools and Access

    • Container Registry.
    • Command Line Tools installed: kubectl, kubectl-oidc_login, pack, docker, helm, cf.
    • Active Sessions: You must be logged into Kyma Runtime (via kubectl), Cloud Foundry space (via cf), and your Container Registry (via docker login).
    • CAP SDK: @sap/cds-dk version >= 6.6.0.
  5. Deploy to SAP Business Technology Platform (BTP)

    main

    This project uses an MTA (Multi-Target Application) configuration for deployment to SAP BTP.

    1. Prepare the MTA file

    • For Node.js backend: Use the default mta.yaml.
    • For Java backend: Copy mta-java.yaml to mta.yaml before building.

    2. Prerequisites (Local Machine)

    Ensure you have the Cloud Foundry CLI, the MultiApps plugin, and the Cloud MTA Build Tool installed:

    # Install MultiApps plugin
    cf add-plugin-repo CF-Community https://plugins.cloudfoundry.org
    cf install-plugin multiapps
    
    # Install Cloud MTA Build Tool
    npm install -g mbt

    3. Build and Deploy

    Execute the build from the project root, then deploy the resulting archive using the CF CLI:

    # Build the project
    mbt build
    
    # Deploy the archive (replace version as needed)
    cf deploy mta_archives/capire.sflight_1.0.0.mtar
    mbt build
    cf deploy mta_archives/capire.sflight_1.0.0.mtar
  6. Build and Push Docker Images (Java)

    main

    To deploy a Java backend, follow these steps:

    1. Build CAP Service and DB Deployer

    # Build the application
    cds build --production
    
    # Build database deployer image
    pack build $YOUR_CONTAINER_REGISTRY/sflight-hana-deployer \
         --path gen/db \
         --buildpack gcr.io/paketo-buildpacks/nodejs \
         --builder paketobuildpacks/builder-jammy-base \
         --env BP_NODE_RUN_SCRIPTS=""
    
    # Build CAP service image
    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-jammy-base \
         --env SPRING_PROFILES_ACTIVE=cloud \
         --env BP_JVM_VERSION=17

    2. Build UI Image

    bash .github/deployment/kyma/scripts/build-ui-image.sh

    3. Push Images

    docker push $YOUR_CONTAINER_REGISTRY/sflight-hana-deployer
    docker push $YOUR_CONTAINER_REGISTRY/sflight-srv
    docker push $YOUR_CONTAINER_REGISTRY/sflight-html5-deployer
    # Java Build Example
    cds build --production
    
    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-jammy-base \
         --env SPRING_PROFILES_ACTIVE=cloud \
         --env BP_JVM_VERSION=17
  7. Access the SFLIGHT UI

    main

    After deployment, follow these steps to access the user interface:

    1. Subscription: Create a Build Work Zone subscription in the BTP Cockpit.
    2. Role Collection: Create a role collection named sflight.
    3. Permissions: Add the role admin of the sflight.tXYZ application to the sflight role collection.
    4. User Assignment: Add your user to the sflight role collection.
    5. Launch: Go to HTML5 Applications in Build Work Zone and start the HTML5 application sapfecaptravel.
  8. Run the CAP SFLIGHT app with a Java Backend

    main

    To run the application locally using the Java stack, follow these steps in the project root:

    1. Install dependencies: npm ci
    2. Build the UI: npm run build:ui (Note: You must run this after every UI change as there is no watch mode for Fiori UI).
    3. Start the Spring Boot application: mvn spring-boot:run

    Once running, you can access the SAP Fiori apps at:

    • Travel Data Processing: http://localhost:4004/travel_processor/dist/index.html
    • Analytical List Page (ALP): http://localhost:4004/travel_analytics/dist/index.html

    Default Login Credentials:

    • User: amy
    • Password: (empty)
    npm ci
    npm run build:ui
    mvn spring-boot:run
  9. Local Development with a HANA Cloud Instance

    main

    To develop locally while connected to a remote SAP HANA Cloud instance:

    1. Deploy HDI content: Run cds deploy --to hana to create/update the HDI container.
    2. Start with Cloud Profile: Run the application using the cloud Spring profile. This ensures the app connects to the HDI container using credentials stored in your local default-env.json.

    Execution Commands:

    • Using Maven: mvn spring-boot:run -Dspring-boot.run.profiles=cloud
    • Using IDE/Environment Variable: Set spring.profiles.active=cloud
    cds deploy --to hana
    # Using Maven
    mvn spring-boot:run -Dspring-boot.run.profiles=cloud
  10. Prepare Kubernetes Namespace and Secrets

    main

    Follow these steps to configure your Kubernetes environment for deployment:

    1. Set Kubeconfig and Namespace

    Export your kubeconfig and set the target namespace:

    set KUBECONFIG=~/.kube/cap-kyma-app-config
    kubectl config set-context --current --namespace=<<NAMESPACE>>

    2. Create Container Registry Secret

    Run the provided script to create a container-registry secret containing your registry credentials:

    bash .github/deployment/kyma/scripts/create-container-registry-secret.sh

    Note: The Docker Server must be the fully-qualified hostname of your registry.

    3. Create HDI Container Secret (BTP Trial Only)

    If using a BTP Trial account, you must create an HDI container and a corresponding Kubernetes secret. For production or free tier accounts, you can skip this by mapping your Kyma namespace to your HANA Cloud instance directly.

    To create the secret for a trial account:

    bash .github/deployment/kyma/scripts/create-db-secret.sh sflight-db

    This creates an HDI container named sflight-db in your Cloud Foundry space and a Kubernetes secret named sflight-db in your namespace.

    set KUBECONFIG=~/.kube/cap-kyma-app-config
    kubectl config set-context --current --namespace=<<NAMESPACE>>
    
    bash .github/deployment/kyma/scripts/create-container-registry-secret.sh
    
    bash .github/deployment/kyma/scripts/create-db-secret.sh sflight-db
  11. Deploy to Kyma using Helm

    main

    Once images are pushed to your registry, deploy the application using Helm. This command also injects the XSUAA security configuration:

    helm install sflight ./chart --set-file xsuaa.jsonParameters=xs-security.json
  12. Run the CAP SFLIGHT app with a Node.js Backend

    main

    To run the application locally using the Node.js stack, ensure you have the @sap/cds-dk development kit installed. Follow these steps in the project root:

    1. Install dependencies: npm ci
    2. Start the application: cds watch

    Once running, you can access the SAP Fiori apps at:

    • Travel Data Processing: http://localhost:4004/sap.fe.cap.travel/index.html
    • Analytical List Page (ALP): http://localhost:4004/sap.fe.cap.travel_analytics/index.html
    # Prerequisite
    npm i -g @sap/cds-dk
    
    # Run locally
    npm ci
    cds watch