Repository navigation
Expand file tree
/
Copy pathgoto_dev_docker.sh
More file actions
executable file
·129 lines (113 loc) · 3.25 KB
/
Copy pathgoto_dev_docker.sh
File metadata and controls
executable file
·129 lines (113 loc) · 3.25 KB
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
124
125
126
127
128
129
#! /bin/bash
set -u
TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
# shellcheck disable=SC1091,SC1090
source "${TOP_DIR}/docker/scripts/docker_base.sh"
DEFAULT_CONTAINER="maiwei_dev_${USER}"
readonly DEFAULT_CONTAINER
DEV_CONTAINER="${DEFAULT_CONTAINER}"
USER="${USER:-"charmve"}"
function usage() {
cat <<EOF
Usage: $0 [options] ...
OPTIONS:
-n, --name <NAME> Specify Docker container name as maiwei_dev_NAME
-h, --help Show this message and exit
EOF
}
function parse_cmdline_args() {
local name=
while [[ $# -gt 0 ]]; do
local opt="$1"
shift
case "${opt}" in
-n | --name)
name="$1"
shift
optarg_check_for_opt "${opt}" "${name}"
;;
-h | --help)
usage
exit 1
;;
esac
done
[[ -n "${name}" ]] && DEV_CONTAINER="maiwei_dev_${name}"
}
function _compare_timestamp_of_docker_image() {
local current="${1##*-}"
local latest="${2##*-}"
if [[ "${#current}" != "${#latest}" || "${current}" == "${latest}" ]]; then
echo 0
elif [[ "${current}" < "${latest}" ]]; then
echo -1
else
echo 1
fi
}
function check_image_updates() {
local latest
latest="$(dev_docker_image)"
local current
current="$(docker exec "${DEV_CONTAINER}" bash -c 'echo "${DOCKER_IMG}"')"
if [[ "${latest}" != "${current}" ]]; then
local result
result="$(_compare_timestamp_of_docker_image "${current}" "${latest}")"
if (("${result}" < 0)); then
warning "===================================================================="
warning "The tag of your currently running Dev Docker image is:"
warning " ${current##*:}"
warning "However, a newer image tagged ${latest##*:} is available."
warning "Please consider restarting Dev Docker at your earliest convenience."
warning "===================================================================="
elif (("${result}" > 0)); then
ok "It seems that you are running a newer Docker image than the latest one."
ok " Currently Running: ${current##*:}"
ok " Latest (see docker/TAG): ${latest##*:}"
else
warning "Unable to check if newer Docker image is available."
warning " Currently Running: ${current##*:}"
warning " Latest(see docker/TAG): ${latest##*:}"
fi
else
ok "==================================================="
ok "Your Dev Docker image is up-to-date."
ok "==================================================="
fi
}
function is_container_running() {
local container="$1"
local status
status="$(docker inspect -f '{{.State.Status}}' "${container}" 2>/dev/null)"
[[ "${status}" == "running" ]]
}
function main() {
parse_cmdline_args "$@"
local container="${DEV_CONTAINER}"
if ! is_container_running "${container}"; then
error "No running Docker container named ${container}"
exit 1
fi
check_image_updates
if [ ! -d ~/workspace/OccNet-Course ]; then
error "OccNet-Course should place at ~/workspace as default."
exit 0
fi
xhost +local:"${USER}" &>/dev/null
# nvidia-docker run \
docker run \
--gpus all \
-it \
-v "/media:/media" \
-v "${HOME}:/hosthome:rw" \
-v "$HOME/workspace/OccNet-Course:/maiwei" \
\
\
--hostname=maiwei-dev \
--workdir=/maiwei \
--shm-size 16g \
"$X86_64_DEV_REPO" /bin/bash # -e USER="${USER}" \
# -u "${USER}" \
xhost -local:"${USER}" 1>/dev/null 2>&1
}
main "$@"