From 149da0115192473d4a449d882004c004c0921636 Mon Sep 17 00:00:00 2001 From: Diego Ferigo Date: Fri, 3 Aug 2018 11:58:09 +0200 Subject: [PATCH] Added support to nvidia runtime through docker-compose Closes https://github.com/diegoferigo/development-iit/issues/1 --- Development/compose/.env | 4 +++- Development/compose/docker-compose.yml | 3 ++- Development/compose/docker-workspace.sh | 28 ++++++++++++++----------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Development/compose/.env b/Development/compose/.env index 5e6ee01..0ef5ba6 100644 --- a/Development/compose/.env +++ b/Development/compose/.env @@ -1,5 +1,7 @@ # Docker Images -DEVELOPMENT_IMAGE=diegoferigo/development +DEVELOPMENT_IMAGE=diegoferigo/development:nvidia +DOCKER_RUNTIME=nvidia +#DOCKER_RUNTIME=runc # X11 authentication XSOCK=/tmp/.X11-unix diff --git a/Development/compose/docker-compose.yml b/Development/compose/docker-compose.yml index a7c5b7c..acc47e8 100644 --- a/Development/compose/docker-compose.yml +++ b/Development/compose/docker-compose.yml @@ -1,8 +1,9 @@ -version: '2' +version: '2.3' services: development: image: ${DEVELOPMENT_IMAGE} + runtime: ${DOCKER_RUNTIME} container_name: development environment: # ROS/YARP Variables diff --git a/Development/compose/docker-workspace.sh b/Development/compose/docker-workspace.sh index a2b28d7..781ac50 100755 --- a/Development/compose/docker-workspace.sh +++ b/Development/compose/docker-workspace.sh @@ -92,9 +92,7 @@ function print_help() function find_docker_bin() { msg "Finding the docker-compose binary" - if [ -x "$(which nvidia-docker-compose)" ] ; then - DOCKERCOMPOSE_BIN=$(which nvidia-docker-compose) - elif [ -x "$(which docker-compose)" ] ; then + if [ -x "$(which docker-compose)" ] ; then DOCKERCOMPOSE_BIN=$(which docker-compose) else err "Docker compose not found! Check your \$PATH" @@ -108,7 +106,7 @@ function handle_persistent_resources() # Persistent files for file in "${PERSISTENT_FILES[@]}" ; do if [ ! -f $file ] ; then - mkdir $(dirname $file) || (err2 "Unable to create $(dirname $file)" && exit 1) + mkdir $(dirname $file) || (err2 "Unable to create $(dirname $file)" && exit 1) touch $file || (err2 "Unable to create $file" && exit 1) fi done @@ -126,18 +124,24 @@ function docker_workspace() case $1 in start|up) msg "Starting up..." + # Set the X11 authentication resources msg "Setting up X11 resources" - if [ ! -e $XAUTH ] ; then - msg2 "Creating authentication file" - touch $XAUTH - chmod 777 $XAUTH - else - msg2 "X11 authentication file found" + if [ -e $XAUTH ] ; then + msg2 "Removing old authentication file" + rm -rf $XAUTH fi + + msg2 "Creating authentication file" + touch $XAUTH + msg2 "Granting X11 permissions" - xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - - + if [ $(xauth nlist $DISPLAY | grep -v ffff | wc -l) -gt 1 ] ; then + err "Your system has more than one authentication entry. Exiting" && exit 1 + fi + xauth nlist $DISPLAY | grep -v ffff | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - + chmod 664 $XAUTH + msg "Setting up the project's resources" # If a folder is passed as $2, mount it into the host and set it as # working directory