Skip to content

Commit

Permalink
Conditional at Launch
Browse files Browse the repository at this point in the history
Previously, a binding was required at build time in order to contribute the
layers for the Stackdriver components.  We've started to think that requiring
a binding during build is too onerous a restriction and instead environment
variables should be used to indicate that a dependency should be contributed.
The knock-on effect of this change is that we have to move a lot more of the
conditional logic out to launch time including ensuring that if the binding
doesn't exist _nothing_ is contributed.  This change makes those updates to
the buildpack's behavior.

In addition, this change also includes an update that enables the buildpack to
determine if the application is running in GCP by detecting the metadata
server.  In this case, no binding is required at launch time either as the
credentials typically provided by the binding are instead provided by the
metadata server.

Finally, this includes a fix where the provided build plan wasn't anywhere
near exhaustive for combinations that a user need when using the buildpack.

Signed-off-by: Ben Hale <[email protected]>
  • Loading branch information
nebhale committed Nov 18, 2020
1 parent 1fa0ef5 commit 1c37f23
Show file tree
Hide file tree
Showing 60 changed files with 2,616 additions and 1,514 deletions.
10 changes: 5 additions & 5 deletions .github/pipeline-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ codeowners:
owner: "@paketo-buildpacks/java-buildpacks"

package:
repository: gcr.io/paketo-buildpacks/google-stackdriver
repository: gcr.io/paketo-buildpacks/google-cloud
register: true
registry_token: ${{ secrets.JAVA_GITHUB_TOKEN }}

Expand All @@ -17,20 +17,20 @@ docker_credentials:
password: ${{ secrets.JAVA_GCLOUD_SERVICE_ACCOUNT_KEY }}

dependencies:
- id: google-stackdriver-debugger-java
- id: google-cloud-debugger-java
uses: docker://ghcr.io/paketo-buildpacks/actions/github-release-dependency:main
with:
glob: compute-java_debian-wheezy_cdbg_java_agent_gce\.tar
owner: GoogleCloudPlatform
repository: cloud-debug-java
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
- id: google-stackdriver-debugger-nodejs
- id: google-cloud-debugger-nodejs
uses: docker://ghcr.io/paketo-buildpacks/actions/npm-dependency:main
with:
package: "@google-cloud/debug-agent"
- id: google-stackdriver-profiler-java
- id: google-cloud-profiler-java
uses: docker://ghcr.io/paketo-buildpacks/actions/google-stackdriver-profiler-dependency:main
- id: google-stackdriver-profiler-nodejs
- id: google-cloud-profiler-nodejs
uses: docker://ghcr.io/paketo-buildpacks/actions/npm-dependency:main
with:
package: "@google-cloud/profiler"
6 changes: 3 additions & 3 deletions .github/workflows/create-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
--config "${HOME}"/package.toml
fi
env:
PACKAGE: gcr.io/paketo-buildpacks/google-stackdriver
PACKAGE: gcr.io/paketo-buildpacks/google-cloud
PUBLISH: "true"
VERSION: ${{ steps.version.outputs.version }}
- name: Update release with digest
Expand All @@ -164,7 +164,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.JAVA_GITHUB_TOKEN }}
- uses: docker://ghcr.io/buildpacks/actions/registry:main
with:
address: gcr.io/paketo-buildpacks/google-stackdriver@${{ steps.package.outputs.digest }}
id: paketo-buildpacks/google-stackdriver
address: gcr.io/paketo-buildpacks/google-cloud@${{ steps.package.outputs.digest }}
id: paketo-buildpacks/google-cloud
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
version: ${{ steps.version.outputs.version }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update google-stackdriver-debugger-java
name: Update google-cloud-debugger-java
"on":
schedule:
- cron: 0 5 * * 1-5
Expand Down Expand Up @@ -75,21 +75,21 @@ jobs:
echo "::set-output name=old-version::${OLD_VERSION}"
echo "::set-output name=new-version::${VERSION}"
env:
ID: google-stackdriver-debugger-java
ID: google-cloud-debugger-java
SHA256: ${{ steps.dependency.outputs.sha256 }}
URI: ${{ steps.dependency.outputs.uri }}
VERSION: ${{ steps.dependency.outputs.version }}
VERSION_PATTERN: '[\d]+\.[\d]+\.[\d]+'
- uses: peter-evans/create-pull-request@v3
with:
body: Bumps `google-stackdriver-debugger-java` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/google-stackdriver-debugger-java
body: Bumps `google-cloud-debugger-java` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/google-cloud-debugger-java
commit-message: |-
Bump google-stackdriver-debugger-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bump google-cloud-debugger-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bumps google-stackdriver-debugger-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
Bumps google-cloud-debugger-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
delete-branch: true
labels: semver:minor, type:dependency-upgrade
signoff: true
title: Bump google-stackdriver-debugger-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
title: Bump google-cloud-debugger-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update google-stackdriver-debugger-nodejs
name: Update google-cloud-debugger-nodejs
"on":
schedule:
- cron: 0 5 * * 1-5
Expand Down Expand Up @@ -72,21 +72,21 @@ jobs:
echo "::set-output name=old-version::${OLD_VERSION}"
echo "::set-output name=new-version::${VERSION}"
env:
ID: google-stackdriver-debugger-nodejs
ID: google-cloud-debugger-nodejs
SHA256: ${{ steps.dependency.outputs.sha256 }}
URI: ${{ steps.dependency.outputs.uri }}
VERSION: ${{ steps.dependency.outputs.version }}
VERSION_PATTERN: '[\d]+\.[\d]+\.[\d]+'
- uses: peter-evans/create-pull-request@v3
with:
body: Bumps `google-stackdriver-debugger-nodejs` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/google-stackdriver-debugger-nodejs
body: Bumps `google-cloud-debugger-nodejs` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/google-cloud-debugger-nodejs
commit-message: |-
Bump google-stackdriver-debugger-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bump google-cloud-debugger-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bumps google-stackdriver-debugger-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
Bumps google-cloud-debugger-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
delete-branch: true
labels: semver:minor, type:dependency-upgrade
signoff: true
title: Bump google-stackdriver-debugger-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
title: Bump google-cloud-debugger-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update google-stackdriver-profiler-java
name: Update google-cloud-profiler-java
"on":
schedule:
- cron: 0 5 * * 1-5
Expand Down Expand Up @@ -70,21 +70,21 @@ jobs:
echo "::set-output name=old-version::${OLD_VERSION}"
echo "::set-output name=new-version::${VERSION}"
env:
ID: google-stackdriver-profiler-java
ID: google-cloud-profiler-java
SHA256: ${{ steps.dependency.outputs.sha256 }}
URI: ${{ steps.dependency.outputs.uri }}
VERSION: ${{ steps.dependency.outputs.version }}
VERSION_PATTERN: '[\d]+\.[\d]+\.[\d]+'
- uses: peter-evans/create-pull-request@v3
with:
body: Bumps `google-stackdriver-profiler-java` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/google-stackdriver-profiler-java
body: Bumps `google-cloud-profiler-java` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/google-cloud-profiler-java
commit-message: |-
Bump google-stackdriver-profiler-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bump google-cloud-profiler-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bumps google-stackdriver-profiler-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
Bumps google-cloud-profiler-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
delete-branch: true
labels: semver:minor, type:dependency-upgrade
signoff: true
title: Bump google-stackdriver-profiler-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
title: Bump google-cloud-profiler-java from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update google-stackdriver-profiler-nodejs
name: Update google-cloud-profiler-nodejs
"on":
schedule:
- cron: 0 5 * * 1-5
Expand Down Expand Up @@ -72,21 +72,21 @@ jobs:
echo "::set-output name=old-version::${OLD_VERSION}"
echo "::set-output name=new-version::${VERSION}"
env:
ID: google-stackdriver-profiler-nodejs
ID: google-cloud-profiler-nodejs
SHA256: ${{ steps.dependency.outputs.sha256 }}
URI: ${{ steps.dependency.outputs.uri }}
VERSION: ${{ steps.dependency.outputs.version }}
VERSION_PATTERN: '[\d]+\.[\d]+\.[\d]+'
- uses: peter-evans/create-pull-request@v3
with:
body: Bumps `google-stackdriver-profiler-nodejs` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/google-stackdriver-profiler-nodejs
body: Bumps `google-cloud-profiler-nodejs` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`.
branch: update/buildpack/google-cloud-profiler-nodejs
commit-message: |-
Bump google-stackdriver-profiler-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bump google-cloud-profiler-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
Bumps google-stackdriver-profiler-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
Bumps google-cloud-profiler-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}.
delete-branch: true
labels: semver:minor, type:dependency-upgrade
signoff: true
title: Bump google-stackdriver-profiler-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
title: Bump google-cloud-profiler-nodejs from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
google-stackdriver
google-cloud

Copyright (c) 2020-Present CloudFoundry.org Foundation, Inc. All Rights Reserved.

Expand Down
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
# `gcr.io/paketo-buildpacks/google-stackdriver`
The Paketo Google Stackdriver Buildpack is a Cloud Native Buildpack that contributes Stackdriver agents and configures them to connect to the service.
# `paketo-buildpacks/google-cloud`
The Paketo Google Cloud Buildpack is a Cloud Native Buildpack that contributes Google Cloud agents and configures them to connect to their services.

## Behavior
This buildpack will participate if any of the following conditions are met

* A binding exists with `type` of `StackdriverDebugger`
* A binding exists with `type` of `StackdriverProfiler`
* If `$BP_GOOGLE_CLOUD_DEBUGGER_ENABLED` is set to `true` and the application is Java
* At build time, contributes an agent to a layer
* At launch time, if credentials are available, configures the application to use the agent
* If `$BP_GOOGLE_CLOUD_DEBUGGER_ENABLED` is set to `true` and the application is NodeJS
* At build time, contributes an agent to a layer
* At launch time, if credentials are available, configures `$NODE_MODULES` with the agent path. If the main module does not already require `@google-cloud/debug-agent`, prepends the main module with `require('@google-cloud/debug-agent').start({...});`.

The buildpack will do the following for Java applications:
* If `$BP_GOOGLE_CLOUD_PROFILER_ENABLED` is set to `true` and the application is Java
* At build time, contributes an agent to a layer
* At launch time, if credentials are available, configures the application to use the agent
* If `$BP_GOOGLE_CLOUD_PROFILER_ENABLED` is set to `true` and the application is NodeJS
* At build time, contributes an agent to a layer
* At launch time, if credentials are available, configures `$NODE_MODULES` with the agent path. If the main module does not already require `@google-cloud/profiler`, prepends the main module with `require('@google-cloud/profiler').start({...});`.

* If `StackdriverDebugger` binding exists contributes a Java debugger agent to a layer and configures `$JAVA_TOOL_OPTIONS` to use it
* If `StackdriverProfiler` binding exists contributes a Java profiler agent to a layer and configures `$JAVA_TOOL_OPTIONS` to use it
* Sets `$GOOGLE_APPLICATION_CREDENTIALS` to the path of the `ApplicationCredentials` secret
### Credential Availability
If the applications runs within Google Cloud and the [Google Metadata Service][m] is accessible, those credentials will be used. If the application runs within any other environment, credentials must be provided with a service binding as described below.

The buildpack will do the following for NodeJS applications:

* If `StackdriverDebugger` binding exists
* Contributes a NodeJS debugger agent to a layer and configures `$NODE_MODULES` to use it
* If main module does not already require `@google-cloud/debug-agent` module, prepends the main module with `require('@google-cloud/debug-agent').start();`
* If `StackdriverProfiler` binding exists
* Contributes a NodeJS profiler agent to a layer and configures `$NODE_MODULES` to use it
* If main module does not already require `@google-cloud/profiler` module, prepends the main module with `require('@google-cloud/profiler').start();`
* Sets `$GOOGLE_APPLICATION_CREDENTIALS` to the path of the `ApplicationCredentials` secret
[m]: https://cloud.google.com/compute/docs/storing-retrieving-metadata

## Configuration
| Environment Variable | Description
| -------------------- | -----------
| `$BPL_GOOGLE_STACKDRIVER_MODULE` | Configure the name of the application. Defaults to `default-module`.
| `$BPL_GOOGLE_STACKDRIVER_VERSION` | Configure the project id for the application. Defaults to `<EMPTY>`.
| `$BPL_GOOGLE_STACKDRIVER_VERSION` | Configure the version of the application. Defaults to `<EMPTY>`.
| `$BP_GOOGLE_CLOUD_DEBUGGER_ENABLED` | Whether to add Google Cloud Debugger during build
| `$BP_GOOGLE_CLOUD_PROFILER_ENABLED` | Whether to add Google Cloud Profiler during build
| `$BPL_GOOGLE_CLOUD_MODULE` | Configure the name of the application (required)
| `$BPL_GOOGLE_CLOUD_PROJECT_ID` | Configure the project id for the application (required if running outside of Google Cloud)
| `$BPL_GOOGLE_CLOUD_VERSION` | Configure the version of the application (required)

## Bindings
The buildpack optionally accepts the following bindings:

### Type: `GoogleCloud`
|Key | Value | Description
|-------------------------|------------------|------------
|`ApplicationCredentials` | `<JSON Payload>` | Google Cloud Application Credentials in JSON form

### Type: `dependency-mapping`
|Key | Value | Description
|----------------------|---------|------------
Expand Down
Loading

0 comments on commit 1c37f23

Please sign in to comment.