Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/ruff/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Ruff (via pipx) (ruff)
# Ruff (via Github Releases)

Ruff is an extremely fast Python linter, written in Rust.

Expand Down
9 changes: 3 additions & 6 deletions src/ruff/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "ruff",
"version": "1.1.1",
"name": "Ruff (via pipx)",
"version": "2.0.0",
"name": "Ruff (via Github Releases)",
"documentationURL": "http://github.com/devcontainers-extra/features/tree/main/src/ruff",
"description": "Ruff is an extremely fast Python linter, written in Rust.",
"options": {
Expand All @@ -21,8 +21,5 @@
]
}
},
"installsAfter": [
"ghcr.io/devcontainers-extra/features/pipx-package",
"ghcr.io/devcontainers/features/python"
]
"installsAfter": []
}
14 changes: 6 additions & 8 deletions src/ruff/install.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#!/usr/bin/env bash

set -e

. ./library_scripts.sh
source ./library_scripts.sh

# nanolayer is a cli utility which keeps container layers as small as possible
# source code: https://github.com/devcontainers-extra/nanolayer
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
# and if missing - will download a temporary copy that automatically get deleted at the end
# of the script
ensure_nanolayer nanolayer_location "v0.5.0"

ensure_nanolayer nanolayer_location "v0.5.6"

# Example nanolayer installation via devcontainer-feature
$nanolayer_location \
install \
devcontainer-feature \
"ghcr.io/devcontainers-extra/features/pipx-package:1.1.8" \
--option package='ruff' --option version="$VERSION"


"ghcr.io/devcontainers-extra/features/gh-release:1" \
--option repo='astral-sh/ruff' --option binaryNames='ruff' --option version="$VERSION"

echo 'Done!'

71 changes: 36 additions & 35 deletions src/ruff/library_scripts.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#!/usr/bin/env bash

clean_download() {
# The purpose of this function is to download a file with minimal impact on container layer size
Expand All @@ -15,7 +15,7 @@ clean_download() {
tempdir=$(mktemp -d)
downloader_installed=""

_apt_get_install() {
function _apt_get_install() {
tempdir=$1

# copy current state of apt list - in order to revert back later (minimize contianer layer size)
Expand All @@ -24,7 +24,7 @@ clean_download() {
apt-get -y install --no-install-recommends wget ca-certificates
}

_apt_get_cleanup() {
function _apt_get_cleanup() {
tempdir=$1

echo "removing wget"
Expand All @@ -35,15 +35,15 @@ clean_download() {
rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists
}

_apk_install() {
function _apk_install() {
tempdir=$1
# copy current state of apk cache - in order to revert back later (minimize contianer layer size)
cp -p -R /var/cache/apk $tempdir

apk add --no-cache wget
apk add --no-cache wget
}

_apk_cleanup() {
function _apk_cleanup() {
tempdir=$1

echo "removing wget"
Expand All @@ -59,10 +59,10 @@ clean_download() {
fi

# in case none of them is installed, install wget temporarly
if [ -z $downloader ] ; then
if [ -x "/usr/bin/apt-get" ] ; then
if [ -z $downloader ]; then
if [ -x "/usr/bin/apt-get" ]; then
_apt_get_install $tempdir
elif [ -x "/sbin/apk" ] ; then
elif [ -x "/sbin/apk" ]; then
_apk_install $tempdir
else
echo "distro not supported"
Expand All @@ -72,18 +72,18 @@ clean_download() {
downloader_installed="true"
fi

if [ $downloader = "wget" ] ; then
if [ $downloader = "wget" ]; then
wget -q $url -O $output_location
else
curl -sfL $url -o $output_location
fi

# NOTE: the cleanup procedure was not implemented using `trap X RETURN` only because
# alpine lack bash, and RETURN is not a valid signal under sh shell
if ! [ -z $downloader_installed ] ; then
if [ -x "/usr/bin/apt-get" ] ; then
if ! [ -z $downloader_installed ]; then
if [ -x "/usr/bin/apt-get" ]; then
_apt_get_cleanup $tempdir
elif [ -x "/sbin/apk" ] ; then
elif [ -x "/sbin/apk" ]; then
_apk_cleanup $tempdir
else
echo "distro not supported"
Expand All @@ -93,56 +93,60 @@ clean_download() {

}


ensure_nanolayer() {
# Ensure existance of the nanolayer cli program
local variable_name=$1

local required_version=$2
# normalize version
if ! [[ $required_version == v* ]]; then
required_version=v$required_version
fi

local __nanolayer_location=""
local nanolayer_location=""

# If possible - try to use an already installed nanolayer
if [ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]; then
if [ -z "${NANOLAYER_CLI_LOCATION}" ]; then
if [[ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]]; then
if [[ -z "${NANOLAYER_CLI_LOCATION}" ]]; then
if type nanolayer >/dev/null 2>&1; then
echo "Found a pre-existing nanolayer in PATH"
__nanolayer_location=nanolayer
nanolayer_location=nanolayer
fi
elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ] ; then
__nanolayer_location=${NANOLAYER_CLI_LOCATION}
echo "Found a pre-existing nanolayer which were given in env variable: $__nanolayer_location"
elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ]; then
nanolayer_location=${NANOLAYER_CLI_LOCATION}
echo "Found a pre-existing nanolayer which were given in env variable: $nanolayer_location"
fi

# make sure its of the required version
if ! [ -z "${__nanolayer_location}" ]; then
if ! [[ -z "${nanolayer_location}" ]]; then
local current_version
current_version=$($__nanolayer_location --version)

current_version=$($nanolayer_location --version)
if ! [[ $current_version == v* ]]; then
current_version=v$current_version
fi

if ! [ $current_version == $required_version ]; then
echo "skipping usage of pre-existing nanolayer. (required version $required_version does not match existing version $current_version)"
__nanolayer_location=""
nanolayer_location=""
fi
fi

fi

# If not previuse installation found, download it temporarly and delete at the end of the script
if [ -z "${__nanolayer_location}" ]; then
if [[ -z "${nanolayer_location}" ]]; then

if [ "$(uname -sm)" = 'Linux x86_64' ] || [ "$(uname -sm)" = "Linux aarch64" ]; then
if [ "$(uname -sm)" == "Linux x86_64" ] || [ "$(uname -sm)" == "Linux aarch64" ]; then
tmp_dir=$(mktemp -d -t nanolayer-XXXXXXXXXX)

clean_up () {
clean_up() {
ARG=$?
rm -rf $tmp_dir
exit $ARG
}
trap clean_up EXIT


if [ -x "/sbin/apk" ] ; then
if [ -x "/sbin/apk" ]; then
clib_type=musl
else
clib_type=gnu
Expand All @@ -155,8 +159,7 @@ ensure_nanolayer() {

tar xfzv $tmp_dir/$tar_filename -C "$tmp_dir"
chmod a+x $tmp_dir/nanolayer
__nanolayer_location=$tmp_dir/nanolayer

nanolayer_location=$tmp_dir/nanolayer

else
echo "No binaries compiled for non-x86-linux architectures yet: $(uname -m)"
Expand All @@ -165,8 +168,6 @@ ensure_nanolayer() {
fi

# Expose outside the resolved location
export ${variable_name}=$__nanolayer_location
declare -g ${variable_name}=$nanolayer_location

}