Skip to content

Commit

Permalink
adding multi arch support, current targets linux/amd64 and linux/arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
pacostas committed Jan 7, 2025
1 parent aee0505 commit 27e6ab7
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 107 deletions.
5 changes: 4 additions & 1 deletion .github/.syncignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
CODEOWNERS
workflows/update-dependencies-from-metadata.yml
workflows/update-dependencies-from-metadata.yml
workflows/push-buildpackage.yml
workflows/create-draft-release.yml
scripts/publish.sh
95 changes: 81 additions & 14 deletions .github/workflows/create-draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ jobs:
name: Release
runs-on: ubuntu-22.04
needs: integration
services:
registry:
image: registry:2
ports:
- 5000:5000

steps:
- name: Setup Go
uses: actions/setup-go@v3
Expand Down Expand Up @@ -110,13 +116,86 @@ jobs:
echo "buildpack_type=buildpack" >> "$GITHUB_OUTPUT"
fi
- name: Get buildpack path
id: get_buildpack_path
run: |
if [ -f "build/buildpackage.cnb" ]; then
echo "path=build/buildpackage.cnb" >> "$GITHUB_OUTPUT"
else
echo "path=build/buildpackage-linux-amd64.cnb" >> "$GITHUB_OUTPUT"
fi
- name: Create Release Notes
id: create-release-notes
uses: paketo-buildpacks/github-config/actions/release/notes@main
with:
repo: ${{ github.repository }}
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
buildpack_type: ${{ steps.get_buildpack_type.outputs.buildpack_type }}
buildpackage_path: ${{ steps.get_buildpack_path.outputs.path }}

- name: Get Image Digest
id: image_digest
run: |
image_name="localhost:5000/npm-install:latest"
./scripts/publish.sh \
--buildpack-archive ./build/buildpack.tgz \
--image-ref $image_name
echo "digest=$(sudo skopeo inspect "docker://${image_name}" --tls-verify=false | jq -r .Digest)" >> "$GITHUB_OUTPUT"
- name: Set Correct Image Digest on the Release notes
run: |
printf '${{ steps.create-release-notes.outputs.release_body }}' \
| sed -E \
"s/\*\*Digest:\*\* \`sha256:[a-f0-9]{64}\`/\*\*Digest:\*\* \`${{ steps.image_digest.outputs.digest }}\`/" \
> ./release_notes
printf '${{ steps.image_digest.outputs.digest }}' > ./index-digest.sha256
- name: Create release assets
id: create_release_assets
run: |
release_assets=$(jq -n --arg repo_name "${{ github.event.repository.name }}" --arg tag "${{ steps.tag.outputs.tag }}" '
[
{
"path": "build/buildpack.tgz",
"name": ($repo_name + "-" + $tag + ".tgz"),
"content_type": "application/gzip"
},
{
"path": "./index-digest.sha256",
"name": ($repo_name + "-" + $tag + "-" + "index-digest.sha256"),
"content_type": "text/plain"
}
]')
for filepath in build/*.cnb; do
filename=$(basename "$filepath")
asset_name=""
if [[ "$filename" == "buildpackage-linux-amd64.cnb" ]]; then
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb"
elif [[ "$filename" == "buildpackage.cnb" ]]; then
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb"
else
formatted_filename="${filename#buildpackage-}"
asset_name="${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}-${formatted_filename}"
fi
release_assets=$(echo "$release_assets" | jq --arg asset_name "${asset_name}" --arg filepath "$filepath" '
. + [
{
"path": $filepath,
"name": $asset_name,
"content_type": "application/gzip"
}
]')
done
release_assets=$(jq -c <<< "$release_assets" )
printf "release_assets=%s\n" "${release_assets}" >> "$GITHUB_OUTPUT"
- name: Create Release
uses: paketo-buildpacks/github-config/actions/release/create@main
Expand All @@ -126,21 +205,9 @@ jobs:
tag_name: v${{ steps.tag.outputs.tag }}
target_commitish: ${{ github.sha }}
name: v${{ steps.tag.outputs.tag }}
body: ${{ steps.create-release-notes.outputs.release_body }}
body_filepath: "./release_notes"
draft: true
assets: |
[
{
"path": "build/buildpack.tgz",
"name": "${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.tgz",
"content_type": "application/gzip"
},
{
"path": "build/buildpackage.cnb",
"name": "${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb",
"content_type": "application/gzip"
}
]
assets: ${{ steps.create_release_assets.outputs.release_assets }}

failure:
name: Alert on Failure
Expand Down
109 changes: 77 additions & 32 deletions .github/workflows/push-buildpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ on:
release:
types:
- published

env:
REGISTRIES_FILENAME: "registries.json"

jobs:
push:
name: Push
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
env:
GCR_REGISTRY: "gcr.io"
GCR_PASSWORD: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
GCR_USERNAME: "_json_key"
DOCKERHUB_REGISTRY: docker.io
DOCKERHUB_USERNAME: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}

steps:

- name: Checkout
Expand All @@ -25,30 +34,43 @@ jobs:
echo "tag_full=${FULL_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag_minor=${MINOR_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag_major=${MAJOR_VERSION}" >> "$GITHUB_OUTPUT"
echo "download_url=$(jq -r '.release.assets[] | select(.name | endswith(".cnb")) | .url' "${GITHUB_EVENT_PATH}")" >> "$GITHUB_OUTPUT"
echo "download_tgz_file_url=$(jq -r '.release.assets[] | select(.name | endswith(".tgz")) | .url' "${GITHUB_EVENT_PATH}")" >> "$GITHUB_OUTPUT"
echo "download_cnb_file_url=$(jq -r --arg tag_full "$FULL_VERSION" '.release.assets[] | select(.name | endswith($tag_full + ".cnb")) | .url' "${GITHUB_EVENT_PATH}")" >> "$GITHUB_OUTPUT"
echo "download_sha256_file_url=$(jq -r '.release.assets[] | select(.name | endswith("index-digest.sha256")) | .url' "${GITHUB_EVENT_PATH}")" >> "$GITHUB_OUTPUT"
- name: Download
id: download
- name: Download .cnb buildpack
uses: paketo-buildpacks/github-config/actions/release/download-asset@main
with:
url: ${{ steps.event.outputs.download_url }}
url: ${{ steps.event.outputs.download_cnb_file_url }}
output: "/github/workspace/buildpackage.cnb"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}

- name: Download .tgz buildpack
uses: paketo-buildpacks/github-config/actions/release/download-asset@main
with:
url: ${{ steps.event.outputs.download_tgz_file_url }}
output: "/github/workspace/buildpack.tgz"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}

- name: Download .sha digest
uses: paketo-buildpacks/github-config/actions/release/download-asset@main
with:
url: ${{ steps.event.outputs.download_sha256_file_url }}
output: "/github/workspace/index-digest.sha256"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}

- name: Parse Configs
id: parse_configs
run: |
registries_filename="${{ env.REGISTRIES_FILENAME }}"
push_to_dockerhub=true
push_to_gcr=true
if [[ -f $registries_filename ]]; then
if jq 'has("dockerhub")' $registries_filename > /dev/null; then
push_to_dockerhub=$(jq '.dockerhub' $registries_filename)
if [[ -f $REGISTRIES_FILENAME ]]; then
if jq 'has("dockerhub")' $REGISTRIES_FILENAME > /dev/null; then
push_to_dockerhub=$(jq '.dockerhub' $REGISTRIES_FILENAME)
fi
if jq 'has("GCR")' $registries_filename > /dev/null; then
push_to_gcr=$(jq '.GCR' $registries_filename)
if jq 'has("GCR")' $REGISTRIES_FILENAME > /dev/null; then
push_to_gcr=$(jq '.GCR' $REGISTRIES_FILENAME)
fi
fi
Expand All @@ -64,34 +86,57 @@ jobs:
exit 1
fi
- name: Push to GCR
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
env:
GCR_PUSH_BOT_JSON_KEY: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
run: |
echo "${GCR_PUSH_BOT_JSON_KEY}" | sudo skopeo login --username _json_key --password-stdin gcr.io
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_full }}"
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_minor }}"
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:${{ steps.event.outputs.tag_major }}"
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:latest"
- name: Docker login docker.io
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
registry: ${{ env.DOCKERHUB_REGISTRY }}

- name: Docker login gcr.io
uses: docker/login-action@v3
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
with:
username: ${{ env.GCR_USERNAME }}
password: ${{ env.GCR_PASSWORD }}
registry: ${{ env.GCR_REGISTRY }}

- name: Push to DockerHub
if: ${{ steps.parse_configs.outputs.push_to_dockerhub == 'true' }}
id: push
env:
DOCKERHUB_USERNAME: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
run: |
REPOSITORY="${GITHUB_REPOSITORY_OWNER/-/}/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" # translates 'paketo-buildpacks/bundle-install' to 'paketobuildpacks/bundle-install'
IMAGE="index.docker.io/${REPOSITORY}"
echo "${DOCKERHUB_PASSWORD}" | sudo skopeo login --username "${DOCKERHUB_USERNAME}" --password-stdin index.docker.io
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://${IMAGE}:${{ steps.event.outputs.tag_full }}"
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://${IMAGE}:${{ steps.event.outputs.tag_minor }}"
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://${IMAGE}:${{ steps.event.outputs.tag_major }}"
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://${IMAGE}:latest"
IMAGE="${GITHUB_REPOSITORY_OWNER/-/}/${GITHUB_REPOSITORY#${GITHUB_REPOSITORY_OWNER}/}" # translates 'paketo-buildpacks/bundle-install' to 'paketobuildpacks/bundle-install'
echo "${DOCKERHUB_PASSWORD}" | sudo skopeo login --username "${DOCKERHUB_USERNAME}" --password-stdin ${DOCKERHUB_REGISTRY}
./scripts/publish.sh \
--buildpack-archive ./buildpack.tgz \
--image-ref "${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}"
## Validate that the digest pushed to registry matches with the one mentioned on the readme file
pushed_image_index_digest=$(sudo skopeo inspect "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" | jq -r .Digest)
if [ "$(cat ./index-digest.sha256)" != "$pushed_image_index_digest" ]; then
echo "Image index digest pushed to registry does not match with the one mentioned on the readme file"
exit 1;
fi
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_minor }}" --multi-arch all
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_major }}" --multi-arch all
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:${{ steps.event.outputs.tag_full }}" "docker://${DOCKERHUB_REGISTRY}/${IMAGE}:latest" --multi-arch all
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
echo "digest=$(sudo skopeo inspect "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" | jq -r .Digest)" >> "$GITHUB_OUTPUT"
echo "digest=$pushed_image_index_digest" >> "$GITHUB_OUTPUT"
- name: Push to GCR
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
run: |
echo "${GCR_PASSWORD}" | sudo skopeo login --username "${GCR_USERNAME}" --password-stdin "${GCR_REGISTRY}"
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_full }}" --multi-arch all
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_minor }}" --multi-arch all
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:${{ steps.event.outputs.tag_major }}" --multi-arch all
sudo skopeo copy "docker://${DOCKERHUB_REGISTRY}/${{ steps.push.outputs.image }}" "docker://${GCR_REGISTRY}/${{ github.repository }}:latest" --multi-arch all
- name: Register with CNB Registry
uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:main
Expand Down
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.bin
.DS_Store
.idea
/.bin
/build
/bin
/build
/linux
/darwin
/windows
20 changes: 18 additions & 2 deletions extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,21 @@ name = "Ubi Node.js Extension"
description = "This extension installs the appropriate Node.js runtime via dnf"

[metadata]
pre-package = "./scripts/build.sh"
include-files = ["bin/generate", "bin/detect", "bin/run", "extension.toml"]
pre-package = "./scripts/build.sh --target linux/amd64 --target linux/arm64"
include-files = [
"linux/amd64/bin/generate",
"linux/amd64/bin/detect",
"linux/amd64/bin/run",
"linux/arm64/bin/generate",
"linux/arm64/bin/detect",
"linux/arm64/bin/run",
"extension.toml"
]

[[targets]]
os = "linux"
arch = "amd64"

[[targets]]
os = "linux"
arch = "arm64"
5 changes: 4 additions & 1 deletion scripts/.syncignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
options.json
options.json
build.sh
package.sh
publish.sh
Loading

0 comments on commit 27e6ab7

Please sign in to comment.