Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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/anaconda/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "anaconda",
"version": "1.0.13",
"version": "1.0.14",
"name": "Anaconda",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/anaconda",
"options": {
Expand Down
65 changes: 53 additions & 12 deletions src/anaconda/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
UPDATE_RC="${UPDATE_RC:-"true"}"
CONDA_DIR="${CONDA_DIR:-"/usr/local/conda"}"

set -eux
set -exo pipefail
export DEBIAN_FRONTEND=noninteractive

# Clean up
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/apt/lists/*

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.'
Expand Down Expand Up @@ -47,7 +47,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
Expand Down Expand Up @@ -75,6 +80,20 @@ check_packages() {
fi
}

sudo_if() {
COMMAND="$*"
if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then
su - "$USERNAME" -c "$COMMAND"
else
$COMMAND
fi
}

install_user_package() {
PACKAGE="$1"
sudo_if "${CONDA_DIR}/bin/python3" -m pip install --user --upgrade "$PACKAGE"
}

# Install Conda if it's missing
if ! conda --version &> /dev/null ; then
if ! cat /etc/group | grep -e "^conda:" > /dev/null 2>&1; then
Expand All @@ -83,30 +102,51 @@ if ! conda --version &> /dev/null ; then
usermod -a -G conda "${USERNAME}"

# Install dependencies
check_packages wget ca-certificates
check_packages wget ca-certificates libgtk-3-0

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
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
elif [ "${architecture}" = "aarch64" ]; then
su --login -c "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}" ${USERNAME} 2>&1
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}"

find "${CONDA_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s

# Temporary fixes
# Due to https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-23491
install_user_package certifi
# Due to https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-0286 and https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-23931
install_user_package pyopenssl
install_user_package cryptography
# Due to https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-40897
install_user_package setuptools
install_user_package tornado

rm /tmp/anaconda-install.sh
updaterc "export CONDA_DIR=${CONDA_DIR}/bin"
fi

Expand Down Expand Up @@ -136,6 +176,7 @@ if [ -f "/etc/bash.bashrc" ]; then
fi

# Clean up
apt-get -y clean
rm -rf /var/lib/apt/lists/*

echo "Done!"
30 changes: 30 additions & 0 deletions test/anaconda/install_anaconda_bookworm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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

30 changes: 30 additions & 0 deletions test/anaconda/install_anaconda_bullseye.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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

30 changes: 30 additions & 0 deletions test/anaconda/install_anaconda_jammy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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

30 changes: 30 additions & 0 deletions test/anaconda/install_anaconda_noble.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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

30 changes: 30 additions & 0 deletions test/anaconda/install_anaconda_noble_without_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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

47 changes: 47 additions & 0 deletions test/anaconda/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"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"
}
}
}
}