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

[Bug]: elixir-asdf feature installation fails on Debian base images due to installing Ubuntu specific apt packages #543

Merged
merged 3 commits into from
Oct 3, 2023
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/elixir-asdf/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "elixir-asdf",
"version": "2.0.18",
"version": "2.0.19",
"name": "Elixir (via asdf)",
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/elixir-asdf",
"description": "Elixir is a functional, concurrent, general-purpose programming language that runs on the BEAM virtual machine which is also used to implement the Erlang programming language.",
Expand Down
9 changes: 4 additions & 5 deletions src/elixir-asdf/install.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/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
# of the script
ensure_nanolayer nanolayer_location "v0.4.45"
ensure_nanolayer nanolayer_location "v0.5.5"


$nanolayer_location \
install \
devcontainer-feature \
"ghcr.io/devcontainers-contrib/features/apt-get-packages:1.0.4" \
--option packages='build-essential,autoconf,m4,libncurses5-dev,libwxgtk3.0-gtk3-dev,libwxgtk-webview3.0-gtk3-dev,libgl1-mesa-dev,libglu1-mesa-dev,libpng-dev,libssh-dev,unixodbc-dev,xsltproc,fop,libxml2-utils,libncurses-dev,openjdk-11-jdk,procps'
"ghcr.io/devcontainers-contrib/features/apt-get-packages:1.0.6" \
--option packages='build-essential,autoconf,m4,libncurses5-dev,libwxgtk3.*-dev,libwxgtk-webview3.*-dev,libgl1-mesa-dev,libglu1-mesa-dev,libpng-dev,libssh-dev,unixodbc-dev,xsltproc,fop,libxml2-utils,libncurses-dev,openjdk-1*-jdk,procps'



Expand Down
45 changes: 19 additions & 26 deletions src/elixir-asdf/library_scripts.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash -i


clean_download() {
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -36,15 +35,15 @@ 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

apk add --no-cache wget
}

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

echo "removing wget"
Expand Down Expand Up @@ -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 () {
Expand All @@ -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
Expand All @@ -172,7 +165,7 @@ ensure_nanolayer() {
fi

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

}

Expand Down
2 changes: 1 addition & 1 deletion src/erlang-asdf/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "erlang-asdf",
"version": "2.0.17",
"version": "2.0.18",
"name": "Erlang (via asdf)",
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/erlang-asdf",
"description": "Erlang is a general-purpose, concurrent, functional programming language, and a garbage-collected runtime system.",
Expand Down
9 changes: 4 additions & 5 deletions src/erlang-asdf/install.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/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
# of the script
ensure_nanolayer nanolayer_location "v0.4.45"
ensure_nanolayer nanolayer_location "v0.5.5"


$nanolayer_location \
install \
devcontainer-feature \
"ghcr.io/devcontainers-contrib/features/apt-get-packages:1.0.4" \
--option packages='build-essential,autoconf,m4,libncurses5-dev,libwxgtk3.0-gtk3-dev,libwxgtk-webview3.0-gtk3-dev,libgl1-mesa-dev,libglu1-mesa-dev,libpng-dev,libssh-dev,unixodbc-dev,xsltproc,fop,libxml2-utils,libncurses-dev,openjdk-11-jdk,procps'
"ghcr.io/devcontainers-contrib/features/apt-get-packages:1.0.6" \
--option packages='build-essential,autoconf,m4,libncurses5-dev,libwxgtk3.*-dev,libwxgtk-webview3.*-dev,libgl1-mesa-dev,libglu1-mesa-dev,libpng-dev,libssh-dev,unixodbc-dev,xsltproc,fop,libxml2-utils,libncurses-dev,openjdk-1*-jdk,procps'



Expand Down
45 changes: 19 additions & 26 deletions src/erlang-asdf/library_scripts.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash -i


clean_download() {
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -36,15 +35,15 @@ 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

apk add --no-cache wget
}

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

echo "removing wget"
Expand Down Expand Up @@ -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 () {
Expand All @@ -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
Expand All @@ -172,7 +165,7 @@ ensure_nanolayer() {
fi

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

}

Expand Down
22 changes: 20 additions & 2 deletions test/elixir-asdf/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
{
"test": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"test_debian_11": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore (cleanup): This scenario was renamed, but the corresponding scenario test file test.sh was not renamed, it now sits there as a leftover.

"image": "mcr.microsoft.com/devcontainers/base:debian-11",
"features": {
"elixir-asdf": {}
}
},
"test_debian_12": {
"image": "mcr.microsoft.com/devcontainers/base:debian-12",
"features": {
"elixir-asdf": {}
}
},
"test_ubuntu_2004": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
"features": {
"elixir-asdf": {}
}
},
"test_ubuntu_2204": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04",
"features": {
"elixir-asdf": {}
}
Expand Down
9 changes: 9 additions & 0 deletions test/elixir-asdf/test_debian_12.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -i

set -e

source dev-container-features-test-lib

check "elixir --version" elixir --version

reportResults
9 changes: 9 additions & 0 deletions test/elixir-asdf/test_ubuntu_2004.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -i

set -e

source dev-container-features-test-lib

check "elixir --version" elixir --version

reportResults
9 changes: 9 additions & 0 deletions test/elixir-asdf/test_ubuntu_2204.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -i

set -e

source dev-container-features-test-lib

check "elixir --version" elixir --version

reportResults
8 changes: 7 additions & 1 deletion test/erlang-asdf/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"test": {
"test_debian_bullseye": {
"image": "debian:bullseye",
"features": {
"erlang-asdf": {}
}
},
"test_ubuntu": {
"image": "ubuntu",
"features": {
"erlang-asdf": {}
}
}
}
Loading