Skip to content

Commit

Permalink
First stable version
Browse files Browse the repository at this point in the history
- PATH bug fixed (injected in userconfig.sh)
- PYTHONPATH being unset
- internal ipykernel installed
  • Loading branch information
rodrigo-sobral committed Feb 26, 2024
1 parent 8805d61 commit 2f7205a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
7 changes: 3 additions & 4 deletions swan-cern/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ LABEL maintainer="[email protected]"
ARG NB_UID="1000"
ARG BUILD_TAG=daily
ENV VERSION_DOCKER_IMAGE=$BUILD_TAG
ENV PATH="/srv/singleuser/bin:${PATH}"

RUN echo "Building swan-cern image with tag ${VERSION_DOCKER_IMAGE} from parent tag ${VERSION_PARENT}."

Expand Down Expand Up @@ -42,9 +41,9 @@ USER root

# Crate a new bin path for allowing the user to run it with an alias
# Add script for virtual environment creation
RUN mkdir /srv/singleuser/bin
RUN mv /srv/singleuser/makenv.sh /srv/singleuser/bin/makenv
RUN chmod u+x /srv/singleuser/bin/makenv
RUN mkdir /srv/singleuser/bin && \
mv /srv/singleuser/makenv.sh /srv/singleuser/bin/makenv && \
chmod +x /srv/singleuser/bin/makenv

# HTCondor requirements
RUN dnf install -y \
Expand Down
40 changes: 23 additions & 17 deletions swan-cern/scripts/others/makenv.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _log () {
NAME_ENV=$1
REQ_PATH=$2

# Help page
# Help page (passing -h as first argument)
if [ "$NAME_ENV" = "-h" ]; then
_log "This script builds a virtual environment."
_log "Usage: makenv <virtualenv_name> <requirements_file>"
Expand All @@ -28,44 +28,50 @@ fi
# Checks if a name for the environment is given
if [ -z "$NAME_ENV" ]; then
_log "ERROR: No virtual environment name provided."
exit 0
exit 1
fi

# Checks if a requirements file is given
if [ -z "$REQ_PATH" ]; then
_log "ERROR: No requirements file provided."
exit 0
exit 1
fi

# Checks if the requirements file is found
if [ ! -f "$REQ_PATH" ]; then
_log "ERROR: Requirements file not found."
exit 0
exit 1
fi

# Checks if an environment with the same name was already created
if [ -d "/home/$USER/${NAME_ENV}" ]; then
_log "ERROR: Virtual environment already exists. Skipping..."
exit 0
_log "ERROR: Virtual environment already exists."
exit 1
fi

# Create virtual environment using Python venv
_log "WARNING: Creating ${NAME_ENV} virtual environment..."

python3 -m venv /home/$USER/${NAME_ENV}
_log "Creating ${NAME_ENV} virtual environment..."
python3 -m venv /home/$USER/${NAME_ENV} --copies

# Activate the created virtual environment
_log "WARNING: Activating virtual environment..."

_log "Activating virtual environment..."
source /home/$USER/${NAME_ENV}/bin/activate

# Install kernel (within the environment), so it can be ran in Jupyter
/home/$USER/${NAME_ENV}/bin/python3 -m ipykernel install --name ${NAME_ENV} --display-name "Python (${NAME_ENV})" --prefix /home/$USER/.local
# Unset PYTHONPATH to avoid that the virtual environment uses the system packages
unset PYTHONPATH

# Ensure pip is installed on venv so ipykernel and requirements can be installed
python3 -m ensurepip --upgrade

# Configure venv kernel so Jupyter can recognise it as a proper Python language
/home/$USER/${NAME_ENV}/bin/python3 -I /srv/singleuser/configure_kernels_and_terminal.py
# Install ipykernel so the kernel can be used in Jupyter
pip3 install ipykernel -q

# Install kernel (within the environment), so it can be ran in Jupyter
python3 -m ipykernel install --name ${NAME_ENV} --display-name "Python (${NAME_ENV})" --prefix /home/$USER/.local

# Install the given requirements
_log "WARNING: Installing packages from ${REQ_PATH}..."
_log "Installing packages from ${REQ_PATH}..."
pip3 install -q -r ${REQ_PATH}

/home/$USER/${NAME_ENV}/bin/python3 -m pip install -r ${REQ_PATH}
_log "Virtual environment ${NAME_ENV} created successfully."
_log "WARNING: You may need to refresh the page"
3 changes: 3 additions & 0 deletions swan/scripts/others/userconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ ln -s $LOCAL_NB_NBEXTENSIONS $NBCONFIG/notebook.json
START_TIME_SETUP_LCG=$( date +%s.%N )
export JUPYTER_DATA_DIR=$LCG_VIEW/share/jupyter

# Path for scripts to build custom user environments (e.g. makenv.sh)
export PATH="${PATH}:/srv/singleuser/bin"

# Setup LCG
source $LCG_VIEW/setup.sh

Expand Down

0 comments on commit 2f7205a

Please sign in to comment.