From 5d5be1d5dcd532fdd7afed69f801f7df554d50b8 Mon Sep 17 00:00:00 2001 From: Daniel Braun Date: Sat, 30 Sep 2023 13:43:03 +0000 Subject: [PATCH] fix: standard format for node-asdf and ruby-asdf features --- src/node-asdf/README.md | 2 ++ src/node-asdf/devcontainer-feature.json | 4 +-- src/node-asdf/install.sh | 12 +++---- src/node-asdf/library_scripts.sh | 45 +++++++++++-------------- src/ruby-asdf/README.md | 2 ++ src/ruby-asdf/devcontainer-feature.json | 7 ++-- src/ruby-asdf/install.sh | 14 ++++---- src/ruby-asdf/library_scripts.sh | 45 +++++++++++-------------- test/node-asdf/scenarios.json | 2 +- test/ruby-asdf/scenarios.json | 2 +- 10 files changed, 62 insertions(+), 73 deletions(-) diff --git a/src/node-asdf/README.md b/src/node-asdf/README.md index d2ec74f8d..d7feb60ed 100644 --- a/src/node-asdf/README.md +++ b/src/node-asdf/README.md @@ -16,3 +16,5 @@ Installs Node.js via asdf. | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| | version | Select the version to install. | string | latest | + + diff --git a/src/node-asdf/devcontainer-feature.json b/src/node-asdf/devcontainer-feature.json index 3c9ac7e3b..0e7e3a807 100644 --- a/src/node-asdf/devcontainer-feature.json +++ b/src/node-asdf/devcontainer-feature.json @@ -3,7 +3,7 @@ "version": "0.0.1", "name": "Node.js (via asdf)", "documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/node-asdf", - "description": "Installs Node.js via asdf", + "description": "Installs Node.js via asdf.", "options": { "version": { "default": "latest", @@ -17,4 +17,4 @@ "installsAfter": [ "ghcr.io/devcontainers-contrib/features/asdf-package" ] -} +} \ No newline at end of file diff --git a/src/node-asdf/install.sh b/src/node-asdf/install.sh index 36310a40b..f633abb4c 100755 --- a/src/node-asdf/install.sh +++ b/src/node-asdf/install.sh @@ -1,15 +1,14 @@ -#!/bin/bash -i set -e -source ./library_scripts.sh +. ./library_scripts.sh # nanolayer is a cli utility which keeps container layers as small as possible # source code: https://github.com/devcontainers-contrib/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 +# `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.4.45" +ensure_nanolayer nanolayer_location "v0.5.4" $nanolayer_location \ @@ -17,7 +16,8 @@ $nanolayer_location \ devcontainer-feature \ "ghcr.io/devcontainers-contrib/features/asdf-package:1.0.8" \ --option plugin='nodejs' --option version="$VERSION" - + echo 'Done!' + diff --git a/src/node-asdf/library_scripts.sh b/src/node-asdf/library_scripts.sh index 8f9bd9a0e..0d7f34d4b 100644 --- a/src/node-asdf/library_scripts.sh +++ b/src/node-asdf/library_scripts.sh @@ -1,4 +1,3 @@ -#!/bin/bash -i clean_download() { @@ -10,13 +9,13 @@ clean_download() { # The above steps will minimize the leftovers being created while installing the downloader # Supported distros: # debian/ubuntu/alpine - + url=$1 output_location=$2 tempdir=$(mktemp -d) downloader_installed="" - function _apt_get_install() { + _apt_get_install() { tempdir=$1 # copy current state of apt list - in order to revert back later (minimize contianer layer size) @@ -25,7 +24,7 @@ clean_download() { apt-get -y install --no-install-recommends wget ca-certificates } - function _apt_get_cleanup() { + _apt_get_cleanup() { tempdir=$1 echo "removing wget" @@ -36,7 +35,7 @@ clean_download() { rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists } - function _apk_install() { + _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 @@ -44,7 +43,7 @@ clean_download() { apk add --no-cache wget } - function _apk_cleanup() { + _apk_cleanup() { tempdir=$1 echo "removing wget" @@ -100,45 +99,39 @@ ensure_nanolayer() { 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" + __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) - if ! [[ $current_version == v* ]]; then - current_version=v$current_version - fi + current_version=$($__nanolayer_location --version) + 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 () { @@ -162,7 +155,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 @@ -172,7 +165,7 @@ ensure_nanolayer() { fi # Expose outside the resolved location - declare -g ${variable_name}=$nanolayer_location + export ${variable_name}=$__nanolayer_location } diff --git a/src/ruby-asdf/README.md b/src/ruby-asdf/README.md index 80937f386..40bc0bbf1 100644 --- a/src/ruby-asdf/README.md +++ b/src/ruby-asdf/README.md @@ -16,3 +16,5 @@ Installs Ruby via asdf. | Options Id | Description | Type | Default Value | |-----|-----|-----|-----| | version | Select the version to install. | string | latest | + + diff --git a/src/ruby-asdf/devcontainer-feature.json b/src/ruby-asdf/devcontainer-feature.json index 7001822cb..2dc08741e 100644 --- a/src/ruby-asdf/devcontainer-feature.json +++ b/src/ruby-asdf/devcontainer-feature.json @@ -3,7 +3,7 @@ "version": "0.0.1", "name": "Ruby (via asdf)", "documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/ruby-asdf", - "description": "Installs Ruby via asdf", + "description": "Installs Ruby via asdf.", "options": { "version": { "default": "latest", @@ -15,7 +15,6 @@ } }, "installsAfter": [ - "ghcr.io/devcontainers-contrib/features/asdf-package", - "ghcr.io/devcontainers-contrib/features/apt-get-packages" + "ghcr.io/devcontainers-contrib/features/asdf-package" ] -} +} \ No newline at end of file diff --git a/src/ruby-asdf/install.sh b/src/ruby-asdf/install.sh index eddf78f2b..051c213f0 100755 --- a/src/ruby-asdf/install.sh +++ b/src/ruby-asdf/install.sh @@ -1,15 +1,14 @@ -#!/bin/bash -i set -e -source ./library_scripts.sh +. ./library_scripts.sh # nanolayer is a cli utility which keeps container layers as small as possible # source code: https://github.com/devcontainers-contrib/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 +# `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.4.45" +ensure_nanolayer nanolayer_location "v0.5.4" $nanolayer_location \ @@ -17,7 +16,7 @@ $nanolayer_location \ devcontainer-feature \ "ghcr.io/devcontainers-contrib/features/apt-get-packages:1.0.6" \ --option packages='curl,ca-certificates,software-properties-common,build-essential,gnupg2,libreadline-dev,procps,dirmngr,gawk,autoconf,automake,bison,libffi-dev,libgdbm-dev,libncurses5-dev,libsqlite3-dev,libtool,libyaml-dev,pkg-config,sqlite3,zlib1g-dev,libgmp-dev,libssl-dev' - + $nanolayer_location \ @@ -25,7 +24,8 @@ $nanolayer_location \ devcontainer-feature \ "ghcr.io/devcontainers-contrib/features/asdf-package:1.0.8" \ --option plugin='ruby' --option version="$VERSION" - + echo 'Done!' + diff --git a/src/ruby-asdf/library_scripts.sh b/src/ruby-asdf/library_scripts.sh index 8f9bd9a0e..0d7f34d4b 100644 --- a/src/ruby-asdf/library_scripts.sh +++ b/src/ruby-asdf/library_scripts.sh @@ -1,4 +1,3 @@ -#!/bin/bash -i clean_download() { @@ -10,13 +9,13 @@ clean_download() { # The above steps will minimize the leftovers being created while installing the downloader # Supported distros: # debian/ubuntu/alpine - + url=$1 output_location=$2 tempdir=$(mktemp -d) downloader_installed="" - function _apt_get_install() { + _apt_get_install() { tempdir=$1 # copy current state of apt list - in order to revert back later (minimize contianer layer size) @@ -25,7 +24,7 @@ clean_download() { apt-get -y install --no-install-recommends wget ca-certificates } - function _apt_get_cleanup() { + _apt_get_cleanup() { tempdir=$1 echo "removing wget" @@ -36,7 +35,7 @@ clean_download() { rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists } - function _apk_install() { + _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 @@ -44,7 +43,7 @@ clean_download() { apk add --no-cache wget } - function _apk_cleanup() { + _apk_cleanup() { tempdir=$1 echo "removing wget" @@ -100,45 +99,39 @@ ensure_nanolayer() { 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" + __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) - if ! [[ $current_version == v* ]]; then - current_version=v$current_version - fi + current_version=$($__nanolayer_location --version) + 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 () { @@ -162,7 +155,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 @@ -172,7 +165,7 @@ ensure_nanolayer() { fi # Expose outside the resolved location - declare -g ${variable_name}=$nanolayer_location + export ${variable_name}=$__nanolayer_location } diff --git a/test/node-asdf/scenarios.json b/test/node-asdf/scenarios.json index 5bef3fcbf..64baed0a5 100644 --- a/test/node-asdf/scenarios.json +++ b/test/node-asdf/scenarios.json @@ -5,4 +5,4 @@ "node-asdf": {} } } -} +} \ No newline at end of file diff --git a/test/ruby-asdf/scenarios.json b/test/ruby-asdf/scenarios.json index 2e136b578..70885a815 100644 --- a/test/ruby-asdf/scenarios.json +++ b/test/ruby-asdf/scenarios.json @@ -5,4 +5,4 @@ "ruby-asdf": {} } } -} +} \ No newline at end of file