diff --git a/.github/pipeline-descriptor.yml b/.github/pipeline-descriptor.yml index eb96451..0834a40 100644 --- a/.github/pipeline-descriptor.yml +++ b/.github/pipeline-descriptor.yml @@ -24,7 +24,18 @@ dependencies: id: jattach uses: docker://ghcr.io/paketo-buildpacks/actions/github-release-dependency:main with: - glob: jattach + glob: jattach-linux-x64.tgz + owner: apangin + repository: jattach + tag_filter: v([\d.]*) + token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} + +# ARM64 +- name: jattach ARM64 + id: jattach + uses: docker://ghcr.io/paketo-buildpacks/actions/github-release-dependency:main + with: + glob: jattach-linux-arm64.tgz owner: apangin repository: jattach tag_filter: v([\d.]*) diff --git a/.github/workflows/pb-update-jattach-arm-64.yml b/.github/workflows/pb-update-jattach-arm-64.yml new file mode 100644 index 0000000..b8ec043 --- /dev/null +++ b/.github/workflows/pb-update-jattach-arm-64.yml @@ -0,0 +1,121 @@ +name: Update jattach ARM64 +"on": + schedule: + - cron: 0 5 * * 1-5 + workflow_dispatch: {} +jobs: + update: + name: Update Buildpack Dependency + runs-on: + - ubuntu-latest + steps: + - uses: actions/setup-go@v5 + with: + go-version: "1.20" + - name: Install update-buildpack-dependency + run: | + #!/usr/bin/env bash + + set -euo pipefail + + go install -ldflags="-s -w" github.com/paketo-buildpacks/libpak/cmd/update-buildpack-dependency@latest + - name: Install yj + run: | + #!/usr/bin/env bash + + set -euo pipefail + + echo "Installing yj ${YJ_VERSION}" + + mkdir -p "${HOME}"/bin + echo "${HOME}/bin" >> "${GITHUB_PATH}" + + curl \ + --location \ + --show-error \ + --silent \ + --output "${HOME}"/bin/yj \ + "https://github.com/sclevine/yj/releases/download/v${YJ_VERSION}/yj-linux-amd64" + + chmod +x "${HOME}"/bin/yj + env: + YJ_VERSION: 5.1.0 + - uses: actions/checkout@v4 + - id: dependency + uses: docker://ghcr.io/paketo-buildpacks/actions/github-release-dependency:main + with: + glob: jattach-linux-arm64.tgz + owner: apangin + repository: jattach + tag_filter: v([\d.]*) + token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} + - name: Update Buildpack Dependency + id: buildpack + run: | + #!/usr/bin/env bash + + set -euo pipefail + + if [ -z "${ARCH}" ]; then + ARCH="amd64" + fi + + OLD_VERSION=$(yj -tj < buildpack.toml | \ + jq -r ".metadata.dependencies[] | select( .id == env.ID ) | select( .version | test( env.VERSION_PATTERN ) ) | select( .purl | contains( env.ARCH ) ) | .version") + + update-buildpack-dependency \ + --buildpack-toml buildpack.toml \ + --id "${ID}" \ + --arch "${ARCH}" \ + --version-pattern "${VERSION_PATTERN}" \ + --version "${VERSION}" \ + --cpe-pattern "${CPE_PATTERN:-}" \ + --cpe "${CPE:-}" \ + --purl-pattern "${PURL_PATTERN:-}" \ + --purl "${PURL:-}" \ + --uri "${URI}" \ + --sha256 "${SHA256}" \ + --source "${SOURCE_URI}" \ + --source-sha256 "${SOURCE_SHA256}" + + git add buildpack.toml + git checkout -- . + + if [ "$(echo "$OLD_VERSION" | awk -F '.' '{print $1}')" != "$(echo "$VERSION" | awk -F '.' '{print $1}')" ]; then + LABEL="semver:major" + elif [ "$(echo "$OLD_VERSION" | awk -F '.' '{print $2}')" != "$(echo "$VERSION" | awk -F '.' '{print $2}')" ]; then + LABEL="semver:minor" + else + LABEL="semver:patch" + fi + + echo "old-version=${OLD_VERSION}" >> "$GITHUB_OUTPUT" + echo "new-version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "version-label=${LABEL}" >> "$GITHUB_OUTPUT" + env: + ARCH: "" + CPE: ${{ steps.dependency.outputs.cpe }} + CPE_PATTERN: "" + ID: jattach + PURL: ${{ steps.dependency.outputs.purl }} + PURL_PATTERN: "" + SHA256: ${{ steps.dependency.outputs.sha256 }} + SOURCE_SHA256: ${{ steps.dependency.outputs.source_sha256 }} + SOURCE_URI: ${{ steps.dependency.outputs.source }} + URI: ${{ steps.dependency.outputs.uri }} + VERSION: ${{ steps.dependency.outputs.version }} + VERSION_PATTERN: '[\d]+\.[\d]+\.[\d]+' + - uses: peter-evans/create-pull-request@v5 + with: + author: ${{ secrets.JAVA_GITHUB_USERNAME }} <${{ secrets.JAVA_GITHUB_USERNAME }}@users.noreply.github.com> + body: Bumps `jattach ARM64` from `${{ steps.buildpack.outputs.old-version }}` to `${{ steps.buildpack.outputs.new-version }}`. + branch: update/buildpack/jattach-arm-64 + commit-message: |- + Bump jattach ARM64 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }} + + Bumps jattach ARM64 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }}. + delete-branch: true + labels: ${{ steps.buildpack.outputs.version-label }}, type:dependency-upgrade + signoff: true + title: Bump jattach ARM64 from ${{ steps.buildpack.outputs.old-version }} to ${{ steps.buildpack.outputs.new-version }} + token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} diff --git a/.github/workflows/pb-update-jattach.yml b/.github/workflows/pb-update-jattach.yml index 98ea51b..b0aab87 100644 --- a/.github/workflows/pb-update-jattach.yml +++ b/.github/workflows/pb-update-jattach.yml @@ -44,7 +44,7 @@ jobs: - id: dependency uses: docker://ghcr.io/paketo-buildpacks/actions/github-release-dependency:main with: - glob: jattach + glob: jattach-linux-x64.tgz owner: apangin repository: jattach tag_filter: v([\d.]*) diff --git a/buildpack.toml b/buildpack.toml index df7df46..dbd11d5 100644 --- a/buildpack.toml +++ b/buildpack.toml @@ -1,4 +1,4 @@ -# Copyright 2018-2021 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. @@ -42,22 +42,32 @@ api = "0.7" id = "jattach" name = "JAttach" purl = "pkg:generic/jattach@2.2.0?arch=amd64" - sha256 = "a08cb795a1e8d11ea6c2dd6adf8c9edead9a7c3bbca07681dad79cc3eaec0ef4" + sha256 = "acd9e17f15749306be843df392063893e97bfecc5260eef73ee98f06e5cfe02f" source = "https://github.com/apangin/jattach/archive/refs/tags/v2.2.tar.gz" source-sha256 = "dc29ebb4fe795a026698fd77d04072cfb39295276a541cfc5e77d20b1509a1cf" - stacks = ["io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "*"] - uri = "https://github.com/jattach/jattach/releases/download/v2.2/jattach" + stacks = ["*"] + uri = "https://github.com/jattach/jattach/releases/download/v2.2/jattach-linux-x64.tgz" version = "2.2.0" [[metadata.dependencies.licenses]] type = "Apache-2.0" uri = "https://github.com/apangin/jattach/blob/master/LICENSE" -[[stacks]] - id = "io.buildpacks.stacks.bionic" + [[metadata.dependencies]] + cpes = ["cpe:2.3:a:apangin:jattach:2.2.0:*:*:*:*:*:*:*"] + id = "jattach" + name = "JAttach" + purl = "pkg:generic/jattach@2.2.0?arch=arm64" + sha256 = "288ae5ed87ee7fe0e608c06db5a23a096a6217c9878ede53c4e33710bdcaab51" + source = "https://github.com/apangin/jattach/archive/refs/tags/v2.2.tar.gz" + source-sha256 = "dc29ebb4fe795a026698fd77d04072cfb39295276a541cfc5e77d20b1509a1cf" + stacks = ["*"] + uri = "https://github.com/jattach/jattach/releases/download/v2.2/jattach-linux-arm64.tgz" + version = "2.2.0" -[[stacks]] - id = "io.paketo.stacks.tiny" + [[metadata.dependencies.licenses]] + type = "Apache-2.0" + uri = "https://github.com/apangin/jattach/blob/master/LICENSE" [[stacks]] id = "*" diff --git a/go.mod b/go.mod index 9791a75..a394b58 100644 --- a/go.mod +++ b/go.mod @@ -14,11 +14,13 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/creack/pty v1.1.21 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/h2non/filetype v1.1.3 // indirect github.com/heroku/color v0.0.6 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect + github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect golang.org/x/net v0.20.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/go.sum b/go.sum index 4adf99c..e010425 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= +github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= +github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/heroku/color v0.0.6 h1:UTFFMrmMLFcL3OweqP1lAdp8i1y/9oHqkeHjQ/b/Ny0= github.com/heroku/color v0.0.6/go.mod h1:ZBvOcx7cTF2QKOv4LbmoBtNl5uB17qWxGuzZrsi1wLU= github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= @@ -36,6 +38,8 @@ github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8= github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM= github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= +github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/jattach/build_test.go b/jattach/build_test.go index 6079413..7fa3611 100644 --- a/jattach/build_test.go +++ b/jattach/build_test.go @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 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. @@ -17,8 +17,6 @@ package jattach_test import ( - "io/ioutil" - "os" "testing" "github.com/paketo-buildpacks/jattach/jattach" @@ -39,9 +37,11 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - ctx.Application.Path, err = ioutil.TempDir("", "build") + ctx.Application.Path = t.TempDir() Expect(err).NotTo(HaveOccurred()) + t.Setenv("BP_ARCH", "amd64") + ctx.Plan.Entries = append(ctx.Plan.Entries, libcnb.BuildpackPlanEntry{Name: "jattach"}) ctx.Buildpack.Metadata = map[string]interface{}{ "dependencies": []map[string]interface{}{ @@ -49,40 +49,15 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { "id": "jattach", "version": "1.0.0", "stacks": []interface{}{"test-stack-id"}, + "cpes": []string{"cpe:2.3:a:jattach:jattach:1.0.0:*:*:*:*:*:*:*"}, + "purl": "pkg:generic/jattach@1.0.0?arch=amd64", }, }, } ctx.StackID = "test-stack-id" }) - it.After(func() { - Expect(os.RemoveAll(ctx.Application.Path)).To(Succeed()) - }) - - it("contributes JAttach for API <= 0.6", func() { - ctx.Buildpack.API = "0.6" - - result, err := build.Build(ctx) - Expect(err).NotTo(HaveOccurred()) - - Expect(result.Layers).To(HaveLen(1)) - Expect(result.Layers[0].Name()).To(Equal("jattach")) - - Expect(result.BOM.Entries).To(HaveLen(1)) - Expect(result.BOM.Entries[0].Name).To(Equal("jattach")) - }) - it("contributes JAttach for API 0.7+", func() { - ctx.Buildpack.Metadata = map[string]interface{}{ - "dependencies": []map[string]interface{}{ - { - "id": "jattach", - "version": "1.0.0", - "stacks": []interface{}{"test-stack-id"}, - "cpes": []string{"cpe:2.3:a:jattach:jattach:1.17.1:*:*:*:*:*:*:*"}, - "purl": "pkg:generic/jattach@1.0.0?arch=amd64", - }, - }, - } + it("contributes JAttach", func() { result, err := build.Build(ctx) Expect(err).NotTo(HaveOccurred()) diff --git a/jattach/jattach.go b/jattach/jattach.go index 5124e75..62b8642 100644 --- a/jattach/jattach.go +++ b/jattach/jattach.go @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 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. @@ -21,7 +21,7 @@ import ( "os" "path/filepath" - "github.com/paketo-buildpacks/libpak/sherpa" + "github.com/paketo-buildpacks/libpak/crush" "github.com/buildpacks/libcnb" "github.com/paketo-buildpacks/libpak" @@ -44,7 +44,6 @@ func (j JAttach) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { j.LayerContributor.Logger = j.Logger return j.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) { - binDir := filepath.Join(layer.Path, "bin") if err := os.MkdirAll(binDir, 0755); err != nil { @@ -52,11 +51,11 @@ func (j JAttach) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { } j.Logger.Bodyf("Copying to %s", binDir) - file := filepath.Join(binDir, filepath.Base(artifact.Name())) - if err := sherpa.CopyFile(artifact, file); err != nil { - return libcnb.Layer{}, fmt.Errorf("unable to copy %s to %s\n%w", artifact.Name(), file, err) + if err := crush.Extract(artifact, binDir, 0); err != nil { + return libcnb.Layer{}, fmt.Errorf("unable to expand jattach\n%w", err) } + file := filepath.Join(binDir, "jattach") if err := os.Chmod(file, 0755); err != nil { return libcnb.Layer{}, fmt.Errorf("unable to chmod %s\n%w", file, err) } diff --git a/jattach/jattach_test.go b/jattach/jattach_test.go index f0a2a44..98d7cf4 100644 --- a/jattach/jattach_test.go +++ b/jattach/jattach_test.go @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 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. @@ -17,8 +17,6 @@ package jattach_test import ( - "io/ioutil" - "os" "path/filepath" "testing" @@ -41,18 +39,14 @@ func testJAttach(t *testing.T, context spec.G, it spec.S) { it.Before(func() { var err error - ctx.Layers.Path, err = ioutil.TempDir("", "jattach-layers") + ctx.Layers.Path = t.TempDir() Expect(err).NotTo(HaveOccurred()) }) - it.After(func() { - Expect(os.RemoveAll(ctx.Layers.Path)).To(Succeed()) - }) - it("contributes JAttach", func() { dep := libpak.BuildpackDependency{ - URI: "https://localhost/jattach", - SHA256: "24d462459f142b1e1465eca49989cad4389d66d7167c6d5f5b2ac89502cec380", + URI: "https://localhost/jattach.tgz", + SHA256: "61f13e4c60ad63295453a5e1c92e04ad34bab09871b622b5aac0e72236431000", } dc := libpak.DependencyCache{CachePath: "testdata"} diff --git a/jattach/testdata/24d462459f142b1e1465eca49989cad4389d66d7167c6d5f5b2ac89502cec380.toml b/jattach/testdata/24d462459f142b1e1465eca49989cad4389d66d7167c6d5f5b2ac89502cec380.toml deleted file mode 100644 index d5253f8..0000000 --- a/jattach/testdata/24d462459f142b1e1465eca49989cad4389d66d7167c6d5f5b2ac89502cec380.toml +++ /dev/null @@ -1,2 +0,0 @@ -uri = "https://localhost/jattach" -sha256 = "24d462459f142b1e1465eca49989cad4389d66d7167c6d5f5b2ac89502cec380" diff --git a/jattach/testdata/24d462459f142b1e1465eca49989cad4389d66d7167c6d5f5b2ac89502cec380/jattach b/jattach/testdata/24d462459f142b1e1465eca49989cad4389d66d7167c6d5f5b2ac89502cec380/jattach deleted file mode 100644 index d2b60ac..0000000 --- a/jattach/testdata/24d462459f142b1e1465eca49989cad4389d66d7167c6d5f5b2ac89502cec380/jattach +++ /dev/null @@ -1 +0,0 @@ -jattach diff --git a/jattach/testdata/61f13e4c60ad63295453a5e1c92e04ad34bab09871b622b5aac0e72236431000.toml b/jattach/testdata/61f13e4c60ad63295453a5e1c92e04ad34bab09871b622b5aac0e72236431000.toml new file mode 100644 index 0000000..53ce57b --- /dev/null +++ b/jattach/testdata/61f13e4c60ad63295453a5e1c92e04ad34bab09871b622b5aac0e72236431000.toml @@ -0,0 +1,2 @@ +uri = "https://localhost/jattach.tgz" +sha256 = "61f13e4c60ad63295453a5e1c92e04ad34bab09871b622b5aac0e72236431000" diff --git a/jattach/testdata/61f13e4c60ad63295453a5e1c92e04ad34bab09871b622b5aac0e72236431000/jattach.tgz b/jattach/testdata/61f13e4c60ad63295453a5e1c92e04ad34bab09871b622b5aac0e72236431000/jattach.tgz new file mode 100644 index 0000000..c24b3a5 Binary files /dev/null and b/jattach/testdata/61f13e4c60ad63295453a5e1c92e04ad34bab09871b622b5aac0e72236431000/jattach.tgz differ