-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from paketo-buildpacks/dotnet-agent
Adds support for .NET agent with .Net Core apps
- Loading branch information
Showing
9 changed files
with
224 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ api = "0.7" | |
description = "A Cloud Native Buildpack that contributes the New Relic Agent and configures it to connect to the service" | ||
homepage = "https://github.com/paketo-buildpacks/new-relic" | ||
id = "paketo-buildpacks/new-relic" | ||
keywords = ["new-relic", "agent", "apm", "java", "node.js", "php", "python"] | ||
keywords = ["new-relic", "agent", "apm", "java", "node.js", "php", "python", "dotnet"] | ||
name = "Paketo Buildpack for New Relic" | ||
sbom-formats = ["application/vnd.syft+json", "application/vnd.cyclonedx+json"] | ||
version = "{{.version}}" | ||
|
@@ -91,6 +91,20 @@ api = "0.7" | |
[[metadata.dependencies.licenses]] | ||
uri = "https://docs.newrelic.com/docs/licenses/license-information" | ||
|
||
[[metadata.dependencies]] | ||
cpes = ["cpe:2.3:a:appdynamics:dotnet-agent:10.11.0:*:*:*:*:*:*:*"] | ||
id = "new-relic-dotnet" | ||
name = "New Relic Dotnet Agent" | ||
purl = "pkg:generic/[email protected]?arch=amd64" | ||
sha256 = "8a00aac013ea551b2f34e85dba2f9d5b097caf75e236eac45e26fbcb6d929d43" | ||
stacks = ["io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "*"] | ||
uri = "https://download.newrelic.com/dot_net_agent/latest_release/newrelic-dotnet-agent_10.11.0_amd64.tar.gz" | ||
version = "10.11.0" | ||
|
||
[[metadata.dependencies.licenses]] | ||
uri = "https://docs.newrelic.com/docs/licenses/license-information" | ||
|
||
|
||
[[stacks]] | ||
id = "io.buildpacks.stacks.bionic" | ||
|
||
|
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
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,70 @@ | ||
/* | ||
* Copyright 2018-2022 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
package newrelic | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/buildpacks/libcnb" | ||
"github.com/paketo-buildpacks/libpak" | ||
"github.com/paketo-buildpacks/libpak/bard" | ||
"github.com/paketo-buildpacks/libpak/crush" | ||
) | ||
|
||
type DotnetAgent struct { | ||
LayerContributor libpak.DependencyLayerContributor | ||
Logger bard.Logger | ||
} | ||
|
||
func NewDotnetAgent(dependency libpak.BuildpackDependency, cache libpak.DependencyCache) (DotnetAgent, libcnb.BOMEntry) { | ||
contributor, entry := libpak.NewDependencyLayer(dependency, cache, libcnb.LayerTypes{ | ||
Launch: true, | ||
}) | ||
return DotnetAgent{ | ||
LayerContributor: contributor, | ||
}, entry | ||
} | ||
|
||
func (d DotnetAgent) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { | ||
d.LayerContributor.Logger = d.Logger | ||
|
||
layer, err := d.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) { | ||
d.Logger.Bodyf("Expanding to %s", layer.Path) | ||
|
||
if err := crush.ExtractTarGz(artifact, layer.Path, 1); err != nil { | ||
return libcnb.Layer{}, fmt.Errorf("unable to expand New Relic\n%w", err) | ||
} | ||
|
||
layer.LaunchEnvironment.Default("CORECLR_NEWRELIC_HOME", layer.Path) | ||
layer.LaunchEnvironment.Default("CORECLR_ENABLE_PROFILING", "1") | ||
layer.LaunchEnvironment.Default("CORECLR_PROFILER", "{36032161-FFC0-4B61-B559-F6C5D41BAE5A}") | ||
layer.LaunchEnvironment.Default("CORECLR_PROFILER_PATH", filepath.Join(layer.Path, "libNewRelicProfiler.so")) | ||
|
||
return layer, nil | ||
}) | ||
if err != nil { | ||
return libcnb.Layer{}, fmt.Errorf("unable to contribute dotnet agent\n%w", err) | ||
} | ||
|
||
return layer, nil | ||
} | ||
|
||
func (n DotnetAgent) Name() string { | ||
return n.LayerContributor.LayerName() | ||
} |
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,73 @@ | ||
/* | ||
* Copyright 2018-2022 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
package newrelic_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/buildpacks/libcnb" | ||
. "github.com/onsi/gomega" | ||
"github.com/paketo-buildpacks/libpak" | ||
"github.com/sclevine/spec" | ||
|
||
"github.com/paketo-buildpacks/new-relic/v4/newrelic" | ||
) | ||
|
||
func testDotnetAgent(t *testing.T, context spec.G, it spec.S) { | ||
var ( | ||
Expect = NewWithT(t).Expect | ||
|
||
ctx libcnb.BuildContext | ||
) | ||
|
||
it.Before(func() { | ||
var err error | ||
|
||
ctx.Layers.Path, err = ioutil.TempDir("", "dotnet-agent-layers") | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
it.After(func() { | ||
Expect(os.RemoveAll(ctx.Layers.Path)).To(Succeed()) | ||
}) | ||
|
||
it("contributes Dotnet agent", func() { | ||
dep := libpak.BuildpackDependency{ | ||
URI: "https://localhost/stub-new-relic-agent.tar.gz", | ||
SHA256: "52d21d0eac639a8b5d47f52b0256a5acb94983282ecfa8f7a11bbaf85da77425", | ||
} | ||
dc := libpak.DependencyCache{CachePath: "testdata"} | ||
|
||
d, _ := newrelic.NewDotnetAgent(dep, dc) | ||
layer, err := ctx.Layers.Layer("test-layer") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
layer, err = d.Contribute(layer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(layer.Launch).To(BeTrue()) | ||
Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile()) | ||
|
||
Expect(layer.LaunchEnvironment["CORECLR_ENABLE_PROFILING.default"]).To(Equal("1")) | ||
Expect(layer.LaunchEnvironment["CORECLR_NEWRELIC_HOME.default"]).To(Equal(filepath.Join(layer.Path))) | ||
Expect(layer.LaunchEnvironment["CORECLR_PROFILER.default"]).To(Equal("{36032161-FFC0-4B61-B559-F6C5D41BAE5A}")) | ||
Expect(layer.LaunchEnvironment["CORECLR_PROFILER_PATH.default"]).To(Equal(filepath.Join(layer.Path, "libNewRelicProfiler.so"))) | ||
}) | ||
} |