forked from notadamking/RLTrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev-with-docker
executable file
·68 lines (56 loc) · 1.4 KB
/
dev-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
67
68
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
CWD=$(realpath "${SCRIPT_DIR}")
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-dev
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-dev"
docker build --tag $N -f "$CWD/docker/Dockerfile.cpu" "$CWD"
else
N="trader-rl-gpu-dev"
docker build --tag $N -f "$CWD/docker/Dockerfile.gpu" "$CWD"
fi
docker rm -fv rl_trader_dev || true
docker run \
--name 'rl_trader_dev' \
--user $(id -u):$(id -g) \
--entrypoint 'bash' \
--interactive \
--memory "${MEM_LIMIT}b" \
--cpus "${CPU_LIMIT}" \
--tty \
--volume "${CWD}":/code \
"$N"