-
Notifications
You must be signed in to change notification settings - Fork 314
/
docker_run.sh
executable file
·126 lines (94 loc) · 2.88 KB
/
docker_run.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
124
125
126
#!/bin/bash
#set -e
CONTAINER_NAME=google_map_react/main
DOCKER_HOST_NAME=gmr
SERVER_PATH=
export LC_NUMERIC=C
# get script dir
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
usage()
{
cat << EOF
examples
dev build
./docker_run.sh
production with offset
./docker_run.sh --production --offset 3030
dev with offset
./docker_run.sh --offset 3030
for developer build
./docker_run
for production build
./docker_run --production
also you can use
--offset $PORT
EOF
}
NODE_ENV_FOR_CONTAINER=
PORT_OFFSET=3080
while :
do
case $1 in
-h | --help | -\?)
usage
exit 0
;;
-p | --production)
# пример параметра без знчения
NODE_ENV_FOR_CONTAINER=production
shift
;;
-s | --serverpath)
SERVER_PATH=$2
shift 2
;;
-o | --offset)
PORT_OFFSET=$2
shift 2
;;
-*)
printf >&2 'WARN: Unknown option (ignored): %s\n' "$1"
shift
;;
*) # no more options. Stop while loop
break
;;
esac
done
EXT_IP="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | grep -v '172.1' | head -1)"
HOT_RELOAD_PORT=$(expr $PORT_OFFSET + 1)
echo "be sure you has this ip in your network $EXT_IP"
#on osx you need to install watchman 'brew install watchman'
SYSTEM=`uname`
[ "$SYSTEM" = "Darwin" ] && ./inotify_touch_helper.sh
CROSS_COMPAT_DIR=${DIR#$HOME}
docker run --name "$DOCKER_HOST_NAME" -d -t \
-e HOSTNAME="$DOCKER_HOST_NAME" \
-e SERVER_PATH="$SERVER_PATH" \
-e EXT_IP="$EXT_IP" \
-e HOT_RELOAD_PORT="$HOT_RELOAD_PORT" \
-e NODE_ENV="$NODE_ENV_FOR_CONTAINER" \
-p $PORT_OFFSET:80 \
-p $HOT_RELOAD_PORT:$HOT_RELOAD_PORT \
-v $HOME$CROSS_COMPAT_DIR:/home/ice$CROSS_COMPAT_DIR \
--add-host "$DOCKER_HOST_NAME":127.0.0.1 \
"$CONTAINER_NAME"
HOST_VAR=$(docker exec -it "$DOCKER_HOST_NAME" su - ice -c 'echo $HOSTNAME')
HOST_VAR=${HOST_VAR%?} #last symbol is bad clear it
while [[ "$HOST_VAR" != "$DOCKER_HOST_NAME" ]]; do
HOST_VAR=$(docker exec -it "$DOCKER_HOST_NAME" su - ice -c 'echo $HOSTNAME')
HOST_VAR=${HOST_VAR%?} #last symbol is bad clear it
echo "wait " -"$HOST_VAR"- -"$DOCKER_HOST_NAME"-
sleep 1
done
docker exec -it "$DOCKER_HOST_NAME" su - ice -c "cd /home/ice$CROSS_COMPAT_DIR && NODE_ENV= npm install"
sleep 1
#run tmux inside container
docker exec -it -d "$DOCKER_HOST_NAME" su - ice -c "script -q /dev/null -c 'cd /home/ice$CROSS_COMPAT_DIR && ./tmux_run'"
echo 'done'