These instructions will walk you through deploying the [Cloud Foundry Spring
Music](https://github.com/cloudfoundry-samples/spring-music) reference App with Kf, demonstrating a few things along the
way:

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 and bind a PostgreSQL
   database to the Spring Music App.

3. **Spring Cloud Connectors** : [Spring Cloud
   Connectors](https://cloud.spring.io/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

### Option 1: Minibroker

The cluster administrator should follow [these instructions](https://docs.cloud.google.com/migrate/kf/docs/2.3/how-to/minibroker.md.txt)
to install the Minibroker service broker into your cluster. Minibroker will
allow you to provision a PostgreSQL database and configure your App to use it.

To confirm that Minibroker is installed and available to your cluster, run `kf
marketplace` and you should see output similar to:

```bash
$ kf marketplace
5 services can be used in Space "demo", use the --service flag to list the plans for a service

Broker      Name        Space      Status  Description
minibroker  mariadb                Active  Helm Chart for mariadb
minibroker  mongodb                Active  Helm Chart for mongodb
minibroker  mysql                  Active  Helm Chart for mysql
minibroker  postgresql             Active  Helm Chart for postgresql
minibroker  redis                  Active  Helm Chart for redis
```

### Option 2: Other Service Broker

You can use a different service broker that's installed as long as it supports
creating PostgreSQL services. For example, the [gcp-service-broker]().

## Deploy

### Clone source

1. Clone the [Spring Music repo](https://github.com/cloudfoundry-samples/spring-music).

   ```
   git clone https://github.com/cloudfoundry-samples/spring-music.git spring-music
   cd spring-music
   ```
2. Edit `manifest.yml`, and replace the contents with the following:

   ```bash
   ---
   applications:
   - name: spring-music
     memory: 1G
     random-route: true
     stack: org.cloudfoundry.stacks.cflinuxfs3
     env:
       BP_AUTO_RECONFIGURATION_ENABLED: false
   ```

### Push App

1. Deploy (this assumes you've already `kf target`ed a Space; see [these
   docs](https://docs.cloud.google.com/migrate/kf/docs/2.3/quickstart#prepare_space) for more detail):

   ```bash
   kf push spring-music
   ```
2. Use the proxy feature to access the deployed App, then load
   `http://localhost:8080` in your browser:

   ```bash
   kf proxy spring-music
   ```

   ![](https://docs.cloud.google.com/migrate/kf/docs/2.3/images/sm1.png)
   > 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 database

1. Create a PostgreSQL service via the broker installed in the marketplace:

   ```bash
   kf create-service postgresql 11-7-0 spring-music-db -c '{"postgresqlDatabase":"smdb", "postgresDatabase":"smdb"}'
   ```
2. Bind the service instance to the Spring Music App:

   ```bash
   kf bind-service spring-music spring-music-db -c '{"postgresqlDatabase":"smdb", "postgresDatabase":"smdb"}'
   ```
3. Restart the App to make the service binding available via the `VCAP_SERVICES`
   environment variable:

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

   ```bash
   kf bindings
   ```
5. `kf proxy` to the App again and view it in your web browser. The Spring
   profile should be shown, indicating the PostgreSQL service you created and
   bound is being used:

   ![](https://docs.cloud.google.com/migrate/kf/docs/2.3/images/sm2.png)

## Destroy

1. Unbind and delete the PostgreSQL service:

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

   ```bash
   kf delete spring-music
   ```