Using Metadata to Label PAS App Resources with a git SHA

Introduction

The PAS 2.5 release added the ability to add metadata to a given resource. The metadata feature allows users to add both labels and annotations to their PAS resources. One interesting use case is to tag your app and related resources with a git commit SHA. This allows you to track which version of your code is running on PAS.

When you push an app to PAS, the files you push are stored in a resource called a package. Packages are an input into the staging process, along with buildpacks, the output of which is a droplet.

Tracking the version of your code through these various resources can be difficult, so it may help to label them.

Prerequisites

Adding Labels with the API

Then, we need to find the GUIDs of the resource we want to label. Here, we'll label the app, package, and droplet.

To get the app's GUID:

cf app appName --guid

The CLI does not yet support labels, so we'll have to access the API directly. Luckily, the CLI does include a curl command that takes care of authentication and targeting the appropriate API endpoint.

To get the GUID of the current droplet associated with the app:

cf curl "/v3/apps/${APP_GUID}/droplets/current" | jq -r .guid

Droplet are built from packages, so to get the package GUID associated with your droplet:

Viewing and editing labels in Pivotal Apps Manager

You can also view and edit app labels in Pivotal Apps Manager. In order to do this, you will want to navigate to your application page in Apps Manager. Your app's metadata is stored under the Settings tab.

If you already successfully ran the script from above, you will notice the commit label exists for the app. Apps Manager allows you to add, edit and remove metadata directly from the UI. Simply make your edits via the metadata text boxes or the JSON editor and hit the `Update Metadata` button. Your metadata will be saved to your app and will be accessible via Apps Manager or API.

Now you are ready to begin labeling your app, package and droplet resources with your git commit SHA to help you better understand what code is running on PAS. This is just one use case for using metadata, but there are many more. We look forward to seeing how our users adopts this new feature

About the Author

The CAPI Product Team is a core component team for PAS and Cloud Foundry. The team’s core mission is to simplify the experience of running cloud applications at scale.