From bd9bff7ec0a080324812073be394daa00b7f7626 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Wed, 29 May 2024 15:11:45 -0400 Subject: [PATCH 1/5] fix: use single command to execute container commands --- esi-shell | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/esi-shell b/esi-shell index b2807ae..638b365 100755 --- a/esi-shell +++ b/esi-shell @@ -256,28 +256,8 @@ ohai "Using esi-shell image: ${IMG}" if [[ -n "${USABLE_DOCKER-}" ]] then - cmd="docker run --rm -dit ${DOCKER_GPU-} ${DOCKER_PLATFORM-} ${DOCKER_BIND_VOLUME-} -e OPTICKS_OPTIX_PREFIX=$OPTIX_DIR $IMG" - CONTAINER_ID=$(exec $cmd) - - if [ $? -ne 0 ] - then - abort "Failed to start esi-shell" - fi - - CONTAINER_ID=$(echo $CONTAINER_ID | cut -c -12) - ohai "Running docker container $CONTAINER_ID" - - ohai "Setting up opticks environment. Please wait..." - if [[ -d $WORKDIR/.opticks ]] - then - ohai "Found existing $WORKDIR/.opticks. Will use it" - else - ohai "Creating new $WORKDIR/.opticks required by opticks" - docker exec -it $CONTAINER_ID sh -c 'cp -r $ESI_DIR/.opticks $HOME/' - fi - - docker exec -it $CONTAINER_ID /opt/nvidia/nvidia_entrypoint.sh - confirm "Stop and remove container? [Y/n]" yes && docker rm -f $CONTAINER_ID || ohai "Remove container manually: docker rm -f $CONTAINER_ID" + cmd="docker run --rm -it ${DOCKER_GPU-} ${DOCKER_PLATFORM-} ${DOCKER_BIND_VOLUME-} -e OPTICKS_OPTIX_PREFIX=$OPTIX_DIR $IMG" + exec $cmd else abort "Docker client (>= $REQUIRED_DOCKER_VERSION) must be installed to proceed." From 5b0ff881bf71c27c5f99442798452335af55ac12 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Fri, 10 May 2024 10:05:16 -0400 Subject: [PATCH 2/5] feat(esi-shell): exec user command, pass through container options --- esi-shell | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/esi-shell b/esi-shell index 638b365..71cc2a8 100755 --- a/esi-shell +++ b/esi-shell @@ -29,21 +29,34 @@ REQUIRED_DOCKER_VERSION=23.0.0 IMAGE_NAME="ghcr.io/bnlnpps/esi-shell" DEFAULT_VERSION="latest" VERSION=$DEFAULT_VERSION +CONTAINER_COMMAND= +CONTAINER_OPTIONS= usage() { echo "Start esi-shell, the ESI containerized software environment." echo "" echo "USAGE:" - echo " ./esi-shell [OPTIONS] [ -- COMMAND ]" + echo " ./esi-shell [OPTIONS] [COMMAND] [-- CONTAINER_OPTIONS]" echo "" - echo "OPTIONAL ARGUMENTS:" - echo " -v, --version Version to install (Default: $DEFAULT_VERSION)" + echo "OPTIONS:" + echo " -v, --version Specific esi-shell version to use (Default: $DEFAULT_VERSION)" echo " -h, --help Print this message" echo "" + echo "COMMAND is a command to execute in the container, leave it empty for interactive shell. For example:" + echo " pwd" + echo " ls -la" + echo " echo '\$HOME'" + echo " tests/test_opticks.sh" + echo "" + echo "CONTAINER_OPTIONS will be passed to the underlying container command. For example:" + echo " -- --volume \$PWD/mytests:/tmp/mytests" + echo " -- -v \$HOME/optix:/usr/local/optix -e OPTICKS_OPTIX_PREFIX=/usr/local/optix" + echo "" echo "EXAMPLES:" echo " - Start an interactive shell: ./esi-shell" - echo " - Use different version: ./esi-shell -v 0.1.0" - echo " - Execute a single command: ./esi-shell -- " + echo " - Use specific version: ./esi-shell -v 0.1.0" + echo " - Execute a single command: ./esi-shell echo \$OPTIX_DIR" + echo " - Configure remote image: ./esi-shell -- --pull=always -e HOME=\$HOME" echo "" exit "${1:-0}" } @@ -86,7 +99,7 @@ warn() { } -while [ $# -gt 0 ] +while [[ $# -gt 0 ]] do case $1 in -v | --version) @@ -95,15 +108,24 @@ do shift ;; -h | --help) - usage + usage 0 ;; --) shift + CONTAINER_OPTIONS="$@" break ;; - *) + -*) warn "Unrecognized option: '$1'" usage 1 + break + ;; + *) + _ALL_OTHER_ARGS="$@" + CONTAINER_COMMAND=${_ALL_OTHER_ARGS%% -- *} + CONTAINER_OPTIONS=${_ALL_OTHER_ARGS#* -- } + CONTAINER_OPTIONS=$([[ $CONTAINER_OPTIONS == $CONTAINER_COMMAND ]] && echo "" || echo $CONTAINER_OPTIONS) + break ;; esac done @@ -256,9 +278,8 @@ ohai "Using esi-shell image: ${IMG}" if [[ -n "${USABLE_DOCKER-}" ]] then - cmd="docker run --rm -it ${DOCKER_GPU-} ${DOCKER_PLATFORM-} ${DOCKER_BIND_VOLUME-} -e OPTICKS_OPTIX_PREFIX=$OPTIX_DIR $IMG" + cmd="docker run --rm -it ${DOCKER_GPU-} ${DOCKER_PLATFORM-} ${DOCKER_BIND_VOLUME-} -e OPTICKS_OPTIX_PREFIX=${OPTIX_DIR} ${CONTAINER_OPTIONS} ${IMG} ${CONTAINER_COMMAND}" exec $cmd - else abort "Docker client (>= $REQUIRED_DOCKER_VERSION) must be installed to proceed." fi From 558f4bcc6f9486a717569769a5c57b209a498a7d Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Fri, 31 May 2024 10:38:42 -0400 Subject: [PATCH 3/5] ci: run test command in esi-shell --- .github/workflows/build-pull-request.yml | 6 +++++- .github/workflows/release.yml | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-pull-request.yml b/.github/workflows/build-pull-request.yml index 17872a0..230b711 100644 --- a/.github/workflows/build-pull-request.yml +++ b/.github/workflows/build-pull-request.yml @@ -50,6 +50,10 @@ jobs: rm -rf /home/runner/.buildx-cache mv /home/runner/.buildx-cache-new /home/runner/.buildx-cache - - name: Run tests + - name: Test image run: | docker run --rm ${{ env.IMAGE_NAME }}:${{ env.TAG }} tests/test_opticks.sh + + - name: Test esi-shell + run: | + ./esi-shell -v ${{ env.TAG }} "opticks-full-prepare && opticks-t" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4b80c0b..684cc6a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,8 +42,8 @@ jobs: cache-from: ${{ env.IMAGE_NAME }}:latest cache-to: type=inline - - name: Run tests - run: docker run --rm ${{ env.IMAGE_NAME }}:latest tests/test_opticks.sh + - name: Test esi-shell + run: ./esi-shell "opticks-full-prepare && opticks-t" - name: Declare latest and push run: docker push ${{ env.IMAGE_NAME }}:latest From 0cf2a438ffc1038c1fac0aed2e7bb43d5183cb31 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Fri, 31 May 2024 18:03:10 -0400 Subject: [PATCH 4/5] fix(env): activate virtual environment via poetry --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0d60d45..e4b4e84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,6 +67,7 @@ ENV OPTICKS_COMPUTE_CAPABILITY=89 ENV LD_LIBRARY_PATH=${OPTICKS_PREFIX}/lib:${LD_LIBRARY_PATH} ENV PATH=${OPTICKS_PREFIX}/lib:${PATH} ENV NVIDIA_DRIVER_CAPABILITIES=graphics,compute,utility +ENV VIRTUAL_ENV_DISABLE_PROMPT=1 WORKDIR $ESI_DIR @@ -79,9 +80,11 @@ COPY README.md . COPY NVIDIA-OptiX-SDK-7.6.0-linux64-x86_64.sh . COPY pyproject.toml . +RUN poetry install RUN patch -p1 opticks/sysrap/sevt.py patches/opticks-fix-update-array-dtype-for-numpy-1.26.patch COPY <<-"EOF" /etc/profile.d/z20_opticks.sh + source $(poetry env info --path)/bin/activate source $OPTICKS_HOME/opticks.bash opticks- EOF @@ -89,5 +92,3 @@ EOF RUN mkdir -p $OPTIX_DIR && ./NVIDIA-OptiX-SDK-7.6.0-linux64-x86_64.sh --skip-license --prefix=$OPTIX_DIR RUN opticks-full RUN rm -fr $OPTIX_DIR/* $ESI_DIR/NVIDIA-OptiX-SDK-7.6.0-linux64-x86_64.sh - -RUN poetry install From 4c600c5ea0367df1be1c4d33dd6ea353d1573a69 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Fri, 31 May 2024 18:45:45 -0400 Subject: [PATCH 5/5] fix(esi-shell): run commands without TTY --- esi-shell | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/esi-shell b/esi-shell index 71cc2a8..5ac4fd9 100755 --- a/esi-shell +++ b/esi-shell @@ -270,6 +270,11 @@ done # DOCKER_PLATFORM="--platform linux/amd64" #fi +if [[ -z ${CONTAINER_COMMAND-} ]] +then + CONTAINER_OPTIONS+=" -i -t" +fi + USABLE_SINGULARITY="$(find_tool singularity)" USABLE_DOCKER="$(find_tool docker)" @@ -278,7 +283,7 @@ ohai "Using esi-shell image: ${IMG}" if [[ -n "${USABLE_DOCKER-}" ]] then - cmd="docker run --rm -it ${DOCKER_GPU-} ${DOCKER_PLATFORM-} ${DOCKER_BIND_VOLUME-} -e OPTICKS_OPTIX_PREFIX=${OPTIX_DIR} ${CONTAINER_OPTIONS} ${IMG} ${CONTAINER_COMMAND}" + cmd="docker run --rm ${DOCKER_GPU-} ${DOCKER_PLATFORM-} ${DOCKER_BIND_VOLUME-} -e OPTICKS_OPTIX_PREFIX=${OPTIX_DIR} ${CONTAINER_OPTIONS} ${IMG} ${CONTAINER_COMMAND}" exec $cmd else abort "Docker client (>= $REQUIRED_DOCKER_VERSION) must be installed to proceed."