Now that you've deployed PCF and logged in to Cloud Foundry it's time to explore the platform and Google Cloud.
This exercise deploys a spring application that scrapes /r/aww for photos, stores them in Google Cloud Storage and classifies them with the Google Cloud Vision API.
The services are provisioned by the GCP Service Broker so we will not need to leave Cloud Foundry to create them or setup authentication.
Run cf apps
to ensure you're connected and authenticated to Cloud Foundry.
If the command fails ensure you've logged in.
Cloud Foundry uses orgs and spaces to contain applications and services. Create and target an org and space for your development with the following commands:
cf create-org dev
cf create-space -o dev dev
cf target -o dev -s dev
This sample app requires maven and Java 1.8 to build. Users of Google Cloud Shell will have this by default.
Confirm with the following commands:
mvn -version # look for: Apache Maven 3+
java -version # look for: version "1.8"
From the root directory of this project (gcp-pcf-quickstart
) run the following commands:
cd docs/samples/awwvision
mvn package -DskipTests && cf push -p target/awwvision-spring-0.0.1-SNAPSHOT.jar --no-start
Create a Google Cloud Storage service and bind it to the application. This provisions a new storage bucket and service account with the role 'storage.objectAdmin'. The bind command will also create a new service account key for your application to authenticate to Google Cloud Storage.
Run the following commands:
cf create-service google-storage standard awwvision-storage
cf bind-service awwvision awwvision-storage -c '{"role":"storage.objectAdmin"}'
To view the credentials, try: cf env awwvision
The app can now be started and hostname retrieved with the following commands:
cf start awwvision
cf apps
Enter the URL into your browser (eg: http://awwvision-...apps...) and click on 'Update with latest images'. This may take up to 30 seconds. Follow the link back to the homepage and view the resulting images:
Click on the text category to view the related images, for example click 'Dog'
Find the name of the Google Cloud Storage bucket by running the following command and looking for "bucket_name":
cf env awwvision
Clear the contents of the bucket:
gsutil rm gs://<bucket name>/*
Delete the binding, service, and app:
cf unbind-service awwvision awwvision-storage
cf delete-service awwvision-storage
cf delete awwvision