Deploy Spring Music

These instructions will walk you through deploying the Cloud Foundry Spring Music reference App using the Kf Cloud Service Broker for Google Cloud.

  1. Building Java Apps from source: The Spring Music source will be built on the cluster, not locally.

  2. Service broker integration: You will create a database using the Kf Cloud Service Broker and bind the Spring Music App to it.

  3. Spring Cloud Connectors: Spring Cloud Connectors are used by the Spring Music App to detect things like bound CF services. They work seamlessly with Kf.

  4. Configuring the Java version: You will specify the version of Java you want the buildpack to use.

Prerequisites

Install and configure Kf Cloud Service Broker

  1. Deploy Kf Cloud Service Broker.

Deploy Spring Music

Clone source

  1. Clone the Spring Music repo.

    git clone https://github.com/cloudfoundry-samples/spring-music.git spring-music
    cd spring-music
  2. Edit manifest.yml, and replace path: build/libs/spring-music-1.0.jar with stack: org.cloudfoundry.stacks.cflinuxfs3. This instructs Kf to build from source using cloud native buildpacks so you don't have to compile locally.

    ---
    applications:
    - name: spring-music
      memory: 1G
      random-route: true
      stack: org.cloudfoundry.stacks.cflinuxfs3
      env:
        JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'
    #    JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }'

Push Spring Music with no bindings

  1. Create and target a Space.

    kf create-space test
    kf target -s test
  2. Deploy Spring Music.

    kf push spring-music
  3. Use the proxy feature to access the deployed App.

    1. Start the proxy:

      kf proxy spring-music
    2. Open http://localhost:8080 in your browser:

    The deployed App includes a UI element showing which (if any) Spring profile is being used. No profile is being used here, indicating an in-memory database is in use.

Create and bind a database

  1. Create a PostgresSQL database from the marketplace.

     kf create-service csb-google-postgres small spring-music-postgres-db -c '{"region":"COMPUTE_REGION","authorized_network":"VPC_NAME"}'
  2. Bind the Service with the App.

     kf bind-service spring-music spring-music-postgres-db
  3. Restart the App to make the service binding available via the VCAP_SERVICES environment variable.

     kf restart spring-music
  4. (Optional) View the binding details.

     kf bindings
  5. Verify the App is using the new binding.

    1. Start the proxy:

      kf proxy spring-music
    2. Open http://localhost:8080 in your browser:

      You now see the Postgres profile is being used, and we see the name of our Service we bound the App to.

Clean up

  1. Unbind and delete the PostgreSQL service:

    kf unbind-service spring-music spring-music-db
    kf delete-service spring-music-db
  2. Delete the App:

    kf delete spring-music