Skip to content

Commit ac24137

Browse files
Kaniska244abdurriq
andauthored
Move conda installation from deprecated DEBs to Miniconda installer (#1619)
* Move conda installation from deprecated DEBs to Miniconda installer * Fix missing newline at end of conda_channel_creation.sh * Fix missing newline at end of install_conda_package_after_upgrade.sh --------- Co-authored-by: Abdurrahmaan Iqbal <[email protected]>
1 parent dc8cf55 commit ac24137

8 files changed

Lines changed: 58 additions & 80 deletions

File tree

src/conda/NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ conda install python=3.7
1515

1616
## OS Support
1717

18-
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.
18+
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. Both `x86_64` and `aarch64` architectures are supported.
1919

2020
`bash` is required to execute the `install.sh` script.

src/conda/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A cross-platform, language-agnostic binary package manager
77

88
```json
99
"features": {
10-
"ghcr.io/devcontainers/features/conda:1": {}
10+
"ghcr.io/devcontainers/features/conda:2": {}
1111
}
1212
```
1313

src/conda/devcontainer-feature.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "conda",
3-
"version": "1.2.6",
3+
"version": "2.0.0",
44
"name": "Conda",
55
"description": "A cross-platform, language-agnostic binary package manager",
66
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/conda",
@@ -9,8 +9,8 @@
99
"type": "string",
1010
"proposals": [
1111
"latest",
12-
"4.11.0",
13-
"4.12.0"
12+
"24.11.3",
13+
"24.7.1"
1414
],
1515
"default": "latest",
1616
"description": "Select or enter a conda version."

src/conda/install.sh

Lines changed: 44 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
4545
fi
4646

4747
architecture="$(uname -m)"
48-
if [ "${architecture}" != "x86_64" ]; then
49-
echo "(!) Architecture $architecture unsupported"
50-
exit 1
51-
fi
48+
case "${architecture}" in
49+
x86_64) MINICONDA_ARCH="x86_64" ;;
50+
aarch64|arm64) MINICONDA_ARCH="aarch64" ;;
51+
*)
52+
echo "(!) Architecture $architecture unsupported"
53+
exit 1
54+
;;
55+
esac
5256

5357
# Checks if packages are installed and installs them if not
5458
check_packages() {
@@ -75,6 +79,17 @@ install_user_package() {
7579
sudo_if "${CONDA_DIR}/bin/python3" -m pip install --user --upgrade "$PACKAGE"
7680
}
7781

82+
accept_anaconda_tos_if_needed() {
83+
if ! "${CONDA_DIR}/bin/conda" tos --help > /dev/null 2>&1; then
84+
return 0
85+
fi
86+
87+
for channel in "https://repo.anaconda.com/pkgs/main" "https://repo.anaconda.com/pkgs/r"; do
88+
echo "Accepting Conda Terms of Service for ${channel}..."
89+
"${CONDA_DIR}/bin/conda" tos accept --override-channels --channel "${channel}"
90+
done
91+
}
92+
7893
# Install Conda if it's missing
7994
if ! conda --version &> /dev/null ; then
8095
if ! cat /etc/group | grep -e "^conda:" > /dev/null 2>&1; then
@@ -85,78 +100,36 @@ if ! conda --version &> /dev/null ; then
85100
# Install dependencies
86101
check_packages curl ca-certificates
87102

88-
echo "Installing Conda..."
103+
echo "Installing Conda via Miniconda installer..."
89104

90-
# Download .deb package directly from repository (bypassing SHA1 signature issue)
91-
TEMP_DEB="$(mktemp -t conda_XXXXXX.deb)"
92-
CONDA_REPO_BASE="https://repo.anaconda.com/pkgs/misc/debrepo/conda"
93-
94-
# Determine package filename based on requested version
95-
ARCH="$(dpkg --print-architecture 2>/dev/null || echo "amd64")"
96-
PACKAGES_URL="https://repo.anaconda.com/pkgs/misc/debrepo/conda/dists/stable/main/binary-${ARCH}/Packages"
97-
98-
if [ "${VERSION}" = "latest" ]; then
99-
# For latest, we need to query the repository to find the current version
100-
echo "Fetching package list to determine latest version..."
101-
CONDA_PKG_INFO=$(curl -fsSL "${PACKAGES_URL}" | grep -A 30 "^Package: conda$" | head -n 31)
102-
CONDA_VERSION=$(echo "${CONDA_PKG_INFO}" | grep "^Version:" | head -n 1 | awk '{print $2}')
103-
CONDA_FILENAME=$(echo "${CONDA_PKG_INFO}" | grep "^Filename:" | head -n 1 | awk '{print $2}')
104-
105-
if [ -z "${CONDA_VERSION}" ] || [ -z "${CONDA_FILENAME}" ]; then
106-
echo "ERROR: Could not determine latest conda version or filename from ${PACKAGES_URL}"
107-
echo "This may indicate an unsupported architecture or repository unavailability."
108-
rm -f "${TEMP_DEB}"
109-
exit 1
110-
fi
111-
112-
CONDA_PKG_NAME="${CONDA_FILENAME}"
113-
else
114-
# For specific versions, query the Packages file to find the exact filename
115-
echo "Fetching package list to find version ${VERSION}..."
116-
# Search for version pattern - user may specify 4.12.0 but package has 4.12.0-0
117-
CONDA_PKG_INFO=$(curl -fsSL "${PACKAGES_URL}" | grep -A 30 "^Package: conda$" | grep -B 5 -A 25 "^Version: ${VERSION}")
118-
CONDA_FILENAME=$(echo "${CONDA_PKG_INFO}" | grep "^Filename:" | head -n 1 | awk '{print $2}')
119-
120-
if [ -z "${CONDA_FILENAME}" ]; then
121-
echo "ERROR: Could not find conda version ${VERSION} in ${PACKAGES_URL}"
122-
echo "Please verify the version specified is valid."
123-
rm -f "${TEMP_DEB}"
124-
exit 1
125-
fi
126-
127-
CONDA_PKG_NAME="${CONDA_FILENAME}"
128-
fi
129-
130-
# Download the .deb package
131-
CONDA_DEB_URL="${CONDA_REPO_BASE}/${CONDA_PKG_NAME}"
132-
echo "Downloading conda package from ${CONDA_DEB_URL}..."
133-
134-
if ! curl -fsSL "${CONDA_DEB_URL}" -o "${TEMP_DEB}"; then
135-
echo "ERROR: Failed to download conda .deb package from ${CONDA_DEB_URL}"
136-
echo "Please verify the version specified is valid."
137-
rm -f "${TEMP_DEB}"
138-
exit 1
139-
fi
140-
141-
# Verify the package was downloaded successfully
142-
if [ ! -f "${TEMP_DEB}" ] || [ ! -s "${TEMP_DEB}" ]; then
143-
echo "ERROR: Conda .deb package file is missing or empty"
144-
rm -f "${TEMP_DEB}"
105+
# Download and run the official Miniconda installer
106+
MINICONDA_INSTALLER="$(mktemp -t miniconda_XXXXXX.sh)"
107+
MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-${MINICONDA_ARCH}.sh"
108+
109+
echo "Downloading Miniconda installer from ${MINICONDA_URL}..."
110+
if ! curl -fsSL --connect-timeout 10 --max-time 120 "${MINICONDA_URL}" -o "${MINICONDA_INSTALLER}"; then
111+
echo "ERROR: Failed to download Miniconda installer from ${MINICONDA_URL}"
112+
rm -f "${MINICONDA_INSTALLER}"
145113
exit 1
146114
fi
147-
148-
# Install the package using apt (which handles dependencies automatically)
149-
echo "Installing conda package..."
150-
if ! apt-get install -y "${TEMP_DEB}"; then
151-
echo "ERROR: Failed to install conda package"
152-
rm -f "${TEMP_DEB}"
153-
exit 1
115+
116+
# Run installer in batch mode (no prompts) and install to CONDA_DIR
117+
bash "${MINICONDA_INSTALLER}" -b -p "${CONDA_DIR}"
118+
rm -f "${MINICONDA_INSTALLER}"
119+
120+
# Conda defaults channels now require a non-interactive ToS acknowledgement.
121+
accept_anaconda_tos_if_needed
122+
123+
# Install specific conda version if requested (latest Miniconda already bundles a recent conda)
124+
if [ "${VERSION}" != "latest" ]; then
125+
echo "Installing conda version ${VERSION}..."
126+
if ! "${CONDA_DIR}/bin/conda" install -y "conda=${VERSION}"; then
127+
echo "ERROR: Failed to install conda version ${VERSION}. Please verify the version is valid and available."
128+
exit 1
129+
fi
154130
fi
155-
156-
# Clean up downloaded package
157-
rm -f "${TEMP_DEB}"
158131

159-
CONDA_SCRIPT="/opt/conda/etc/profile.d/conda.sh"
132+
CONDA_SCRIPT="${CONDA_DIR}/etc/profile.d/conda.sh"
160133
. $CONDA_SCRIPT
161134

162135
if [ "${ADD_CONDA_FORGE}" = "true" ]; then

test/conda/conda_channel_creation.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ source dev-container-features-test-lib
77

88
## Test Conda
99
check "conda-update-conda" bash -c "conda update -c defaults -y conda"
10-
check "conda-install-tensorflow" bash -c "conda create --name test-env -c conda-forge --yes tensorflow"
11-
check "conda-install-pytorch" bash -c "conda create --name test-env -c conda-forge --yes pytorch"
10+
check "conda-install-tensorflow" bash -c "conda create --name tensorflow-test-env -c conda-forge --yes tensorflow"
11+
check "conda-install-pytorch" bash -c "conda create --name pytorch-test-env -c conda-forge --yes pytorch"
1212

1313
# Report result
1414
reportResults

test/conda/install_conda.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ set -e
55
# Optional: Import test library
66
source dev-container-features-test-lib
77

8-
check "conda" conda --version | grep 4.12.0
8+
check "conda" conda --version
9+
check "conda update" conda update -n base -c defaults -y conda
10+
check "conda updated version" conda --version
911
check "conda-forge" conda config --show channels | grep conda-forge
1012
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
1113

test/conda/install_conda_package_after_upgrade.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ source dev-container-features-test-lib
99
# This validates the fix for the pluggy/conda version mismatch issue where
1010
# conda self-upgrades but the older pluggy lacks the 'wrapper' attribute
1111
check "conda version" conda --version
12+
check "conda update" conda update -n base -c defaults -y conda
13+
check "conda updated version" conda --version
1214
check "install pyopenssl" conda install -y -c defaults pyopenssl
1315
check "install cryptography" conda install -y -c defaults cryptography
16+
check "install scipy with bioconda" conda install -y -c bioconda scipy
1417
check "conda-forge" conda config --show channels | grep conda-forge
1518
check "if conda-notice.txt exists" cat /usr/local/etc/vscode-dev-containers/conda-notice.txt
1619

test/conda/scenarios.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"image": "ubuntu:noble",
44
"features": {
55
"conda": {
6-
"version": "4.12.0",
6+
"version": "latest",
77
"addCondaForge": "true"
88
}
99
}

0 commit comments

Comments
 (0)