Skip to content

Commit

Permalink
Updating github-config
Browse files Browse the repository at this point in the history
  • Loading branch information
paketo-bot committed Jul 2, 2024
1 parent 6164097 commit d8d625c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scripts/.util/tools.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"jam": "v2.8.0",
"pack": "v0.34.2",
"syft": "v1.8.0"
"syft": "v1.8.0",
"crane": "v0.19.2"
}
88 changes: 88 additions & 0 deletions scripts/.util/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function util::tools::arch() {
amd64|x86_64)
if [[ "${1:-}" == "--blank-amd64" ]]; then
echo ""
elif [[ "${1:-}" == "--uname-format-amd64" ]]; then
echo "x86_64"
else
echo "amd64"
fi
Expand Down Expand Up @@ -251,3 +253,89 @@ function util::tools::tests::checkfocus() {
fi
rm "${testout}"
}

function util::tools::crane::install() {
local dir token
token=""

while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
dir="${2}"
shift 2
;;

--token)
token="${2}"
shift 2
;;

*)
util::print::error "unknown argument \"${1}\""
esac
done

mkdir -p "${dir}"
util::tools::path::export "${dir}"

if [[ ! -f "${dir}/crane" ]]; then
local version curl_args os arch

version="$(jq -r .crane "$(dirname "${BASH_SOURCE[0]}")/tools.json")"

curl_args=(
"--fail"
"--silent"
"--location"
)

if [[ "${token}" != "" ]]; then
curl_args+=("--header" "Authorization: Token ${token}")
fi

util::print::title "Installing crane ${version}"

os=$(util::tools::os)
arch=$(util::tools::arch --uname-format-amd64)


curl "https://github.com/google/go-containerregistry/releases/download/${version}/go-containerregistry_Linux_${arch}.tar.gz" \
"${curl_args[@]}" | tar -C "${dir}" -xz crane

chmod +x "${dir}/crane"
fi
}


# Returns a random unused port
function get::random::port() {
local port=$(shuf -i 50000-65000 -n 1)
netstat -lat | grep $port > /dev/null
if [[ $? == 1 ]] ; then
echo $port
else
echo get::random::port
fi
}

# Starts a local registry on the given port and returns the pid
function local::registry::start() {
local registryPort registryPid localRegistry

registryPort="$1"
localRegistry="127.0.0.1:$registryPort"

# Start a local in-memory registry so we can work with oci archives
PORT=$registryPort crane registry serve --insecure > /dev/null 2>&1 &
registryPid=$!

# Stop the registry if execution is interrupted
trap "kill $registryPid" 1 2 3 6

# Wait for the registry to be available
until crane catalog $localRegistry > /dev/null 2>&1; do
sleep 1
done

echo $registryPid
}

0 comments on commit d8d625c

Please sign in to comment.