Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(esi-shell): exec user command, pass through container options #82

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/build-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -79,15 +80,15 @@ 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

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
68 changes: 37 additions & 31 deletions esi-shell
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- <COMMAND>"
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}"
}
Expand Down Expand Up @@ -86,7 +99,7 @@ warn() {
}


while [ $# -gt 0 ]
while [[ $# -gt 0 ]]
do
case $1 in
-v | --version)
Expand All @@ -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
Expand Down Expand Up @@ -248,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)"

Expand All @@ -256,29 +283,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 ${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