Skip to content

Commit

Permalink
feat: implement apko-specific download logic
Browse files Browse the repository at this point in the history
  • Loading branch information
omissis committed Jan 5, 2024
1 parent 4314ef1 commit e106b1e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
TODO: INSERT YOUR NAME COPYRIGHT YEAR (if applicable to your license)

MIT License

Copyright (c) [year] [fullname]
Copyright (c) 2024-present Claudio Beatrice

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`, and [POSIX utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.
- `melange`: while not strictly required, apko needs apks built by melange in order to package them into an image

# Install

Expand Down
1 change: 0 additions & 1 deletion bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ source "${plugin_dir}/lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"

# TODO: Adapt this to proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"

# Download tar.gz file to the download directory
Expand Down
1 change: 0 additions & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Testing Locally:
```shell
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]

# TODO: adapt this
asdf plugin test apko https://github.com/omissis/asdf-apko.git "apko --help"
```

Expand Down
33 changes: 25 additions & 8 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for apko.
GH_REPO="https://github.com/chainguard-dev/apko"
TOOL_NAME="apko"
TOOL_TEST="apko --help"
Expand All @@ -14,7 +13,6 @@ fail() {

curl_opts=(-fsSL)

# NOTE: You might want to remove this if apko is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi
Expand All @@ -27,12 +25,10 @@ sort_versions() {
list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
sed 's/^v//'
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if apko has other means of determining installable versions.
list_github_tags
}

Expand All @@ -41,8 +37,7 @@ download_release() {
version="$1"
filename="$2"

# TODO: Adapt the release URL convention for apko
url="$GH_REPO/archive/v${version}.tar.gz"
url="$GH_REPO/releases/download/v${version}/apko_${version}_$(get_platform)_$(get_arch).tar.gz"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -61,7 +56,6 @@ install_version() {
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"

# TODO: Assert apko executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."
Expand All @@ -72,3 +66,26 @@ install_version() {
fail "An error occurred while installing $TOOL_NAME $version."
)
}

get_platform() {
uname | tr '[:upper:]' '[:lower:]'
}

get_arch() {
local arch=""

case "$(uname -m)" in
x86_64 | amd64) arch="amd64" ;;
i686 | i386) arch="386" ;;
armv6l) arch="armv6" ;;
armv7l) arch="armv7" ;;
aarch64 | arm64) arch="arm64" ;;
ppc64le) arch="ppc64le" ;;
*)
echo "Arch '$(uname -m)' not supported!" >&2
exit 1
;;
esac

echo -n $arch
}

0 comments on commit e106b1e

Please sign in to comment.