-
-
Notifications
You must be signed in to change notification settings - Fork 539
/
run-with-docker
executable file
·66 lines (54 loc) · 1.39 KB
/
run-with-docker
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
#!/usr/bin/env bash
set -e
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [[ -z $1 ]]; then
echo "Should have 1 argument: cpu or gpu"
exit
fi
TYPE=$1
shift;
if [[ -n $2 ]]; then
docker build \
--tag 'trader-rl-postgres' \
--build-arg ID=$(id -u) \
--build-arg GI=$(id -g) \
-f "$CWD/docker/Dockerfile.backend" "$CWD"
mkdir -p "$CWD/data/postgres"
docker run \
--detach \
--publish 5432:5432 \
--tty \
--user "$(id -u):$(id -g)" \
--volume "$CWD/data/postgres":"/var/lib/postgresql/data/trader-data" \
trader-rl-postgres
shift
fi
if [[ $TYPE == 'gpu' ]]; then
GPU=1
else
GPU=0
fi
MEM=$(cat /proc/meminfo | grep 'MemTotal:' | awk '{ print $2 }')
CPUS=$(cat /proc/cpuinfo | grep -P 'processor.+[0-7]+' | wc -l)
MEM_LIMIT=$((MEM/4*3))
CPU_LIMIT=$((CPUS/4*3))
if [ $CPU_LIMIT == 0 ];then
CPU_LIMIT=1
fi
if [ $GPU == 0 ]; then
N="trader-rl-cpu"
docker build --tag $N -f "$CWD/docker/Dockerfile.cpu" "$CWD"
else
N="trader-rl-gpu"
docker build --tag $N -f "$CWD/docker/Dockerfile.gpu" "$CWD"
fi
echo "CWD: $CWD - Procs: $CPU_LIMIT Memory: ${MEM_LIMIT}bytes"
docker run \
--user $(id -u):$(id -g) \
--interactive \
--memory "${MEM_LIMIT}b" \
--cpus "${CPU_LIMIT}" \
--tty \
--volume "${CWD}":/code \
"$N" \
python /code/cli.py $@