Unverified Commit 5fda4439 authored by Kaniska's avatar Kaniska Committed by GitHub

[anaconda] - feature installation support for arm64/ aarch64. (#1342)

* anaconda feature installation support for arm64/ aarch64.

* Adding support for RHEL based linux distributions.

* Correction in the CONDA directory permission

* Update src/anaconda/install.sh, removing whitespaces
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>

* Update src/anaconda/install.sh, removing whitespaces
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>

* Update src/anaconda/install.sh
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>

* Update src/anaconda/install.sh, removing whitespaces as suggested by copilot
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>

* Update src/anaconda/install.sh, removing whitespaces
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>

* Update test/anaconda/scenarios.json, removing whitespaces
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>

* Apply suggestions from code review
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>

* Apply suggestions from code review
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>

* Correcting incorrect code review suggestion by Copilot

* Corrections based on review comments.

* Further corrections based on review comments.

---------
Co-authored-by: 's avatarKaniska244 <kaniska244@example.com>
Co-authored-by: 's avatarCopilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: 's avatarÁlvaro Rausell Guiard <33221237+AlvaroRausell@users.noreply.github.com>
parent 91460a32
......@@ -17,4 +17,7 @@ conda install python=3.7
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.
Also RHEL based linux distributions such as almalinux, rockylinux, fedora are supported now.
Please do note that Alpine and cbl-mariner aren't supported due system level restrictions with the anaconda installer.
`bash` is required to execute the `install.sh` script.
......@@ -35,7 +35,7 @@ conda install python=3.7
## OS Support
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.
Also RHEL based linux distributions such as almalinux, rockylinux, fedora are supported now.
`bash` is required to execute the `install.sh` script.
......
{
"id": "anaconda",
"version": "1.0.13",
"version": "1.1.0",
"name": "Anaconda",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/anaconda",
"options": {
......
......@@ -13,11 +13,63 @@ USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
UPDATE_RC="${UPDATE_RC:-"true"}"
CONDA_DIR="${CONDA_DIR:-"/usr/local/conda"}"
set -eux
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
# Detect package manager and set install command
detect_package_manager() {
if command -v apt-get > /dev/null; then
PKG_MANAGER="apt-get"
PKG_UPDATE="apt-get update -y"
PKG_INSTALL="apt-get -y install --no-install-recommends"
PKG_CLEAN="apt-get -y clean"
PKG_LISTS="/var/lib/apt/lists/*"
PKG_QUERY="dpkg -s"
elif command -v apk > /dev/null; then
PKG_MANAGER="apk"
PKG_UPDATE="apk update"
PKG_INSTALL="apk add --no-cache"
PKG_CLEAN="rm -rf /var/cache/apk/*"
PKG_LISTS="/var/cache/apk/*"
PKG_QUERY="apk info -e"
elif command -v dnf > /dev/null; then
PKG_MANAGER="dnf"
PKG_UPDATE="dnf -y makecache"
PKG_INSTALL="dnf -y install"
PKG_CLEAN="dnf clean all"
PKG_LISTS="/var/cache/dnf/*"
PKG_QUERY="rpm -q"
elif command -v microdnf > /dev/null; then
PKG_MANAGER="microdnf"
PKG_UPDATE="microdnf update"
PKG_INSTALL="microdnf install -y"
PKG_CLEAN="microdnf clean all"
PKG_LISTS="/var/cache/yum/*"
PKG_QUERY="rpm -q"
elif command -v tdnf > /dev/null; then
PKG_MANAGER="tdnf"
PKG_UPDATE="tdnf makecache"
PKG_INSTALL="tdnf install -y"
PKG_CLEAN="tdnf clean all"
PKG_LISTS="/var/cache/tdnf/*"
PKG_QUERY="rpm -q"
elif command -v yum > /dev/null; then
PKG_MANAGER="yum"
PKG_UPDATE="yum -y makecache"
PKG_INSTALL="yum -y install"
PKG_CLEAN="yum clean all"
PKG_LISTS="/var/cache/yum/*"
PKG_QUERY="rpm -q"
else
echo "No supported package manager found (apt-get, apk, dnf, microdnf, tdnf, yum)."
exit 1
fi
}
detect_package_manager
# Clean up
rm -rf /var/lib/apt/lists/*
eval "$PKG_CLEAN"
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
......@@ -47,7 +99,12 @@ elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
fi
architecture="$(uname -m)"
if [ "${architecture}" != "x86_64" ]; then
# Normalize arm64 to aarch64 for consistency
if [ "${architecture}" = "arm64" ]; then
architecture="aarch64"
fi
if [ "${architecture}" != "x86_64" ] && [ "${architecture}" != "aarch64" ]; then
echo "(!) Architecture $architecture unsupported"
exit 1
fi
......@@ -66,12 +123,76 @@ updaterc() {
# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
for pkg in "$@"; do
# Use PKG_QUERY variable to check if package is installed
if ! eval "$PKG_QUERY $pkg" > /dev/null 2>&1; then
# Package not installed, check if we need to update package lists
if [ "$PKG_MANAGER" = "apt-get" ]; then
# For apt-get, check if package lists are empty
if [ "$(find "$PKG_LISTS" | wc -l)" = "0" ]; then
echo "Running $PKG_UPDATE..."
eval "$PKG_UPDATE"
fi
else
# For other package managers, always update before installing
echo "Running $PKG_UPDATE..."
eval "$PKG_UPDATE"
fi
# Install the package
echo "Installing package: $pkg"
eval "$PKG_INSTALL $pkg"
else
echo "Package $pkg is already installed"
fi
apt-get -y install --no-install-recommends "$@"
done
}
sudo_if() {
COMMAND="$*"
if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then
if command -v runuser > /dev/null; then
runuser -l "$USERNAME" -c "$COMMAND"
elif command -v su > /dev/null; then
su - "$USERNAME" -c "$COMMAND"
elif command -v sudo > /dev/null; then
sudo -u "$USERNAME" -i bash -c "$COMMAND"
else
# Fallback: execute as root (not ideal but works in containers)
echo "Warning: No user switching command available, running as root"
eval "$COMMAND"
fi
else
eval "$COMMAND"
fi
}
run_as_user() {
local user="$1"
shift
local cmd="$*"
if command -v runuser > /dev/null; then
if [ "$PKG_MANAGER" = "apk" ]; then
runuser "$user" -c "$cmd"
else
runuser -l "$user" -c "$cmd"
fi
elif command -v su > /dev/null; then
if [ "$PKG_MANAGER" = "apk" ]; then
su "$user" -c "$cmd"
else
su --login -c "$cmd" "$user"
fi
elif command -v sudo > /dev/null; then
if [ "$PKG_MANAGER" = "apk" ]; then
sudo -u "$user" sh -c "$cmd"
else
sudo -u "$user" -i bash -c "$cmd"
fi
else
echo "Warning: No user switching command available, running as root"
eval "$cmd"
fi
}
......@@ -83,30 +204,46 @@ if ! conda --version &> /dev/null ; then
usermod -a -G conda "${USERNAME}"
# Install dependencies
check_packages wget ca-certificates
if [ "$PKG_MANAGER" = "apt-get" ]; then
check_packages wget ca-certificates libgtk-3-0
elif [ "$PKG_MANAGER" = "apk" ]; then
check_packages wget ca-certificates gtk+3.0
else
check_packages wget ca-certificates gtk3
fi
mkdir -p $CONDA_DIR
chown -R "${USERNAME}:conda" "${CONDA_DIR}"
chmod -R g+r+w "${CONDA_DIR}"
find "${CONDA_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s
chmod -R g+r+w "${CONDA_DIR}"
echo "Installing Anaconda..."
CONDA_VERSION=$VERSION
if [ "${VERSION}" = "latest" ] || [ "${VERSION}" = "lts" ]; then
CONDA_VERSION="2021.11"
CONDA_VERSION="2024.10-1"
fi
su --login -c "export http_proxy=${http_proxy:-} && export https_proxy=${https_proxy:-} \
&& wget -q https://repo.anaconda.com/archive/Anaconda3-${CONDA_VERSION}-Linux-x86_64.sh -O /tmp/anaconda-install.sh \
&& /bin/bash /tmp/anaconda-install.sh -u -b -p ${CONDA_DIR}" ${USERNAME} 2>&1
if [ "${architecture}" = "x86_64" ]; then
run_as_user "${USERNAME}" "export http_proxy=${http_proxy:-} && export https_proxy=${https_proxy:-} \
&& wget -q https://repo.anaconda.com/archive/Anaconda3-${CONDA_VERSION}-Linux-x86_64.sh -O /tmp/anaconda-install.sh \
&& /bin/bash /tmp/anaconda-install.sh -u -b -p ${CONDA_DIR}"
elif [ "${architecture}" = "aarch64" ]; then
run_as_user "${USERNAME}" "export http_proxy=${http_proxy:-} && export https_proxy=${https_proxy:-} \
&& wget -q https://repo.anaconda.com/archive/Anaconda3-${CONDA_VERSION}-Linux-aarch64.sh -O /tmp/anaconda-install.sh \
&& /bin/bash /tmp/anaconda-install.sh -u -b -p ${CONDA_DIR}"
fi
if [ "${VERSION}" = "latest" ] || [ "${VERSION}" = "lts" ]; then
PATH=$PATH:${CONDA_DIR}/bin
conda update -y conda
fi
rm /tmp/anaconda-install.sh
chown -R "${USERNAME}:conda" "${CONDA_DIR}"
chmod -R g+r+w "${CONDA_DIR}"
rm /tmp/anaconda-install.sh
updaterc "export CONDA_DIR=${CONDA_DIR}/bin"
fi
......@@ -135,7 +272,6 @@ if [ -f "/etc/bash.bashrc" ]; then
echo "${notice_script}" | tee -a /etc/bash.bashrc
fi
# Clean up
rm -rf /var/lib/apt/lists/*
# Final clean up
eval "$PKG_CLEAN"
echo "Done!"
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "conda" conda --version
check "python" python --version
check "pylint" pylint --version
check "flake8" flake8 --version
check "autopep8" autopep8 --version
check "yapf" yapf --version
check "pydocstyle" pydocstyle --version
check "pycodestyle" pycodestyle --version
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
check "certifi" pip show certifi | grep Version
check "cryptography" pip show cryptography | grep Version
check "setuptools" pip show setuptools | grep Version
check "tornado" pip show tornado | grep Version
check "conda-update-conda" bash -c "conda update -y conda"
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
# Report result
reportResults
{
"install_anaconda_noble": {
"image": "mcr.microsoft.com/devcontainers/base:noble",
"user": "vscode",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_jammy": {
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"user": "vscode",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_bookworm": {
"image": "mcr.microsoft.com/devcontainers/base:bookworm",
"user": "vscode",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_bullseye": {
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"user": "vscode",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_noble_without_user": {
"image": "mcr.microsoft.com/devcontainers/base:noble",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_almalinux8": {
"image": "almalinux:8",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_almalinux9": {
"image": "almalinux:9",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_rockylinux8": {
"image": "rockylinux:8",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_rockylinux9": {
"image": "rockylinux:9",
"features": {
"anaconda": {
"version": "latest"
}
}
},
"install_anaconda_fedora": {
"image": "fedora",
"features": {
"anaconda": {
"version": "latest"
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment