-
Notifications
You must be signed in to change notification settings - Fork 16
/
angel-workspace-shell.sh
executable file
·123 lines (108 loc) · 3.21 KB
/
angel-workspace-shell.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
#
# Launch a bash shell with the ROS2 workspace mounted.
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# source common functionalities
. "${SCRIPT_DIR}/scripts/common.bash"
DEFAULT_SERVICE_NAME="workspace-shell-dev-gpu"
function usage()
{
echo "
Usage: $0 [-h|--help] [-s|--service=SERVICE_NAME] [--] ...
Start up a temporary container instance.
By default this will launch the ${DEFAULT_SERVICE_NAME} service.
Available services that may be specified may be found in the
./docker/docker-compose.yml configuration file.
Additional arguments, and explicitly those after a '--' are passed as command
arguments to the service run.
Options:
-h | --help Display this message.
-r | --run-setup Start the service with the workspace setup
script already sourced, allowing the ready
invocation of workspace products.
-s | --service=SERVICE_NAME Explicitly use the provide service.
"
}
# Option parsing
passthrough_args=()
while [[ $# -gt 0 ]]
do
case "$1" in
-h|--help)
usage
exit 0
;;
-r|--run-setup)
shift
export SETUP_WORKSPACE_INSTALL=true
;;
-s|--service)
# Use a specific service
shift
ARG_SERVICE_NAME="$1"
if [[ "$ARG_SERVICE_NAME" = "--" ]]
then
log "[ERROR] Service name cannot be '--'"
exit 1
fi
shift
;;
--)
# Escape the remainder of args as to be considered passthrough
shift
passthrough_args+=("${@}")
break
;;
*) # passthrough_args args
passthrough_args+=("$1")
shift
;;
esac
done
SERVICE_NAME="${ARG_SERVICE_NAME:-${DEFAULT_SERVICE_NAME}}"
# Create a permissions file for xauthority.
XAUTH_DIR="${SCRIPT_DIR}/.container_xauth"
mkdir -p "${XAUTH_DIR}"
# Exporting to be used in replacement in docker-compose file.
XAUTH_FILEPATH="$(mktemp "${XAUTH_DIR}/local-XXXXXX.xauth")"
export XAUTH_FILEPATH
log "[INFO] Creating local xauth file: $XAUTH_FILEPATH"
touch "$XAUTH_FILEPATH"
xauth nlist "$DISPLAY" | sed -e 's/^..../ffff/' | xauth -f "$XAUTH_FILEPATH" nmerge -
# Conditionally gather if jupyter is available in the current
# environment and parameterize mounting it's runtime dir
if [[ -n "$(which jupyter)" ]]
then
jupyter_rt_dir="$(jupyter --runtime-dir)"
export JUPYTER_MOUNT_PARAM=(-v "${jupyter_rt_dir}:/root/.local/share/jupyter/runtime")
fi
# Print some status stuff from the ENV file we are using
#
# Encapsulating the source in a nested bash instance to not pollute the
# current env with the contents of the file.
ENV_FILE="${SCRIPT_DIR}/docker/.env"
if [[ -n "${PTG_TAG+x}" ]]
then
>&2 echo "[INFO] Using container tag: ${PTG_TAG}"
else
bash -c "\
source \"${ENV_FILE}\";
>&2 echo \"[INFO] Using container tag: \${PTG_TAG}\"
"
fi
get_docker_compose_cmd DC_CMD
set +e
"${DC_CMD[@]}" \
--env-file "$ENV_FILE" \
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
run --rm \
"${JUPYTER_MOUNT_PARAM[@]}" \
"$SERVICE_NAME" "${passthrough_args[@]}"
DC_RUN_RET_CODE="$?"
set -e
log "[INFO] Container run exited with code: $DC_RUN_RET_CODE"
log "[INFO] Removing local xauth file."
rm "${XAUTH_FILEPATH}"
exit "$DC_RUN_RET_CODE"