diff --git a/.github/pipeline-descriptor.yml b/.github/pipeline-descriptor.yml index 8357286..a28e0ae 100644 --- a/.github/pipeline-descriptor.yml +++ b/.github/pipeline-descriptor.yml @@ -2,6 +2,9 @@ github: username: ${{ secrets.JAVA_GITHUB_USERNAME }} token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} +helpers: + "bin/helper": "$GOMOD/cmd/helper" + codeowners: - path: "*" owner: "@paketo-buildpacks/app-monitoring-maintainers" diff --git a/.github/workflows/pb-create-package.yml b/.github/workflows/pb-create-package.yml index 178c6a6..20cfb43 100644 --- a/.github/workflows/pb-create-package.yml +++ b/.github/workflows/pb-create-package.yml @@ -25,7 +25,7 @@ jobs: username: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }} - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version: "1.22" - name: Install create-package run: | #!/usr/bin/env bash @@ -33,13 +33,24 @@ jobs: set -euo pipefail go install -ldflags="-s -w" github.com/paketo-buildpacks/libpak/cmd/create-package@latest - - uses: buildpacks/github-actions/setup-tools@v5.5.3 + - uses: buildpacks/github-actions/setup-tools@v5.6.0 with: - crane-version: 0.19.0 + crane-version: 0.19.1 yj-version: 5.1.0 - - uses: buildpacks/github-actions/setup-pack@v5.5.3 - with: - pack-version: 0.33.2 + - name: Install pack + run: | + #!/usr/bin/env bash + # this is coming from a copy of https://github.com/buildpacks/pack/actions/runs/8118576298 stored on box + # TODO to revisit when the official one is out + set -euo pipefail + + echo "Installing pack experimental" + + mkdir -p "${HOME}"/bin + echo "${HOME}/bin" >> "${GITHUB_PATH}" + + curl -L "https://ent.box.com/shared/static/j4d1bfe9uk1sb0i7zjvci0md9xmy41u4" -o ${HOME}/bin/pack + chmod +x "${HOME}"/bin/pack - name: Enable pack Experimental if: ${{ false }} run: | @@ -106,21 +117,23 @@ jobs: if [[ "${INCLUDE_DEPENDENCIES}" == "true" ]]; then create-package \ - --source ${SOURCE_PATH:-.} \ + --source "${SOURCE_PATH:-.}" \ --cache-location "${HOME}"/carton-cache \ --destination "${HOME}"/buildpack \ --include-dependencies \ --version "${VERSION}" else create-package \ - --source ${SOURCE_PATH:-.} \ + --source "${SOURCE_PATH:-.}" \ --destination "${HOME}"/buildpack \ --version "${VERSION}" fi - PACKAGE_FILE=${SOURCE_PATH:-.}/package.toml - [[ -e ${PACKAGE_FILE} ]] && cp ${PACKAGE_FILE} "${HOME}"/package.toml - printf '[buildpack]\nuri = "%s"\n\n[platform]\nos = "%s"\n' "${HOME}"/buildpack "${OS}" >> "${HOME}"/package.toml + PACKAGE_FILE="${SOURCE_PATH:-.}/package.toml" + if [ -f "${PACKAGE_FILE}" ]; then + cp "${PACKAGE_FILE}" "${HOME}/buildpack/package.toml" + printf '[buildpack]\nuri = "%s"\n\n[platform]\nos = "%s"\n' "${HOME}/buildpack" "${OS}" >> "${HOME}/buildpack/package.toml" + fi env: INCLUDE_DEPENDENCIES: "false" OS: linux @@ -133,15 +146,23 @@ jobs: set -euo pipefail + COMPILED_BUILDPACK="${HOME}/buildpack" + + # create-package puts the buildpack here, we need to run from that directory + # for component buildpacks so that pack doesn't need a package.toml + cd "${COMPILED_BUILDPACK}" + CONFIG="" + if [ -f "${COMPILED_BUILDPACK}/package.toml" ]; then + CONFIG="--config ${COMPILED_BUILDPACK}/package.toml" + fi PACKAGE_LIST=($PACKAGES) # Extract first repo (Docker Hub) as the main to package & register PACKAGE=${PACKAGE_LIST[0]} if [[ "${PUBLISH:-x}" == "true" ]]; then - pack buildpack package \ - "${PACKAGE}:${VERSION}" \ - --config "${HOME}"/package.toml \ + pack -v buildpack package \ + "${PACKAGE}:${VERSION}" ${CONFIG} \ --publish if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then @@ -165,10 +186,9 @@ jobs: done else - pack buildpack package \ - "${PACKAGE}:${VERSION}" \ - --config "${HOME}"/package.toml \ - --format "${FORMAT}" + pack -v buildpack package \ + "${PACKAGE}:${VERSION}" ${CONFIG} \ + --format "${FORMAT}" $([ -n "$TTL_SH_PUBLISH" ] && [ "$TTL_SH_PUBLISH" = "true" ] && echo "--publish") fi env: PACKAGES: docker.io/paketobuildpacks/jprofiler gcr.io/paketo-buildpacks/jprofiler @@ -199,7 +219,7 @@ jobs: DIGEST: ${{ steps.package.outputs.digest }} GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} - if: ${{ true }} - uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:4.0.1 + uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:5.6.0 with: address: docker.io/paketobuildpacks/jprofiler@${{ steps.package.outputs.digest }} id: paketo-buildpacks/jprofiler diff --git a/.github/workflows/pb-tests.yml b/.github/workflows/pb-tests.yml index 6adcf4e..3f2fddb 100644 --- a/.github/workflows/pb-tests.yml +++ b/.github/workflows/pb-tests.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version: "1.22" - name: Install create-package run: | #!/usr/bin/env bash @@ -25,9 +25,20 @@ jobs: set -euo pipefail go install -ldflags="-s -w" github.com/paketo-buildpacks/libpak/cmd/create-package@latest - - uses: buildpacks/github-actions/setup-pack@v5.5.3 - with: - pack-version: 0.33.2 + - name: Install pack + run: | + #!/usr/bin/env bash + # this is coming from a copy of https://github.com/buildpacks/pack/actions/runs/8118576298 stored on box + # TODO to revisit when the official one is out + set -euo pipefail + + echo "Installing pack experimental" + + mkdir -p "${HOME}"/bin + echo "${HOME}/bin" >> "${GITHUB_PATH}" + + curl -L "https://ent.box.com/shared/static/j4d1bfe9uk1sb0i7zjvci0md9xmy41u4" -o ${HOME}/bin/pack + chmod +x "${HOME}"/bin/pack - name: Enable pack Experimental if: ${{ false }} run: | @@ -93,21 +104,23 @@ jobs: if [[ "${INCLUDE_DEPENDENCIES}" == "true" ]]; then create-package \ - --source ${SOURCE_PATH:-.} \ + --source "${SOURCE_PATH:-.}" \ --cache-location "${HOME}"/carton-cache \ --destination "${HOME}"/buildpack \ --include-dependencies \ --version "${VERSION}" else create-package \ - --source ${SOURCE_PATH:-.} \ + --source "${SOURCE_PATH:-.}" \ --destination "${HOME}"/buildpack \ --version "${VERSION}" fi - PACKAGE_FILE=${SOURCE_PATH:-.}/package.toml - [[ -e ${PACKAGE_FILE} ]] && cp ${PACKAGE_FILE} "${HOME}"/package.toml - printf '[buildpack]\nuri = "%s"\n\n[platform]\nos = "%s"\n' "${HOME}"/buildpack "${OS}" >> "${HOME}"/package.toml + PACKAGE_FILE="${SOURCE_PATH:-.}/package.toml" + if [ -f "${PACKAGE_FILE}" ]; then + cp "${PACKAGE_FILE}" "${HOME}/buildpack/package.toml" + printf '[buildpack]\nuri = "%s"\n\n[platform]\nos = "%s"\n' "${HOME}/buildpack" "${OS}" >> "${HOME}/buildpack/package.toml" + fi env: INCLUDE_DEPENDENCIES: "true" OS: linux @@ -118,15 +131,23 @@ jobs: set -euo pipefail + COMPILED_BUILDPACK="${HOME}/buildpack" + + # create-package puts the buildpack here, we need to run from that directory + # for component buildpacks so that pack doesn't need a package.toml + cd "${COMPILED_BUILDPACK}" + CONFIG="" + if [ -f "${COMPILED_BUILDPACK}/package.toml" ]; then + CONFIG="--config ${COMPILED_BUILDPACK}/package.toml" + fi PACKAGE_LIST=($PACKAGES) # Extract first repo (Docker Hub) as the main to package & register PACKAGE=${PACKAGE_LIST[0]} if [[ "${PUBLISH:-x}" == "true" ]]; then - pack buildpack package \ - "${PACKAGE}:${VERSION}" \ - --config "${HOME}"/package.toml \ + pack -v buildpack package \ + "${PACKAGE}:${VERSION}" ${CONFIG} \ --publish if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then @@ -150,14 +171,14 @@ jobs: done else - pack buildpack package \ - "${PACKAGE}:${VERSION}" \ - --config "${HOME}"/package.toml \ - --format "${FORMAT}" + pack -v buildpack package \ + "${PACKAGE}:${VERSION}" ${CONFIG} \ + --format "${FORMAT}" $([ -n "$TTL_SH_PUBLISH" ] && [ "$TTL_SH_PUBLISH" = "true" ] && echo "--publish") fi env: FORMAT: image PACKAGES: test + TTL_SH_PUBLISH: "false" VERSION: ${{ steps.version.outputs.version }} unit: name: Unit Test @@ -172,7 +193,7 @@ jobs: restore-keys: ${{ runner.os }}-go- - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version: "1.22" - name: Install richgo run: | #!/usr/bin/env bash diff --git a/.github/workflows/pb-update-go.yml b/.github/workflows/pb-update-go.yml index 2c33969..3c91606 100644 --- a/.github/workflows/pb-update-go.yml +++ b/.github/workflows/pb-update-go.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version: "1.22" - uses: actions/checkout@v4 - name: Update Go Version & Modules id: update-go @@ -49,7 +49,7 @@ jobs: echo "commit-body=${COMMIT_BODY}" >> "$GITHUB_OUTPUT" echo "commit-semver=${COMMIT_SEMVER}" >> "$GITHUB_OUTPUT" env: - GO_VERSION: "1.20" + GO_VERSION: "1.22" - uses: peter-evans/create-pull-request@v6 with: author: ${{ secrets.JAVA_GITHUB_USERNAME }} <${{ secrets.JAVA_GITHUB_USERNAME }}@users.noreply.github.com> diff --git a/.github/workflows/pb-update-jprofiler.yml b/.github/workflows/pb-update-jprofiler.yml index 9079bc8..46f9aa1 100644 --- a/.github/workflows/pb-update-jprofiler.yml +++ b/.github/workflows/pb-update-jprofiler.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version: "1.22" - name: Install update-buildpack-dependency run: | #!/usr/bin/env bash @@ -19,9 +19,9 @@ jobs: set -euo pipefail go install -ldflags="-s -w" github.com/paketo-buildpacks/libpak/cmd/update-buildpack-dependency@latest - - uses: buildpacks/github-actions/setup-tools@v5.5.3 + - uses: buildpacks/github-actions/setup-tools@v5.6.0 with: - crane-version: 0.19.0 + crane-version: 0.19.1 yj-version: 5.1.0 - uses: actions/checkout@v4 - id: dependency diff --git a/.github/workflows/pb-update-pipeline.yml b/.github/workflows/pb-update-pipeline.yml index a80569f..2c05223 100644 --- a/.github/workflows/pb-update-pipeline.yml +++ b/.github/workflows/pb-update-pipeline.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: "1.20" + go-version: "1.22" - name: Install octo run: | #!/usr/bin/env bash @@ -55,6 +55,12 @@ jobs: ) git add .github/ + git add .gitignore + + if [ -f scripts/build.sh ]; then + git add scripts/build.sh + fi + git checkout -- . echo "old-version=${OLD_VERSION}" >> "$GITHUB_OUTPUT" diff --git a/.gitignore b/.gitignore index b90fc75..2f65ee4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# Copyright 2018-2022 the original author or authors. +# Copyright 2018-2020 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. @@ -13,6 +13,8 @@ # limitations under the License. bin/ +linux/ dependencies/ package/ scratch/ + diff --git a/buildpack.toml b/buildpack.toml index 3557e38..e440157 100644 --- a/buildpack.toml +++ b/buildpack.toml @@ -1,4 +1,4 @@ -# Copyright 2018-2022 the original author or authors. +# Copyright 2018-2024 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. @@ -28,7 +28,7 @@ api = "0.7" uri = "https://github.com/paketo-buildpacks/jprofiler/blob/main/LICENSE" [metadata] - include-files = ["LICENSE", "NOTICE", "README.md", "jprofiler.png", "bin/build", "bin/detect", "bin/helper", "bin/main", "buildpack.toml"] + include-files = ["LICENSE", "NOTICE", "README.md", "linux/amd64/bin/build", "linux/amd64/bin/detect", "linux/amd64/bin/main", "linux/amd64/bin/helper", "linux/arm64/bin/build", "linux/arm64/bin/detect", "linux/arm64/bin/main", "linux/arm64/bin/helper", "buildpack.toml"] pre-package = "scripts/build.sh" [[metadata.configurations]] @@ -57,9 +57,9 @@ api = "0.7" cpes = ["cpe:2.3:a:jprofiler:agent:14.0.3:*:*:*:*:*:*:*"] id = "jprofiler" name = "JProfiler Agent" - purl = "pkg:generic/jprofiler-agent@14.0.3?arch=amd64" + purl = "pkg:generic/jprofiler-agent@14.0.3" sha256 = "60a878023e5b77b13b7e545a0abaed5cb2a8111374c0f56032a26fb0b2acee05" - stacks = ["io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "*"] + stacks = ["*"] uri = "https://download-gcdn.ej-technologies.com/jprofiler/jprofiler_linux_14_0_3.tar.gz" version = "14.0.3" @@ -67,10 +67,12 @@ api = "0.7" uri = "https://www.ej-technologies.com/buy/jprofiler/licensing.html" [[stacks]] - id = "io.buildpacks.stacks.bionic" + id = "*" -[[stacks]] - id = "io.paketo.stacks.tiny" +[[targets]] + arch = "amd64" + os = "linux" -[[stacks]] - id = "*" +[[targets]] + arch = "arm64" + os = "linux" diff --git a/jprofiler/build_test.go b/jprofiler/build_test.go index c9f7e57..1d49aa8 100644 --- a/jprofiler/build_test.go +++ b/jprofiler/build_test.go @@ -34,6 +34,10 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { ctx libcnb.BuildContext ) + it.Before(func() { + t.Setenv("BP_ARCH", "amd64") + }) + it("contributes Java agent API <= 0.6", func() { ctx.Buildpack.Metadata = map[string]interface{}{ "dependencies": []map[string]interface{}{ diff --git a/jprofiler/java_agent.go b/jprofiler/java_agent.go index 796cdf3..01d3af8 100644 --- a/jprofiler/java_agent.go +++ b/jprofiler/java_agent.go @@ -20,6 +20,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "github.com/buildpacks/libcnb" "github.com/paketo-buildpacks/libpak" @@ -45,12 +46,13 @@ func (j JavaAgent) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { return j.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) { j.Logger.Bodyf("Expanding to %s", layer.Path) - if err := crush.ExtractTarGz(artifact, layer.Path, 1); err != nil { + if err := crush.Extract(artifact, layer.Path, 1); err != nil { return libcnb.Layer{}, fmt.Errorf("unable to expand JProfiler\n%w", err) } + arch := archForAgent() layer.LaunchEnvironment.Default("BPI_JPROFILER_AGENT_PATH", - filepath.Join(layer.Path, "bin", "linux-x64", "libjprofilerti.so")) + filepath.Join(layer.Path, "bin", fmt.Sprintf("linux-%s", arch), "libjprofilerti.so")) return layer, nil }) @@ -59,3 +61,18 @@ func (j JavaAgent) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { func (j JavaAgent) Name() string { return j.LayerContributor.LayerName() } + +func archForAgent() string { + archFromEnv, ok := os.LookupEnv("BP_ARCH") + if !ok { + archFromEnv = runtime.GOARCH + } + + if archFromEnv == "amd64" { + return "x64" + } else if archFromEnv == "arm64" { + return "aarch64" + } else { + return archFromEnv + } +} diff --git a/jprofiler/java_agent_test.go b/jprofiler/java_agent_test.go index 3a90a6e..637847e 100644 --- a/jprofiler/java_agent_test.go +++ b/jprofiler/java_agent_test.go @@ -17,7 +17,6 @@ package jprofiler_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -40,7 +39,7 @@ func testJavaAgent(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - ctx.Layers.Path, err = ioutil.TempDir("", "java-agent-layers") + ctx.Layers.Path = t.TempDir() Expect(err).NotTo(HaveOccurred()) }) @@ -48,23 +47,55 @@ func testJavaAgent(t *testing.T, context spec.G, it spec.S) { Expect(os.RemoveAll(ctx.Layers.Path)).To(Succeed()) }) - it("contributes Java agent", func() { - dep := libpak.BuildpackDependency{ - URI: "https://localhost/stub-jprofiler-agent.tar.gz", - SHA256: "9ec6fd679560481ff82d59397ffa289028e2c68df41802d172b35884b84b304d", - } - dc := libpak.DependencyCache{CachePath: "testdata"} + context("BP_ARCH=amd64", func() { + it.Before(func() { + t.Setenv("BP_ARCH", "amd64") + }) - j, _ := jprofiler.NewJavaAgent(dep, dc) - layer, err := ctx.Layers.Layer("test-layer") - Expect(err).NotTo(HaveOccurred()) + it("contributes Java agent", func() { + dep := libpak.BuildpackDependency{ + URI: "https://localhost/stub-jprofiler-agent.tar.gz", + SHA256: "9ec6fd679560481ff82d59397ffa289028e2c68df41802d172b35884b84b304d", + } + dc := libpak.DependencyCache{CachePath: "testdata"} - layer, err = j.Contribute(layer) - Expect(err).NotTo(HaveOccurred()) + j, _ := jprofiler.NewJavaAgent(dep, dc) + layer, err := ctx.Layers.Layer("test-layer") + Expect(err).NotTo(HaveOccurred()) + + layer, err = j.Contribute(layer) + Expect(err).NotTo(HaveOccurred()) + + Expect(layer.Launch).To(BeTrue()) + Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile()) + Expect(layer.LaunchEnvironment["BPI_JPROFILER_AGENT_PATH.default"]).To( + Equal(filepath.Join(layer.Path, "bin", "linux-x64", "libjprofilerti.so"))) + }) + }) + + context("BP_ARCH=arm64", func() { + it.Before(func() { + t.Setenv("BP_ARCH", "arm64") + }) + + it("contributes Java agent", func() { + dep := libpak.BuildpackDependency{ + URI: "https://localhost/stub-jprofiler-agent.tar.gz", + SHA256: "9ec6fd679560481ff82d59397ffa289028e2c68df41802d172b35884b84b304d", + } + dc := libpak.DependencyCache{CachePath: "testdata"} + + j, _ := jprofiler.NewJavaAgent(dep, dc) + layer, err := ctx.Layers.Layer("test-layer") + Expect(err).NotTo(HaveOccurred()) + + layer, err = j.Contribute(layer) + Expect(err).NotTo(HaveOccurred()) - Expect(layer.Launch).To(BeTrue()) - Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile()) - Expect(layer.LaunchEnvironment["BPI_JPROFILER_AGENT_PATH.default"]).To( - Equal(filepath.Join(layer.Path, "bin", "linux-x64", "libjprofilerti.so"))) + Expect(layer.Launch).To(BeTrue()) + Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile()) + Expect(layer.LaunchEnvironment["BPI_JPROFILER_AGENT_PATH.default"]).To( + Equal(filepath.Join(layer.Path, "bin", "linux-aarch64", "libjprofilerti.so"))) + }) }) } diff --git a/scripts/build.sh b/scripts/build.sh index 472969f..9b05e98 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,17 +1,23 @@ #!/usr/bin/env bash - set -euo pipefail -GOOS="linux" go build -ldflags='-s -w' -o bin/helper github.com/paketo-buildpacks/jprofiler/v4/cmd/helper -GOOS="linux" go build -ldflags='-s -w' -o bin/main github.com/paketo-buildpacks/jprofiler/v4/cmd/main +GOMOD=$(head -1 go.mod | awk '{print $2}') +GOOS="linux" GOARCH="amd64" go build -ldflags='-s -w' -o "linux/amd64/bin/helper" "$GOMOD/cmd/helper" +GOOS="linux" GOARCH="arm64" go build -ldflags='-s -w' -o "linux/arm64/bin/helper" "$GOMOD/cmd/helper" +GOOS="linux" GOARCH="amd64" go build -ldflags='-s -w' -o linux/amd64/bin/main "$GOMOD/cmd/main" +GOOS="linux" GOARCH="arm64" go build -ldflags='-s -w' -o linux/arm64/bin/main "$GOMOD/cmd/main" if [ "${STRIP:-false}" != "false" ]; then - strip bin/helper bin/main + strip linux/amd64/bin/helper linux/arm64/bin/helper + strip linux/amd64/bin/main linux/arm64/bin/main fi -if [ "${COMPRESS:-false}" != "false" ]; then - upx -q -9 bin/helper bin/main +if [ "${COMPRESS:-none}" != "none" ]; then + $COMPRESS linux/amd64/bin/helper linux/arm64/bin/helper + $COMPRESS linux/amd64/bin/main linux/arm64/bin/main fi -ln -fs main bin/build -ln -fs main bin/detect +ln -fs main linux/amd64/bin/build +ln -fs main linux/arm64/bin/build +ln -fs main linux/amd64/bin/detect +ln -fs main linux/arm64/bin/detect \ No newline at end of file