NASA-Openscapes / corn

Base image for the NASA-Openscapes Jupyterhub
MIT License
5 stars 5 forks source link

Install vscode extensions, attempt #3 #32

Closed ateucher closed 5 months ago

ateucher commented 5 months ago

Initially we assumed that extensions would be default be installed in $HOME, which we wanted to avoid (#30, #31). But it turns out that code-server from conda-forge sets the --extensions-dir flag to ${CONDA_PREFIX}/share/code-server/extensions, which resolves to /srv/conda/envs/notebook/share/code-server/extensions - i.e., outside of $HOME. So I don't think we need to configure anything; we should just be able to install the extensions we want in the Dockerfile.

I tested this locally (macOS arm), and it worked:

docker build -t openscapes/corn:test . --platform linux/amd64
docker run -p 8888:8888 --platform linux/amd64 openscapes/corn:test jupyter lab --ip 0.0.0.0

I had to remove the postBuild, as the awsv2 install was failing (on macOS).

ateucher commented 5 months ago

I've been trying out the quarto extension with a locally built image with these changes. It wants to write to $HOME/.cache/, but it belongs to root? In the hub however, ~/.cache belongs to jovyan (which I assume is how it should be). I don't see how these changes would cause that... any ideas @betolink?

ateucher commented 5 months ago

I just ran the image built from main, and it also has ~/.cache owned by root... that must be fixed when it's deployed. So maybe that's not an issue here...

eeholmes commented 3 weeks ago

@ateucher Thanks for your help today! For your reference here is my final script. Has some extra error checking.

#!/bin/bash
# Required User: NB_USER

# Install VSCode extensions. 
# These get installed to $CONDA_PREFIX/envs/notebook/share/code-server/extensions/

# Check if a filename argument is provided
if [ -z "$1" ]; then
    echo "Error: install-vscode-extensions.sh requires an input file of extension names (typically called vscode-extensions.txt)." >&2
    echo "Usage: RUN /pyrocket_scripts/install-vscode-extensions.sh <filename>"
    exit 1
fi

# Check if running as root and switch to NB_USER if needed
if [[ $(id -u) -eq 0 ]]; then
    echo "Switching to ${NB_USER} to run install-vscode-extensions.sh"
    exec su "${NB_USER}" -c "/bin/bash $0 $1"  # Pass along the filename argument
fi

echo "Running install-vscode-extensions.sh as ${NB_USER}"

ext_file="$1"

# Verify that ext_file exists and is a file
if [ ! -f "${ext_file}" ]; then
    echo "  Error: Specified file '$ext_file' does not exist."
    exit 1
fi

# Install each extension listed in the file
while IFS= read -r EXT; do
    if code-server --install-extension "$EXT"; then
        echo "  Successfully installed extension: $EXT"
    else
        echo "  Failed to install extension: $EXT" >&2
    fi
done < "$ext_file"

echo "  Success! install-vscode-extensions.sh"