Skip to content

Commit

Permalink
feat: fix badges and import pretty to readme (#5)
Browse files Browse the repository at this point in the history
* feat: fix badges and import pretty to readme

* fix: rm extra ci jobs
  • Loading branch information
TheCubicleJockey authored Jun 22, 2023
1 parent bc20e00 commit 566745d
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
steps:
- uses: asdf-vm/actions/plugin-test@v2
with:
command: crictl --version
command: crictl --version
66 changes: 46 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,62 @@
# asdf-crictl
<div align="center">

crictl plugin for [asdf](https://github.com/asdf-vm/asdf) version manager
# asdf-crictl [![CI](https://github.com/FairwindsOps/asdf-crictl/actions/workflows/workflow.yml/badge.svg?branch=main)](https://github.com/FairwindsOps/asdf-crictl/actions/workflows/workflow.yml)

## Install
[crictl](https://github.com/kubernetes-sigs/cri-tools) plugin for the [asdf version manager](https://asdf-vm.com).

```
asdf plugin-add crictl https://github.com/FairwindsOps/asdf-crictl.git
```
</div>

## Use
# Contents

Check out the [asdf documentation](https://asdf-vm.com/#/core-manage-versions?id=install-version) for instructions on how to install and manage versions of crictl.
- [Dependencies](#dependencies)
- [Install](#install)
- [Contributing](#contributing)
- [License](#license)

## Architecture Override
The `ASDF_crictl_OVERWRITE_ARCH` variable can be used to override the architecture that is used for determining which `crictl` build to download. The primary use case is when attempting to install an older version of `crictl` for use on an Apple M1 computer as `crictl` was not built for ARM at the time.
# Dependencies

### Without `ASDF_crictl_OVERWRITE_ARCH`:
- `bash`, `curl`, `gzip`, `cut`: generic POSIX utilities.

```
% asdf install crictl 6.0.0
Downloading crictl from https://github.com/FairwindsOps/crictl/releases/download/v6.0.0/crictl_6.0.0_darwin_amd64.tar.gz
% asdf global crictl 6.0.0
```
# Install

### With `ASDF_crictl_OVERWRITE_ARCH`:
Plugin:

```shell
asdf plugin add crictl
# or
asdf plugin add crictl https://github.com/FairwindsOps/asdf-crictl.git
```
% ASDF_crictl_OVERWRITE_ARCH=amd64 asdf install crictl 6.0.0-rc.5
Downloading crictl from https://github.com/FairwindsOps/crictl/releases/download/v6.0.0-rc.5/crictl_6.0.0-rc.5_darwin_amd64.tar.gz
% asdf global crictl 6.0.0-rc.5

crictl:

```shell
# Show all installable versions
asdf list-all crictl

# Install specific version
asdf install crictl latest

# Set a version globally (on your ~/.tool-versions file)
asdf global crictl latest

# Now crictl commands are available
crictl --help
```

Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to
install & manage versions.

# Contributing

Contributions of any kind welcome! See the [contributing guide](contributing.md).

[Thanks goes to these contributors](https://github.com/FairwindsOps/asdf-crictl/graphs/contributors)!

# License

See [LICENSE](LICENSE) © [Ivan Valdes](https://github.com/FairwindsOps/)


<!-- Begin boilerplate -->
## Join the Fairwinds Open Source Community

Expand Down
22 changes: 14 additions & 8 deletions bin/check
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ local_version="$1"

os_name="$(uname -s)"
case "${os_name}" in
Linux*) os=linux;;
Darwin*) os=darwin;;
CYGWIN*) os=windows;;
MINGW*) os=windows;;
*) echo "unknown OS"; exit 1;;
Linux*) os=linux ;;
Darwin*) os=darwin ;;
CYGWIN*) os=windows ;;
MINGW*) os=windows ;;
*)
echo "unknown OS"
exit 1
;;
esac

case "$(uname -m)" in
x86_64*) arch=amd64;;
arm64*) arch=arm64;;
*) echo "unknown architecture"; exit 1;;
x86_64*) arch=amd64 ;;
arm64*) arch=arm64 ;;
*)
echo "unknown architecture"
exit 1
;;
esac

curl --silent --fail "https://github.com/kubernetes-sigs/cri-tools/releases/download/v${local_version}/crictl-v${local_version}-${os}-${arch}.tar.gz" >/dev/null
68 changes: 34 additions & 34 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@ set -e
set -o pipefail

install_crictl() {
local install_type=$1
local version=$2
local install_path=$3
local platform="$(uname | tr '[:upper:]' '[:lower:]')-amd64"
local bin_install_path="$install_path/bin"
local binary_path="$bin_install_path/crictl"
local download_url=$(get_download_url $version $platform)

if [ "$TMPDIR" = "" ]; then
local tmp_download_dir=$(mktemp -d -t crictl_XXXXXX)
else
local tmp_download_dir=$TMPDIR
fi

local download_path="$tmp_download_dir/$(get_filename $version $platform)"

echo "Downloading crictl from ${download_url} to ${download_path}"
curl -Lo $download_path $download_url

echo "Creating bin directory"
mkdir -p "${bin_install_path}"

echo "Cleaning previous binaries"
rm -f $binary_path 2>/dev/null || true

echo "Copying binary"
tar -zxf ${download_path} --directory $tmp_download_dir
cp ${tmp_download_dir}/crictl ${bin_install_path}
chmod +x ${binary_path}
local install_type=$1
local version=$2
local install_path=$3
local platform="$(uname | tr '[:upper:]' '[:lower:]')-amd64"
local bin_install_path="$install_path/bin"
local binary_path="$bin_install_path/crictl"
local download_url=$(get_download_url $version $platform)

if [ "$TMPDIR" = "" ]; then
local tmp_download_dir=$(mktemp -d -t crictl_XXXXXX)
else
local tmp_download_dir=$TMPDIR
fi

local download_path="$tmp_download_dir/$(get_filename $version $platform)"

echo "Downloading crictl from ${download_url} to ${download_path}"
curl -Lo $download_path $download_url

echo "Creating bin directory"
mkdir -p "${bin_install_path}"

echo "Cleaning previous binaries"
rm -f $binary_path 2>/dev/null || true

echo "Copying binary"
tar -zxf ${download_path} --directory $tmp_download_dir
cp ${tmp_download_dir}/crictl ${bin_install_path}
chmod +x ${binary_path}
}

get_filename() {
echo "crictl-v${1}-${2}.tar.gz"
echo "crictl-v${1}-${2}.tar.gz"
}

get_download_url() {
local version="$1"
local platform="$2"
local filename="$(get_filename $version $platform)"
echo "https://github.com/kubernetes-sigs/cri-tools/releases/download/v${version}/${filename}"
local version="$1"
local platform="$2"
local filename="$(get_filename $version $platform)"
echo "https://github.com/kubernetes-sigs/cri-tools/releases/download/v${version}/${filename}"
}

install_crictl $ASDF_INSTALL_TYPE $ASDF_INSTALL_VERSION $ASDF_INSTALL_PATH
6 changes: 3 additions & 3 deletions bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
release_path=https://api.github.com/repos/kubernetes-sigs/cri-tools/releases
cmd="curl -s"
if [ -n "$GITHUB_API_TOKEN" ]; then
cmd="$cmd -H 'Authorization: token $GITHUB_API_TOKEN'"
cmd="$cmd -H 'Authorization: token $GITHUB_API_TOKEN'"
fi
cmd="$cmd $release_path"

function sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

versions=$(eval $cmd | grep -oE "tag_name\": *\"v.*.{1,15}\"," | sed 's/tag_name\": *\"v//;s/\",//' | sort_versions)
Expand Down
24 changes: 12 additions & 12 deletions lib/commands.bash
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
list_all_versions() {
local release_url="https://github.com/kubernetes-sigs/cri-tools/releases"
curl -Ls $release_url | grep -oE 'href="/kubernetes-sigs/cri-tools/releases/tag/v[0-9]+\.[0-9]+\.[0-9]+"' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -rV
local release_url="https://github.com/kubernetes-sigs/cri-tools/releases"
curl -Ls $release_url | grep -oE 'href="/kubernetes-sigs/cri-tools/releases/tag/v[0-9]+\.[0-9]+\.[0-9]+"' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -rV
}

list_installed_versions() {
ls -1 ~/.asdf/installs/crictl
ls -1 ~/.asdf/installs/crictl
}

install_version() {
local version=$1
asdf plugin-add crictl https://github.com/kubernetes-sigs/cri-tools.git
asdf install crictl $version
local version=$1
asdf plugin-add crictl https://github.com/kubernetes-sigs/cri-tools.git
asdf install crictl $version
}

uninstall_version() {
local version=$1
asdf uninstall crictl $version
local version=$1
asdf uninstall crictl $version
}

set_global_version() {
local version=$1
asdf global crictl $version
local version=$1
asdf global crictl $version
}

set_local_version() {
local version=$1
asdf local crictl $version
local version=$1
asdf local crictl $version
}
4 changes: 4 additions & 0 deletions scripts/format.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

shfmt --language-dialect bash --write \
./**/*
9 changes: 9 additions & 0 deletions scripts/lint.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

shellcheck --shell=bash --external-sources \
bin/* --source-path=template/lib/ \
lib/* \
scripts/*

shfmt --language-dialect bash --diff \
./**/*

0 comments on commit 566745d

Please sign in to comment.