forked from TobiasNorlund/retro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·90 lines (76 loc) · 2.24 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
set -e
# Path to repo/project root dir (independent of pwd)
PROJECT_ROOT=$( cd $(dirname $(readlink -f $0) ); pwd )
# Load environment variables from (non-tracked) .env file
if [ -f "$PROJECT_ROOT/.env" ]
then
export $(cat $PROJECT_ROOT/.env | xargs)
fi
# Docker image name for this project
DOCKER_IMAGE_NAME="${DOCKER_IMAGE_NAME:-tobias/default}"
# Path to where in the docker container the project root will be mounted
export DOCKER_WORKSPACE_PATH="${DOCKER_WORKSPACE_PATH:-/workspace}"
# Docker user id and group id
export DOCKER_UID=`id -u`
export DOCKER_GID=`id -g`
# Path to where in the docker container the project root will be mounted
export DOCKER_WORKSPACE_PATH="${DOCKER_WORKSPACE_PATH:-/workspace}"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--gpu)
RUNTIME_ARGS="--gpus all"
shift # past argument
;;
--notebook)
JUPYTER_PORT="-p 8888:8888"
shift # past argument
;;
-v|--mount)
MOUNT="-v $2"
shift # past argument
shift # past value
;;
--tensorboard)
TENSORBOARD_PORT="-p 6006:6006"
shift # past argument
;;
-d|--detach)
DETACH="--detach"
shift # past argument
;;
*) # unknown option
echo "Unrecognized argument '$1'"
exit 1
;;
esac
done
CONTAINER_NAME="${CONTAINER_NAME:-${DOCKER_IMAGE_NAME//\//-}}"
HOME_VOLUME_NAME="${HOME_VOLUME_NAME:-$CONTAINER_NAME-home}"
# Stop any potentially running container with the same name
docker stop $CONTAINER_NAME 2> /dev/null || true
# Check if there is a running ssh agent, if so we want to forward it
if [[ ! -z "${SSH_AUTH_SOCK}" ]]; then
SSH_AGENT_FORWARD="-v $SSH_AUTH_SOCK:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent"
fi
# Optionally set a data dir mount if DATA_DIR env is set
if [[ ! -z "${DATA_DIR}" ]]; then
DATA_MOUNT="-v $DATA_DIR:$DOCKER_WORKSPACE_PATH/data"
fi
set -x
docker build --rm --build-arg DOCKER_WORKSPACE_PATH --build-arg DOCKER_UID --build-arg DOCKER_GID -t $DOCKER_IMAGE_NAME $PROJECT_ROOT
docker run --rm -it \
--name $CONTAINER_NAME \
-v $PROJECT_ROOT:$DOCKER_WORKSPACE_PATH \
-v $HOME_VOLUME_NAME:/home/docker-user \
--ipc host \
$DATA_MOUNT \
$SSH_AGENT_FORWARD \
$MOUNT \
$RUNTIME_ARGS \
$JUPYTER_PORT \
$TENSORBOARD_PORT \
$DETACH \
$DOCKER_IMAGE_NAME bash