Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/oras/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "ORAS",
"id": "oras",
"version": "1.0.0",
"description": "Install ORAS ( https://oras.land ), an OCI Artifact tool",
"options": {
"version": {
"type": "string",
"proposals": ["1.0.0"],
"default": "1.0.0",
"description": "The specific version to install"
}
},
"installsAfter": ["ghcr.io/devcontainers/features/common-utils"]
}
28 changes: 28 additions & 0 deletions src/oras/ensure_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ensure_apt_updated() {
if [ "${_apt_updated:-}" != "true" ]; then
apt-get update
_apt_updated=true
fi
}

ensure_command() {
command=${1:?}
package=${2:-$command}

if ! which "$command" >/dev/null; then
ensure_package "$package"
fi
}

ensure_package() {
package=${1:?}
if which apt-get >/dev/null; then
ensure_apt_updated
apt-get -y install "$package"
elif which apk >/dev/null; then
apk add "${package}"
else
echo "Unable to install $package, no supported package manager found" >&2
exit 1
fi
}
21 changes: 21 additions & 0 deletions src/oras/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -euo pipefail

. ./ensure_command.sh
ensure_command curl

VERSION="${VERSION:-1.0.0}"
if [[ ! $VERSION =~ ^[a-zA-Z0-9.-]+$ ]]; then
echo "Error: invalid version: $VERSION" >&2
exit 1
fi

declare -A uname_platforms=([aarch64]=arm64 [x86_64]=amd64)
platform=${uname_platforms[$(uname -m)]:?"Error: unsupported platform: $(uname -m)"}

curl --fail --location -# -o oras.tar.gz \
"https://github.com/oras-project/oras/releases/download/v${VERSION?}/oras_${VERSION:?}_linux_${platform:?}.tar.gz"
mkdir -p oras-install/
tar -zxf oras.tar.gz -C oras-install/
mv oras-install/oras /usr/local/bin/
rm -rf oras.tar.gz oras-install/
1 change: 1 addition & 0 deletions test/oras/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
9 changes: 9 additions & 0 deletions test/oras/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

# https://github.com/devcontainers/cli/blob/main/docs/features/test.md
source dev-container-features-test-lib

check "oras command available" oras version

reportResults