Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use pack experimental
Browse files Browse the repository at this point in the history
anthonydahanne committed Mar 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c19fda4 commit 0c0b745
Showing 4 changed files with 247 additions and 402 deletions.
396 changes: 0 additions & 396 deletions .github/workflows/multi-arch-create-package.yml

This file was deleted.

230 changes: 230 additions & 0 deletions .github/workflows/pb-create-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
name: Create Package
"on":
push:
branches:
- anthonydahanne-arm64-tests
jobs:
create-package:
name: Create Package
runs-on:
- ubuntu-latest
steps:
- name: Docker login gcr.io
if: ${{ (github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork) && (github.actor != 'dependabot[bot]') }}
uses: docker/login-action@v3
with:
password: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
registry: gcr.io
username: _json_key
- name: Docker login docker.io
if: ${{ (github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork) && (github.actor != 'dependabot[bot]') }}
uses: docker/login-action@v3
with:
password: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_PASSWORD }}
registry: docker.io
username: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
- uses: actions/setup-go@v5
with:
go-version: "1.20"
- name: Install create-package
run: |
#!/usr/bin/env bash
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
with:
crane-version: 0.19.0
yj-version: 5.1.0
# 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
- name: Install pack
run: |
#!/usr/bin/env bash
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: |
#!/usr/bin/env bash
set -euo pipefail
echo "Enabling pack experimental features"
mkdir -p "${HOME}"/.pack
echo "experimental = true" >> "${HOME}"/.pack/config.toml
- uses: actions/checkout@v4
- if: ${{ false }}
uses: actions/cache@v4
with:
key: ${{ runner.os }}-go-${{ hashFiles('**/buildpack.toml', '**/package.toml') }}
path: |-
${{ env.HOME }}/.pack
${{ env.HOME }}/carton-cache
restore-keys: ${{ runner.os }}-go-
- name: Compute Version
id: version
run: |
#!/usr/bin/env bash
set -euo pipefail
if [[ ${GITHUB_REF:-} != "refs/"* ]]; then
echo "GITHUB_REF set to [${GITHUB_REF:-}], but that is unexpected. It should start with 'refs/*'"
exit 255
fi
if [[ ${GITHUB_REF} =~ refs/tags/v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
VERSION=${BASH_REMATCH[1]}
MAJOR_VERSION="$(echo "${VERSION}" | awk -F '.' '{print $1 }')"
MINOR_VERSION="$(echo "${VERSION}" | awk -F '.' '{print $1 "." $2 }')"
echo "version-major=${MAJOR_VERSION}" >> "$GITHUB_OUTPUT"
echo "version-minor=${MINOR_VERSION}" >> "$GITHUB_OUTPUT"
elif [[ ${GITHUB_REF} =~ refs/heads/(.+) ]]; then
VERSION=${BASH_REMATCH[1]}
else
VERSION=$(git rev-parse --short HEAD)
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Selected ${VERSION} from
* ref: ${GITHUB_REF}
* sha: ${GITHUB_SHA}
"
- name: Create Package
run: |
#!/usr/bin/env bash
set -euo pipefail
# With Go 1.20, we need to set this so that we produce statically compiled binaries
#
# Starting with Go 1.20, Go will produce binaries that are dynamically linked against libc
# which can cause compatibility issues. The compiler links against libc on the build system
# but that may be newer than on the stacks we support.
export CGO_ENABLED=0
if [[ "${INCLUDE_DEPENDENCIES}" == "true" ]]; then
create-package \
--source ${SOURCE_PATH:-.} \
--cache-location "${HOME}"/carton-cache \
--destination "${HOME}"/buildpack \
--include-dependencies \
--version "${VERSION}"
else
create-package \
--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
env:
INCLUDE_DEPENDENCIES: "false"
OS: linux
SOURCE_PATH: ""
VERSION: ${{ steps.version.outputs.version }}
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
- name: Package Buildpack
id: package
run: |-
#!/usr/bin/env bash
env
set -euo pipefail
set -x
pack --version
which pack
ls -al ~/buildpack/
cat ~/package.toml
# with this, we don't need to use the package.toml, because pack exp. does not support it with multi arch yet
cd ~/buildpack
PACKAGE_LIST=($PACKAGES)
# Extract first repo (Docker Hub) as the main to package & register
PACKAGE=${PACKAGE_LIST[0]}
if [[ "${PUBLISH:-x}" == "true" ]]; then
ls
pack -v buildpack package \
"${PACKAGE}:${VERSION}" \
--publish
if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then
crane tag "${PACKAGE}:${VERSION}" "${VERSION_MINOR}"
crane tag "${PACKAGE}:${VERSION}" "${VERSION_MAJOR}"
fi
#crane tag "${PACKAGE}:${VERSION}" latest
echo "digest=$(crane digest "${PACKAGE}:${VERSION}")" >> "$GITHUB_OUTPUT"
# copy to other repositories specified
for P in "${PACKAGE_LIST[@]}"
do
if [ "$P" != "$PACKAGE" ]; then
crane copy "${PACKAGE}:${VERSION}" "${P}:${VERSION}"
if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then
crane tag "${P}:${VERSION}" "${VERSION_MINOR}"
crane tag "${P}:${VERSION}" "${VERSION_MAJOR}"
fi
#crane tag "${P}:${VERSION}" latest
fi
done
else
pack -v buildpack package \
"${PACKAGE}:${VERSION}" \
--format "${FORMAT}"
fi
env:
PACKAGES: docker.io/paketobuildpacks/syft gcr.io/paketo-buildpacks/syft
PUBLISH: "true"
VERSION: dualarch2
VERSION_MAJOR: dual
VERSION_MINOR: arch
# - name: Update release with digest
# run: |
# #!/usr/bin/env bash
#
# set -euo pipefail
#
# PAYLOAD=$(cat "${GITHUB_EVENT_PATH}")
#
# RELEASE_ID=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.release.id')
# RELEASE_TAG_NAME=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.release.tag_name')
# RELEASE_NAME=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.release.name')
# RELEASE_BODY=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.release.body')
#
# gh api \
# --method PATCH \
# "/repos/:owner/:repo/releases/${RELEASE_ID}" \
# --field "tag_name=${RELEASE_TAG_NAME}" \
# --field "name=${RELEASE_NAME}" \
# --field "body=${RELEASE_BODY//<!-- DIGEST PLACEHOLDER -->/\`${DIGEST}\`}"
# env:
# 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
# with:
# address: docker.io/paketobuildpacks/syft@${{ steps.package.outputs.digest }}
# id: paketo-buildpacks/syft
# token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
# version: ${{ steps.version.outputs.version }}
10 changes: 9 additions & 1 deletion buildpack.toml
Original file line number Diff line number Diff line change
@@ -27,8 +27,16 @@ api = "0.7"
type = "Apache-2.0"
uri = "https://github.com/paketo-buildpacks/syft/blob/main/LICENSE"

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

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

[metadata]
include-files = ["LICENSE", "NOTICE", "README.md", "bin/build", "bin/detect", "bin/main", "buildpack.toml"]
include-files = ["LICENSE", "NOTICE", "README.md", "linux/amd64/bin/build", "linux/amd64/bin/detect", "linux/amd64/bin/main", "linux/arm64/bin/build", "linux/arm64/bin/detect", "linux/arm64/bin/main", "buildpack.toml"]
pre-package = "scripts/build.sh"

[[metadata.dependencies]]
13 changes: 8 additions & 5 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -2,15 +2,18 @@

set -euo pipefail

GOOS="linux" go build -ldflags='-s -w' -o bin/main github.com/paketo-buildpacks/syft/cmd/main
GOOS="linux" go build -ldflags='-s -w' -o linux/amd64/bin/main github.com/paketo-buildpacks/syft/cmd/main
GOOS="linux" GOARCH="arm64" go build -ldflags='-s -w' -o linux/arm64/bin/main github.com/paketo-buildpacks/syft/cmd/main

if [ "${STRIP:-false}" != "false" ]; then
strip bin/main
strip linux/amd64/bin/main linux/arm64/bin/main
fi

if [ "${COMPRESS:-none}" != "none" ]; then
$COMPRESS bin/main
$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

0 comments on commit 0c0b745

Please sign in to comment.