Unverified Commit 14d98b77 authored by Samruddhi Khandale's avatar Samruddhi Khandale Committed by GitHub

Adds a new Conda Feature (#127)

* add conda Feature

* addCondaForge
parent d50ef001
...@@ -16,6 +16,7 @@ jobs: ...@@ -16,6 +16,7 @@ jobs:
"aws-cli", "aws-cli",
"azure-cli", "azure-cli",
"common-utils", "common-utils",
"conda",
"desktop-lite", "desktop-lite",
"docker-from-docker", "docker-from-docker",
"docker-in-docker", "docker-in-docker",
...@@ -65,6 +66,7 @@ jobs: ...@@ -65,6 +66,7 @@ jobs:
"aws-cli", "aws-cli",
"azure-cli", "azure-cli",
"common-utils", "common-utils",
"conda",
"desktop-lite", "desktop-lite",
"docker-from-docker", "docker-from-docker",
"docker-in-docker", "docker-in-docker",
......
...@@ -16,6 +16,7 @@ jobs: ...@@ -16,6 +16,7 @@ jobs:
aws-cli: ./**/aws-cli/** aws-cli: ./**/aws-cli/**
azure-cli: ./**/azure-cli/** azure-cli: ./**/azure-cli/**
common-utils: ./**/common-utils/** common-utils: ./**/common-utils/**
conda: ./**/conda/**
desktop-lite: ./**/desktop-lite/** desktop-lite: ./**/desktop-lite/**
docker-from-docker: ./**/docker-from-docker/** docker-from-docker: ./**/docker-from-docker/**
docker-in-docker: ./**/docker-in-docker/** docker-in-docker: ./**/docker-in-docker/**
......
## Using Conda
This Feature includes [the `conda` package manager](https://docs.conda.io/projects/conda/en/latest/index.html) which is a part of the [Anaconda Distribution](https://repo.anaconda.com). Additional packages installed using Conda will be downloaded from Anaconda or another repository if you configure one. To reconfigure Conda in this container to access an alternative repository, please see information on [configuring Conda channels here](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/channels.html ).
Access to the Anaconda repository is covered by the [Anaconda Terms of Service](https://legal.anaconda.com/policies/en/?name=terms-of-service), which may require some organizations to obtain a commercial license from Anaconda. **However**, when used with GitHub Codespaces or GitHub Actions, **all users are permitted** to use the Anaconda Repository through the service, including organizations normally required by Anaconda to obtain a paid license for commercial activities. Note that third-party packages may be licensed by their publishers in ways that impact your intellectual property, and are used at your own risk.
## Installing a different version of Python
As covered in the [user FAQ](https://docs.anaconda.com/anaconda/user-guide/faq) for Anaconda, you can install different versions of Python than the one in this image by running the following from a terminal:
```bash
conda install python=3.7
```
{
"id": "conda",
"version": "1.0.0",
"name": "Conda - A cross-platform, language-agnostic binary package manager",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/conda",
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"4.11.0",
"4.12.0"
],
"default": "latest",
"description": "Select or enter a conda version."
},
"addCondaForge": {
"type": "boolean",
"default": false,
"description": "Add conda-forge channel to the config?"
}
},
"containerEnv": {
"CONDA_DIR": "/opt/conda",
"PATH": "${PATH}:${CONDA_DIR}/bin:"
}
}
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
VERSION=${VERSION:-"latest"}
ADD_CONDA_FORGE=$ADDCONDAFORGE
USERNAME="automatic"
UPDATE_RC="true"
CONDA_DIR="/opt/conda"
set -eux
export DEBIAN_FRONTEND=noninteractive
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.'
exit 1
fi
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
rm -f /etc/profile.d/00-restore-env.sh
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
chmod +x /etc/profile.d/00-restore-env.sh
# Determine the appropriate non-root user
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
if id -u "${CURRENT_USER}" > /dev/null 2>&1; then
USERNAME="${CURRENT_USER}"
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
USERNAME=root
fi
architecture="$(uname -m)"
if [ "${architecture}" != "x86_64" ]; then
echo "(!) Architecture $architecture unsupported"
exit 1
fi
# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt-get update -y
apt-get -y install --no-install-recommends "$@"
# Clean up
apt-get clean -y
rm -rf /var/lib/apt/lists/*
fi
}
# Install Conda if it's missing
if ! conda --version &> /dev/null ; then
if ! cat /etc/group | grep -e "^conda:" > /dev/null 2>&1; then
groupadd -r conda
fi
usermod -a -G conda "${USERNAME}"
# Install dependencies
check_packages curl ca-certificates gnupg2
echo "Installing Conda..."
curl -sS https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > /usr/share/keyrings/conda-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/conda-archive-keyring.gpg] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" > /etc/apt/sources.list.d/conda.list
CONDA_PKG="conda=${VERSION}-0"
if [ "${VERSION}" = "latest" ]; then
CONDA_PKG="conda"
fi
check_packages $CONDA_PKG
CONDA_SCRIPT="/opt/conda/etc/profile.d/conda.sh"
. $CONDA_SCRIPT
if [ "${ADD_CONDA_FORGE}" = "true" ]; then
conda config --add channels conda-forge
fi
conda config --set channel_priority strict
conda config --set env_prompt '({name})'
echo "source ${CONDA_SCRIPT}" >> ~/.bashrc
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
fi
echo "Done!"
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "conda" conda --version | grep 4.12.0
check "conda-forge" conda config --show channels | grep conda-forge
# Report result
reportResults
{
"install_conda": {
"image": "ubuntu:focal",
"features": {
"conda": {
"version": "4.12.0",
"addCondaForge": "true"
}
}
}
}
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "version" conda --version
# Report result
reportResults
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