Skip to content

Commit

Permalink
feat(features-pixi): adding pixi devcontainer feature! (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: John Muchovej <jmuchovej@users.noreply.github.com>
Co-authored-by: John Muchovej <jmuchovej@users.noreply.github.com>
  • Loading branch information
jmuchovej and jmuchovej authored Sep 14, 2024
1 parent d6e3f4a commit fe8df11
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 4 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/features-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ jobs:
matrix:
features:
- asdf
- pixi
baseImage:
- debian:latest
- ubuntu:latest
- alpine:latest
- mcr.microsoft.com/devcontainers/base:ubuntu
- mcr.microsoft.com/devcontainers/base:alpine
- mcr.microsoft.com/devcontainers/base:debian
steps:
- uses: actions/checkout@v4

Expand All @@ -40,6 +38,7 @@ jobs:
matrix:
features:
- asdf
- pixi
steps:
- uses: actions/checkout@v4

Expand Down
16 changes: 16 additions & 0 deletions features/src/pixi/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Limitations

The `onCreateCommand` relies on having passwordless `sudo` access. Thus, it demands that
both `sudo` is available and the `${remoteUser}` has passwordless access!

## OS Support
This feature has been tested on Debian-based distributions (Ubuntu & Debian). As of
**14 Sep 2024**, **Alpine is unsupported**. This is because Alpine does not provide a
the virtual package `__glibc`, which means that packages have `glibc` dependencies
cannot be used (_many of the core `conda` packages require `glibc` in some fashion).
Thus, there's little use in starting from an `alpine` image.

More details on [this GitHub issue][no-alpine-install] (tracked by the folks at
Prefix.dev).

[no-alpine-install]: https://github.com/prefix-dev/pixi-docker/issues/23
36 changes: 36 additions & 0 deletions features/src/pixi/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "https://github.com/devcontainers/spec/raw/main/schemas/devContainerFeature.schema.json",
"id": "pixi",
"version": "0.1.0",
"name": "pixi",
"documentationURL": "https://github.com/jmuchovej/devcontainers/tree/main/features/pixi",
"description": "Add Pixi (by Prefix.dev) to your Dev Container!",
"options": {
"version": {
"type": "string",
"proposals": [
"latest",
"v0.29.0",
"v0.28.0",
"v0.27.0",
],
"default": "latest",
"description": "Select (or enter) the version of pixi you want to install."
},
},
"installsAfter": [
"ghcr.io/devcontainers/features/git",
"ghcr.io/devcontainers/features/github-cli",
"ghcr.io/devcontainers/features/common-utils"
],
// This mount is provided to ease developer experience, particularly on MacOS.
// By default, MacOS is case-insensitive; however, Linux is [by default] case-sensitive.
// Thus, when running Linux-based containers but bind-mounting `/path/to/.pixi`, any
// libraries with case-sensitive filenames (e.g., `ncurses`) will fail to install.
"mounts": [
{ "type": "volume", "target": "${containerWorkspaceFolder}/.pixi", "source": "${devcontainerId}-pixi", }
],
"onCreateCommand": {
"update .pixi permissions": "sudo chown -R $(id -u) ${containerWorkspaceFolder}/.pixi",
},
}
28 changes: 28 additions & 0 deletions features/src/pixi/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
set -e

if [ "$(id -u)" -ne 0 ]; then
err 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi

PIXI_HOME=/usr/local
PIXI_VERSION="${VERSION:-"latest"}"
[ "${PIXI_VERSION}" != "latest" ] && PIXI_VERSION="${PIXI_VERSION}"

curl -fsSL https://pixi.sh/install.sh | \
PIXI_VERSION="${PIXI_VERSION}" PIXI_HOME="${PIXI_HOME}" bash

if [ -f "/etc/bash.bashrc" ]; then
echo <<-EOF | tee -a /etc/bash.bashrc
# From: jmuchovej/features/pixi
eval "$(pixi completion --shell bash)"
EOF
fi

if [ -f "/etc/zsh/zshrc" ]; then
echo <<-EOF | tee -a /etc/zsh/zshrc
# From: jmuchovej/features/pixi
eval "$(pixi completion --shell zsh)"
EOF
fi
5 changes: 5 additions & 0 deletions features/test/pixi/on-debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

export VERSION
$(dirname ${0})/test.sh
5 changes: 5 additions & 0 deletions features/test/pixi/on-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

export VERSION
$(dirname ${0})/test.sh
58 changes: 58 additions & 0 deletions features/test/pixi/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"on-ubuntu": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/common-utils": {
"installZsh": false,
"installOhMyZsh": false,
"upgradePackages": false
},
"pixi": {
"version": "latest"
}
},
"remoteUser": "vscode"
},
"on-debian": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"ghcr.io/devcontainers/features/common-utils": {
"installZsh": false,
"installOhMyZsh": false,
"upgradePackages": false
},
"pixi": {
"version": "latest"
}
},
"remoteUser": "vscode"
},
"with-v0.29.0": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/common-utils": {
"installZsh": false,
"installOhMyZsh": false,
"upgradePackages": false
},
"pixi": {
"version": "v0.29.0"
}
},
"remoteUser": "vscode"
},
"with-v0.28.0": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/common-utils": {
"installZsh": false,
"installOhMyZsh": false,
"upgradePackages": false
},
"pixi": {
"version": "v0.28.0"
}
},
"remoteUser": "vscode"
}
}
42 changes: 42 additions & 0 deletions features/test/pixi/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# This is a generic test since the primary difference in tests is across versions.
set -e

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

if [ "${VERSION}" = "latest" ]; then
VERSION="$(curl -s https://api.github.com/repos/prefix-dev/pixi/releases | jq -r ".[0].tag_name")"
fi

VERSION_CHECK="${VERSION//v}"

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib.
check \
"validate pixi \`${VERSION_CHECK}\` is installed" \
bash -c "pixi --version | grep \"${VERSION_CHECK}\""

check \
"test that we can \`init\` a pixi project" \
bash -c "pixi init -p linux-aarch64 -p linux-64 -c conda-forge"

check \
"can add libraries?" \
bash -c "pixi add scipy numpy pandas; pixi clean"

check \
"install pixi environments" \
bash -c "pixi install -a"

check \
"run pixi tasks" \
bash -c "pixi run python --version"

check \
"did libraries install?"
bash -c "pixi run python -c 'import pandas'"

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
5 changes: 5 additions & 0 deletions features/test/pixi/with-v0.28.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

export VERSION
$(dirname ${0})/test.sh
5 changes: 5 additions & 0 deletions features/test/pixi/with-v0.29.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

export VERSION
$(dirname ${0})/test.sh

0 comments on commit fe8df11

Please sign in to comment.