Skip to content
This repository was archived by the owner on Jan 12, 2025. It is now read-only.

Commit f47402a

Browse files
fix: standard format for node-asdf and ruby-asdf features (#539)
1 parent 48e41e0 commit f47402a

File tree

10 files changed

+62
-73
lines changed

10 files changed

+62
-73
lines changed

src/node-asdf/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ Installs Node.js via asdf.
1616
| Options Id | Description | Type | Default Value |
1717
|-----|-----|-----|-----|
1818
| version | Select the version to install. | string | latest |
19+
20+

src/node-asdf/devcontainer-feature.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"name": "Node.js (via asdf)",
55
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/node-asdf",
6-
"description": "Installs Node.js via asdf",
6+
"description": "Installs Node.js via asdf.",
77
"options": {
88
"version": {
99
"default": "latest",
@@ -17,4 +17,4 @@
1717
"installsAfter": [
1818
"ghcr.io/devcontainers-contrib/features/asdf-package"
1919
]
20-
}
20+
}

src/node-asdf/install.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
#!/bin/bash -i
21

32
set -e
43

5-
source ./library_scripts.sh
4+
. ./library_scripts.sh
65

76
# nanolayer is a cli utility which keeps container layers as small as possible
87
# source code: https://github.com/devcontainers-contrib/nanolayer
9-
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
10-
# and if missing - will download a temporary copy that automatically get deleted at the end
8+
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
9+
# and if missing - will download a temporary copy that automatically get deleted at the end
1110
# of the script
12-
ensure_nanolayer nanolayer_location "v0.4.45"
11+
ensure_nanolayer nanolayer_location "v0.5.4"
1312

1413

1514
$nanolayer_location \
1615
install \
1716
devcontainer-feature \
1817
"ghcr.io/devcontainers-contrib/features/asdf-package:1.0.8" \
1918
--option plugin='nodejs' --option version="$VERSION"
20-
19+
2120

2221

2322
echo 'Done!'
23+

src/node-asdf/library_scripts.sh

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/bin/bash -i
21

32

43
clean_download() {
@@ -10,13 +9,13 @@ clean_download() {
109
# The above steps will minimize the leftovers being created while installing the downloader
1110
# Supported distros:
1211
# debian/ubuntu/alpine
13-
12+
1413
url=$1
1514
output_location=$2
1615
tempdir=$(mktemp -d)
1716
downloader_installed=""
1817

19-
function _apt_get_install() {
18+
_apt_get_install() {
2019
tempdir=$1
2120

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

28-
function _apt_get_cleanup() {
27+
_apt_get_cleanup() {
2928
tempdir=$1
3029

3130
echo "removing wget"
@@ -36,15 +35,15 @@ clean_download() {
3635
rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists
3736
}
3837

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

4443
apk add --no-cache wget
4544
}
4645

47-
function _apk_cleanup() {
46+
_apk_cleanup() {
4847
tempdir=$1
4948

5049
echo "removing wget"
@@ -100,45 +99,39 @@ ensure_nanolayer() {
10099
local variable_name=$1
101100

102101
local required_version=$2
103-
# normalize version
104-
if ! [[ $required_version == v* ]]; then
105-
required_version=v$required_version
106-
fi
107102

108-
local nanolayer_location=""
103+
local __nanolayer_location=""
109104

110105
# If possible - try to use an already installed nanolayer
111-
if [[ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]]; then
112-
if [[ -z "${NANOLAYER_CLI_LOCATION}" ]]; then
106+
if [ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]; then
107+
if [ -z "${NANOLAYER_CLI_LOCATION}" ]; then
113108
if type nanolayer >/dev/null 2>&1; then
114109
echo "Found a pre-existing nanolayer in PATH"
115-
nanolayer_location=nanolayer
110+
__nanolayer_location=nanolayer
116111
fi
117112
elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ] ; then
118-
nanolayer_location=${NANOLAYER_CLI_LOCATION}
119-
echo "Found a pre-existing nanolayer which were given in env variable: $nanolayer_location"
113+
__nanolayer_location=${NANOLAYER_CLI_LOCATION}
114+
echo "Found a pre-existing nanolayer which were given in env variable: $__nanolayer_location"
120115
fi
121116

122117
# make sure its of the required version
123-
if ! [[ -z "${nanolayer_location}" ]]; then
118+
if ! [ -z "${__nanolayer_location}" ]; then
124119
local current_version
125-
current_version=$($nanolayer_location --version)
126-
if ! [[ $current_version == v* ]]; then
127-
current_version=v$current_version
128-
fi
120+
current_version=$($__nanolayer_location --version)
121+
129122

130123
if ! [ $current_version == $required_version ]; then
131124
echo "skipping usage of pre-existing nanolayer. (required version $required_version does not match existing version $current_version)"
132-
nanolayer_location=""
125+
__nanolayer_location=""
133126
fi
134127
fi
135128

136129
fi
137130

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

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

144137
clean_up () {
@@ -162,7 +155,7 @@ ensure_nanolayer() {
162155

163156
tar xfzv $tmp_dir/$tar_filename -C "$tmp_dir"
164157
chmod a+x $tmp_dir/nanolayer
165-
nanolayer_location=$tmp_dir/nanolayer
158+
__nanolayer_location=$tmp_dir/nanolayer
166159

167160

168161
else
@@ -172,7 +165,7 @@ ensure_nanolayer() {
172165
fi
173166

174167
# Expose outside the resolved location
175-
declare -g ${variable_name}=$nanolayer_location
168+
export ${variable_name}=$__nanolayer_location
176169

177170
}
178171

src/ruby-asdf/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ Installs Ruby via asdf.
1616
| Options Id | Description | Type | Default Value |
1717
|-----|-----|-----|-----|
1818
| version | Select the version to install. | string | latest |
19+
20+

src/ruby-asdf/devcontainer-feature.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"name": "Ruby (via asdf)",
55
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/ruby-asdf",
6-
"description": "Installs Ruby via asdf",
6+
"description": "Installs Ruby via asdf.",
77
"options": {
88
"version": {
99
"default": "latest",
@@ -15,7 +15,6 @@
1515
}
1616
},
1717
"installsAfter": [
18-
"ghcr.io/devcontainers-contrib/features/asdf-package",
19-
"ghcr.io/devcontainers-contrib/features/apt-get-packages"
18+
"ghcr.io/devcontainers-contrib/features/asdf-package"
2019
]
21-
}
20+
}

src/ruby-asdf/install.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
#!/bin/bash -i
21

32
set -e
43

5-
source ./library_scripts.sh
4+
. ./library_scripts.sh
65

76
# nanolayer is a cli utility which keeps container layers as small as possible
87
# source code: https://github.com/devcontainers-contrib/nanolayer
9-
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
10-
# and if missing - will download a temporary copy that automatically get deleted at the end
8+
# `ensure_nanolayer` is a bash function that will find any existing nanolayer installations,
9+
# and if missing - will download a temporary copy that automatically get deleted at the end
1110
# of the script
12-
ensure_nanolayer nanolayer_location "v0.4.45"
11+
ensure_nanolayer nanolayer_location "v0.5.4"
1312

1413

1514
$nanolayer_location \
1615
install \
1716
devcontainer-feature \
1817
"ghcr.io/devcontainers-contrib/features/apt-get-packages:1.0.6" \
1918
--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'
20-
19+
2120

2221

2322
$nanolayer_location \
2423
install \
2524
devcontainer-feature \
2625
"ghcr.io/devcontainers-contrib/features/asdf-package:1.0.8" \
2726
--option plugin='ruby' --option version="$VERSION"
28-
27+
2928

3029

3130
echo 'Done!'
31+

src/ruby-asdf/library_scripts.sh

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/bin/bash -i
21

32

43
clean_download() {
@@ -10,13 +9,13 @@ clean_download() {
109
# The above steps will minimize the leftovers being created while installing the downloader
1110
# Supported distros:
1211
# debian/ubuntu/alpine
13-
12+
1413
url=$1
1514
output_location=$2
1615
tempdir=$(mktemp -d)
1716
downloader_installed=""
1817

19-
function _apt_get_install() {
18+
_apt_get_install() {
2019
tempdir=$1
2120

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

28-
function _apt_get_cleanup() {
27+
_apt_get_cleanup() {
2928
tempdir=$1
3029

3130
echo "removing wget"
@@ -36,15 +35,15 @@ clean_download() {
3635
rm -r /var/lib/apt/lists && mv $tempdir/lists /var/lib/apt/lists
3736
}
3837

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

4443
apk add --no-cache wget
4544
}
4645

47-
function _apk_cleanup() {
46+
_apk_cleanup() {
4847
tempdir=$1
4948

5049
echo "removing wget"
@@ -100,45 +99,39 @@ ensure_nanolayer() {
10099
local variable_name=$1
101100

102101
local required_version=$2
103-
# normalize version
104-
if ! [[ $required_version == v* ]]; then
105-
required_version=v$required_version
106-
fi
107102

108-
local nanolayer_location=""
103+
local __nanolayer_location=""
109104

110105
# If possible - try to use an already installed nanolayer
111-
if [[ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]]; then
112-
if [[ -z "${NANOLAYER_CLI_LOCATION}" ]]; then
106+
if [ -z "${NANOLAYER_FORCE_CLI_INSTALLATION}" ]; then
107+
if [ -z "${NANOLAYER_CLI_LOCATION}" ]; then
113108
if type nanolayer >/dev/null 2>&1; then
114109
echo "Found a pre-existing nanolayer in PATH"
115-
nanolayer_location=nanolayer
110+
__nanolayer_location=nanolayer
116111
fi
117112
elif [ -f "${NANOLAYER_CLI_LOCATION}" ] && [ -x "${NANOLAYER_CLI_LOCATION}" ] ; then
118-
nanolayer_location=${NANOLAYER_CLI_LOCATION}
119-
echo "Found a pre-existing nanolayer which were given in env variable: $nanolayer_location"
113+
__nanolayer_location=${NANOLAYER_CLI_LOCATION}
114+
echo "Found a pre-existing nanolayer which were given in env variable: $__nanolayer_location"
120115
fi
121116

122117
# make sure its of the required version
123-
if ! [[ -z "${nanolayer_location}" ]]; then
118+
if ! [ -z "${__nanolayer_location}" ]; then
124119
local current_version
125-
current_version=$($nanolayer_location --version)
126-
if ! [[ $current_version == v* ]]; then
127-
current_version=v$current_version
128-
fi
120+
current_version=$($__nanolayer_location --version)
121+
129122

130123
if ! [ $current_version == $required_version ]; then
131124
echo "skipping usage of pre-existing nanolayer. (required version $required_version does not match existing version $current_version)"
132-
nanolayer_location=""
125+
__nanolayer_location=""
133126
fi
134127
fi
135128

136129
fi
137130

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

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

144137
clean_up () {
@@ -162,7 +155,7 @@ ensure_nanolayer() {
162155

163156
tar xfzv $tmp_dir/$tar_filename -C "$tmp_dir"
164157
chmod a+x $tmp_dir/nanolayer
165-
nanolayer_location=$tmp_dir/nanolayer
158+
__nanolayer_location=$tmp_dir/nanolayer
166159

167160

168161
else
@@ -172,7 +165,7 @@ ensure_nanolayer() {
172165
fi
173166

174167
# Expose outside the resolved location
175-
declare -g ${variable_name}=$nanolayer_location
168+
export ${variable_name}=$__nanolayer_location
176169

177170
}
178171

test/node-asdf/scenarios.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"node-asdf": {}
66
}
77
}
8-
}
8+
}

test/ruby-asdf/scenarios.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"ruby-asdf": {}
66
}
77
}
8-
}
8+
}

0 commit comments

Comments
 (0)