Skip to content

Commit

Permalink
Merge pull request #108 from paketo-buildpacks/arm64
Browse files Browse the repository at this point in the history
Add ARM64 Support
  • Loading branch information
dmikusa authored May 21, 2024
2 parents a4cdf67 + 5be2f07 commit 2210902
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .github/pipeline-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
52 changes: 36 additions & 16 deletions .github/workflows/pb-create-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,20 @@ jobs:
with:
crane-version: 0.19.0
yj-version: 5.1.0
- uses: buildpacks/github-actions/[email protected]
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: |
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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/dynatrace gcr.io/paketo-buildpacks/dynatrace
Expand Down Expand Up @@ -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.5.3
with:
address: docker.io/paketobuildpacks/dynatrace@${{ steps.package.outputs.digest }}
id: paketo-buildpacks/dynatrace
Expand Down
51 changes: 36 additions & 15 deletions .github/workflows/pb-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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: |
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/pb-update-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,7 +13,8 @@
# limitations under the License.

bin/
linux/
dependencies/
package/
scratch/
.idea/

16 changes: 9 additions & 7 deletions buildpack.toml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -28,14 +28,16 @@ api = "0.7"
uri = "https://github.com/paketo-buildpacks/dynatrace/blob/main/LICENSE"

[metadata]
include-files = ["LICENSE", "NOTICE", "README.md", "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"

[[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"
32 changes: 28 additions & 4 deletions dt/build.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 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.
Expand All @@ -20,6 +20,8 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"runtime"

"github.com/buildpacks/libcnb"
"github.com/paketo-buildpacks/libpak"
Expand Down Expand Up @@ -53,9 +55,9 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
return libcnb.BuildResult{}, fmt.Errorf("unable to determine agent version\n%w", err)
}

uri := fmt.Sprintf("%s/v1/deployment/installer/agent/unix/paas/latest?bitness=64&skipMetadata=true", BaseURI(s))
uri := fmt.Sprintf("%s/v1/deployment/installer/agent/unix/paas/latest?bitness=64&skipMetadata=true&arch=%s", BaseURI(s), archForDynatrace())

for _, t := range []string{"apache", "dotnet", "go", "java", "nginx", "nodejs", "php", "python"} {
for _, t := range []string{"apache", "dotnet", "go", "java", "nginx", "nodejs", "php", "all", "sdk", "envoy"} {
if _, ok, err := pr.Resolve(fmt.Sprintf("dynatrace-%s", t)); err != nil {
return libcnb.BuildResult{}, fmt.Errorf("unable to resolve dynatrace-%s plan entry\n%w", t, err)
} else if ok {
Expand All @@ -70,7 +72,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
URI: uri,
SHA256: "",
Stacks: []string{context.StackID},
PURL: fmt.Sprintf("pkg:generic/dynatrace-one-agent@%s?arch=amd64", v),
PURL: fmt.Sprintf("pkg:generic/dynatrace-one-agent@%s?arch=%s", v, archFromSystem()),
CPEs: []string{fmt.Sprintf("cpe:2.3:a:dynatrace:one-agent:%s:*:*:*:*:*:*:*", v)},
}

Expand Down Expand Up @@ -118,3 +120,25 @@ func (Build) AgentVersion(binding libcnb.Binding, info libcnb.BuildpackInfo) (st

return raw.LatestAgentVersion, nil
}

func archFromSystem() string {
archFromEnv, ok := os.LookupEnv("BP_ARCH")
if !ok {
archFromEnv = runtime.GOARCH
}

return archFromEnv
}

func archForDynatrace() string {
archFromEnv := archFromSystem()

// https://docs.dynatrace.com/docs/dynatrace-api/environment-api/deployment/oneagent/download-oneagent-version?secureweb=Teams
if (archFromEnv == "amd64") || (archFromEnv == "x86_64") {
return "x86"
} else if (archFromEnv == "aarch64") || (archFromEnv == "arm64") {
return "arm"
} else {
return "x86"
}
}
18 changes: 5 additions & 13 deletions dt/build_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 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.
Expand Down Expand Up @@ -37,7 +37,7 @@ func getExpectedDependency(serverUrl string) libpak.BuildpackDependency {
ID: "dynatrace-oneagent",
Name: "Dynatrace OneAgent",
Version: "test-version",
URI: fmt.Sprintf("%s/v1/deployment/installer/agent/unix/paas/latest?bitness=64&skipMetadata=true&include=java&include=php", serverUrl),
URI: fmt.Sprintf("%s/v1/deployment/installer/agent/unix/paas/latest?bitness=64&skipMetadata=true&arch=x86&include=java&include=php", serverUrl),
Stacks: []string{stackId},
PURL: "pkg:generic/dynatrace-one-agent@test-version?arch=amd64",
CPEs: []string{"cpe:2.3:a:dynatrace:one-agent:test-version:*:*:*:*:*:*:*"},
Expand Down Expand Up @@ -75,6 +75,8 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
RegisterTestingT(t)
server = ghttp.NewServer()

t.Setenv("BP_ARCH", "amd64")

ctx.Buildpack.Info.ID = "test-id"
ctx.Buildpack.Info.Version = "test-version"
ctx.StackID = stackId
Expand Down Expand Up @@ -107,17 +109,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
server.Close()
})

it("contributes agent for API 0.7+", func() {
result, err := dt.Build{}.Build(ctx)
Expect(err).NotTo(HaveOccurred())

verifyLayers(result.Layers, server.URL())
verifyBOM(result.BOM)
})

it("contributes agent for API <= 0.6", func() {
ctx.Buildpack.API = "0.6"

it("contributes agent", func() {
result, err := dt.Build{}.Build(ctx)
Expect(err).NotTo(HaveOccurred())

Expand Down
Loading

0 comments on commit 2210902

Please sign in to comment.