forked from cloudfoundry/java-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Google Stackdriver Debugger Framework
This change adds support for the Google Stackdriver Debugger (https://cloud.google.com/debugger/) to the buildpack. It expects a bound service (google-stackdriver-debugger) with module and version credentials. [resolves cloudfoundry#405]
- Loading branch information
Showing
11 changed files
with
234 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Cloud Foundry Java Buildpack | ||
# Copyright 2013-2017 the original author or authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Configuration for the Groovy container | ||
--- | ||
version: 2.+ | ||
repository_root: "{default.repository.root}/google-stackdriver-debugger/{platform}/{architecture}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Google Stackdriver Debugger Framework | ||
The Google Stackdriver Debugger Framework causes an application to be automatically configured to work with a bound [Google Stackdriver Debugger Service][]. | ||
|
||
<table> | ||
<tr> | ||
<td><strong>Detection Criterion</strong></td><td>Existence of a single bound Google Stackdriver Debugger service. | ||
<ul> | ||
<li>Existence of a Google Stackdriver Debugger service is defined as the <a href="http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES"><code>VCAP_SERVICES</code></a> payload containing a service who's name, label or tag has <code>google-stackdriver-debugger</code> as a substring.</li> | ||
</ul> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><strong>Tags</strong></td> | ||
<td><tt>google-stackdriver-debugger=<version></tt></td> | ||
</tr> | ||
</table> | ||
Tags are printed to standard output by the buildpack detect script | ||
|
||
## User-Provided Service (Optional) | ||
Users may optionally provide their own Google Stackdriver Debugger service. A user-provided Google Stackdriver Debugger service must have a name or tag with `google-stackdriver-debugger` in it so that the Google Stackdriver Debugger Agent Framework will automatically configure the application to work with the service. | ||
|
||
The credential payload of the service must contain the following entry: | ||
|
||
| Name | Description | ||
| ---- | ----------- | ||
| `PrivateKeyData` | A Base64 encoded Service Account JSON payload | ||
|
||
## Configuration | ||
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][]. | ||
|
||
The framework can be configured by modifying the [`config/google_stackdriver_debugger.yml`][] file in the buildpack fork. The framework uses the [`Repository` utility support][repositories] and so it supports the [version syntax][] defined there. | ||
|
||
| Name | Description | ||
| ---- | ----------- | ||
| `repository_root` | The URL of the Google Stackdriver Debugger repository index ([details][repositories]). | ||
| `version` | The version of Google Stackdriver Debugger to use. Candidate versions can be found in [this listing][]. | ||
|
||
[Configuration and Extension]: ../README.md#configuration-and-extension | ||
[`config/google_stackdriver_debugger.yml`]: ../config/google_stackdriver_debugger.yml | ||
[Google Stackdriver Debugger Service]: https://cloud.google.com/debugger/ | ||
[repositories]: extending-repositories.md | ||
[this listing]: http://download.pivotal.io.s3.amazonaws.com/google-stackdriver-debugger/trusty/x86_64/index.yml | ||
[version syntax]: extending-repositories.md#version-syntax-and-ordering |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
lib/java_buildpack/framework/google_stackdriver_debugger.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Encoding: utf-8 | ||
# Cloud Foundry Java Buildpack | ||
# Copyright 2013-2017 the original author or authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require 'base64' | ||
require 'java_buildpack/component/versioned_dependency_component' | ||
require 'java_buildpack/framework' | ||
|
||
module JavaBuildpack | ||
module Framework | ||
|
||
# Encapsulates the functionality for enabling zero-touch Google Cloud Debugger support. | ||
class GoogleStackdriverDebugger < JavaBuildpack::Component::VersionedDependencyComponent | ||
|
||
# (see JavaBuildpack::Component::BaseComponent#compile) | ||
def compile | ||
download_tar false | ||
|
||
credentials = @application.services.find_service(FILTER)['credentials'] | ||
write_json_file credentials[PRIVATE_KEY_DATA] | ||
end | ||
|
||
# (see JavaBuildpack::Component::BaseComponent#release) | ||
def release | ||
java_opts = @droplet.java_opts | ||
|
||
java_opts | ||
.add_agentpath_with_props(@droplet.sandbox + 'cdbg_java_agent.so', '--logtostderr' => 1) | ||
.add_system_property('com.google.cdbg.auth.serviceaccount.enable', true) | ||
.add_system_property('com.google.cdbg.auth.serviceaccount.jsonfile', json_file) | ||
.add_system_property('com.google.cdbg.module', @application.details['application_name']) | ||
.add_system_property('com.google.cdbg.version', @application.details['application_version']) | ||
end | ||
|
||
protected | ||
|
||
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) | ||
def supports? | ||
@application.services.one_service? FILTER, PRIVATE_KEY_DATA | ||
end | ||
|
||
FILTER = /google-stackdriver-debugger/ | ||
|
||
PRIVATE_KEY_DATA = 'PrivateKeyData'.freeze | ||
|
||
private_constant :FILTER, :PRIVATE_KEY_DATA | ||
|
||
private | ||
|
||
def json_file | ||
@droplet.sandbox + 'svc.json' | ||
end | ||
|
||
def write_json_file(json_file_data) | ||
FileUtils.mkdir_p json_file.parent | ||
json_file.open(File::CREAT | File::WRONLY) do |f| | ||
f.write "#{Base64.decode64 json_file_data}\n" | ||
f.sync | ||
f | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
75 changes: 75 additions & 0 deletions
75
spec/java_buildpack/framework/google_stackdriver_debugger_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Encoding: utf-8 | ||
# Cloud Foundry Java Buildpack | ||
# Copyright 2013-2017 the original author or authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require 'spec_helper' | ||
require 'component_helper' | ||
require 'java_buildpack/framework/google_stackdriver_debugger' | ||
|
||
describe JavaBuildpack::Framework::GoogleStackdriverDebugger do | ||
include_context 'component_helper' | ||
|
||
it 'does not detect without google-stackdriver-debugger-n/a service' do | ||
expect(component.detect).to be_nil | ||
end | ||
|
||
context do | ||
|
||
before do | ||
allow(services).to receive(:one_service?) | ||
.with(/google-stackdriver-debugger/, 'PrivateKeyData').and_return(true) | ||
|
||
allow(services).to receive(:find_service).and_return( | ||
'credentials' => { | ||
'PrivateKeyData' => 'dGVzdC1wcml2YXRlLWtleS1kYXRh' | ||
} | ||
) | ||
end | ||
|
||
it 'detects with google-stackdriver-debugger-c-n/a service' do | ||
expect(component.detect).to eq("google-stackdriver-debugger=#{version}") | ||
end | ||
|
||
it 'unpacks the google stackdriver debugger tar', | ||
cache_fixture: 'stub-google-stackdriver-debugger.tar.gz' do | ||
|
||
component.compile | ||
|
||
expect(sandbox + 'cdbg_java_agent.so').to exist | ||
end | ||
|
||
it 'writes JSOn file', | ||
cache_fixture: 'stub-google-stackdriver-debugger.tar.gz' do | ||
|
||
component.compile | ||
|
||
expect(sandbox + 'svc.json').to exist | ||
expect(File.read(sandbox + 'svc.json')).to eq("test-private-key-data\n") | ||
end | ||
|
||
it 'updates JAVA_OPTS' do | ||
component.release | ||
expect(java_opts).to include('-agentpath:$PWD/.java-buildpack/google_stackdriver_debugger/cdbg_java_agent.so=' \ | ||
'--logtostderr=1') | ||
expect(java_opts).to include('-Dcom.google.cdbg.auth.serviceaccount.enable=true') | ||
expect(java_opts).to include('-Dcom.google.cdbg.auth.serviceaccount.jsonfile=' \ | ||
'$PWD/.java-buildpack/google_stackdriver_debugger/svc.json') | ||
expect(java_opts).to include('-Dcom.google.cdbg.module=test-application-name') | ||
expect(java_opts).to include('-Dcom.google.cdbg.version=test-application-version') | ||
end | ||
|
||
end | ||
|
||
end |