-
Notifications
You must be signed in to change notification settings - Fork 17
/
web
executable file
·83 lines (74 loc) · 2.45 KB
/
web
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
#!/bin/bash
if [ -z "$COOG_CODE_DIR" ] || [ ! -d "$COOG_CODE_DIR" ] || [ -z "$COOG_DATA_DIR" ]
then
{
echo "Please make sure that these two env vars are set:"
echo " COOG_CODE_DIR: your coog-admin install folder"
echo " COOG_DATA_DIR: the folder where to keep your custom config"
} >&2 && exit 1
fi
_build() {
( cd "$COOG_CODE_DIR/images/web" && ./build "$@" )
}
_args() {
local args
args="$args -e COOG_API_REDIS_URL=//$NETWORK_NAME-redis:6379 -e COOG_API_REDIS_DB=$WEB_REDIS_DB"
args="$args -e COOG_API_COOG_URL=http://$NETWORK_NAME-nginx:80 -e COOG_API_COOG_DB=$COOG_DB_NAME"
args="$args -e COOG_API_API_URL=$COOG_API_API_URL -e COOG_API_API_PATH=/web/api
-e COOG_API_APP_PATH=/web"
[ ! -z "$COOG_API_API_PROTOCOL" ] && args="$args -e COOG_API_API_PROTOCOL=$COOG_API_API_PROTOCOL"
[ ! -z "$COOG_API_CORS" ] && args="$args -e COOG_API_CORS=$COOG_API_CORS"
[ ! -z "$COOG_API_GOOGLE_SECRET" ] && [ ! -z "$COOG_API_GOOGLE_KEY" ] && \
args="$args -e COOG_API_GOOGLE_SECRET=$COOG_API_GOOGLE_SECRET -e
COOG_API_GOOGLE_KEY=$COOG_API_GOOGLE_KEY"
[ ! -z "$COOG_API_APP_URL" ] && args="$args -e COOG_API_APP_URL=$COOG_API_APP_URL" || \
args="$args -e COOG_API_APP_URL=http://$COOG_API_API_URL/web/"
[ ! -z "$DEBUG" ] && args="$args -e DEBUG=$DEBUG"
echo "$args"
}
_docker() {
docker "$@" "$NETWORK_NAME-web"
}
_image() {
[ -z "$1" ] && echo missing command && return 1
local cmd; cmd="$1"
local args
if [ "$cmd" = server ]
then
cmd=web
args=$DOCKER_DAEMON_OPTS
else
args=$DOCKER_INTERACTIVE_OPTS
fi
docker run \
--name "$NETWORK_NAME-$cmd" \
--network "$NETWORK_NAME" \
$args \
$(_args) "$WEB_IMAGE" "$@"
}
########
# main #
########
usage() {
echo
echo Admin commands
echo
echo " build -> build web image: <tag> <repo:branch>+"
echo
echo Docker commands
echo
echo " <action> -> calls docker action on web container"
docker run $DOCKER_PIPED_OPTS "$WEB_IMAGE"
return 0
}
main() {
source "$COOG_CODE_DIR/config"
[ -z "$1" ] && usage && return 0
local cmd; cmd="$1"; shift
[ "$cmd" = "build" ] && { _build "$@"; return $?; }
[ "$cmd" = "server" ] && { _image "$cmd" "$@"; return $?; }
[ "$cmd" = "version" ] && { _image "$cmd" "$@"; return $?; }
[ "$cmd" = "env" ] && { _image "$cmd" "$@"; return $?; }
_docker "$cmd" "$@"
}
main "$@"