aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamruddhi Khandale <skhandale@microsoft.com>2022-09-01 19:41:22 +0300
committerGitHub <noreply@github.com>2022-09-01 19:41:22 +0300
commit14d98b7795ca6f7333cb168ca7be2fd4baf1a882 (patch)
tree739f540408557d29d1782924795b5cc35ea7f8e7
parentd50ef0016a2f8b3baeb88cd26f508f3b4b204573 (diff)
Adds a new Conda Feature (#127)
* add conda Feature * addCondaForge
-rw-r--r--.github/workflows/test-all.yaml2
-rw-r--r--.github/workflows/test-pr.yaml1
-rw-r--r--src/conda/NOTES.md13
-rw-r--r--src/conda/devcontainer-feature.json27
-rw-r--r--src/conda/install.sh101
-rw-r--r--test/conda/install_conda.sh12
-rw-r--r--test/conda/scenarios.json11
-rwxr-xr-xtest/conda/test.sh12
8 files changed, 179 insertions, 0 deletions
diff --git a/.github/workflows/test-all.yaml b/.github/workflows/test-all.yaml
index 621ee83..6d2ba07 100644
--- a/.github/workflows/test-all.yaml
+++ b/.github/workflows/test-all.yaml
@@ -16,6 +16,7 @@ jobs:
"aws-cli",
"azure-cli",
"common-utils",
+ "conda",
"desktop-lite",
"docker-from-docker",
"docker-in-docker",
@@ -65,6 +66,7 @@ jobs:
"aws-cli",
"azure-cli",
"common-utils",
+ "conda",
"desktop-lite",
"docker-from-docker",
"docker-in-docker",
diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml
index c8dec8f..8d21b03 100644
--- a/.github/workflows/test-pr.yaml
+++ b/.github/workflows/test-pr.yaml
@@ -16,6 +16,7 @@ jobs:
aws-cli: ./**/aws-cli/**
azure-cli: ./**/azure-cli/**
common-utils: ./**/common-utils/**
+ conda: ./**/conda/**
desktop-lite: ./**/desktop-lite/**
docker-from-docker: ./**/docker-from-docker/**
docker-in-docker: ./**/docker-in-docker/**
diff --git a/src/conda/NOTES.md b/src/conda/NOTES.md
new file mode 100644
index 0000000..58450c6
--- /dev/null
+++ b/src/conda/NOTES.md
@@ -0,0 +1,13 @@
+## 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
+```
diff --git a/src/conda/devcontainer-feature.json b/src/conda/devcontainer-feature.json
new file mode 100644
index 0000000..81999a7
--- /dev/null
+++ b/src/conda/devcontainer-feature.json
@@ -0,0 +1,27 @@
+{
+ "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:"
+ }
+}
diff --git a/src/conda/install.sh b/src/conda/install.sh
new file mode 100644
index 0000000..ee4ff09
--- /dev/null
+++ b/src/conda/install.sh
@@ -0,0 +1,101 @@
+#!/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!"
diff --git a/test/conda/install_conda.sh b/test/conda/install_conda.sh
new file mode 100644
index 0000000..92fd2e0
--- /dev/null
+++ b/test/conda/install_conda.sh
@@ -0,0 +1,12 @@
+#!/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
diff --git a/test/conda/scenarios.json b/test/conda/scenarios.json
new file mode 100644
index 0000000..9cc2fc1
--- /dev/null
+++ b/test/conda/scenarios.json
@@ -0,0 +1,11 @@
+{
+ "install_conda": {
+ "image": "ubuntu:focal",
+ "features": {
+ "conda": {
+ "version": "4.12.0",
+ "addCondaForge": "true"
+ }
+ }
+ }
+}
diff --git a/test/conda/test.sh b/test/conda/test.sh
new file mode 100755
index 0000000..69120d9
--- /dev/null
+++ b/test/conda/test.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+set -e
+
+# Optional: Import test library
+source dev-container-features-test-lib
+
+# Definition specific tests
+check "version" conda --version
+
+# Report result
+reportResults