-
Notifications
You must be signed in to change notification settings - Fork 22
/
docker-entrypoint.sh
executable file
·71 lines (68 loc) · 2.23 KB
/
docker-entrypoint.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
#!/bin/bash
set -eo pipefail
AWS_CLI='/usr/local/bin/aws'
# if command starts with an option, prepend node
if [ "${1:0:1}" = '-' ]; then
set -- node "$@"
fi
# skip setup if they want an option that stops node
wantHelp=
for arg; do
case "$arg" in
-'?'|--help|--print-defaults|-V|--version)
wantHelp=1
break
;;
esac
done
# generate configuration as per the deployment environment
#_generate_config() {
# #TODO: write configuration generate part here
# ENVIRONMENT=$1
# echo $ENVIRONMENT
#}
_setup_config() {
ENVIRONMENT=$1
./node_modules/grunt-cli/bin/grunt configsetup:${ENVIRONMENT}
}
_deploy_setup() {
ENVIRONMENT=$1
./node_modules/grunt-cli/bin/grunt deploy:${ENVIRONMENT}
}
if [ "$1" = 'node' -a -z "$wantHelp" ]; then
#if [ "$2" = 'server/server.js' ]; then
if [ -z "$MONGOLAB_URI" ]; then
echo >&2 'error: MONGOLAB_URI is not set. You need to specify MONGOLAB_URI'
exit 1
fi
if [ -z "$NODE_ENV" ]; then
echo >&2 'error: NODE_ENV is not set. You need to specify NODE_ENV'
exit 1
fi
if [ ! -z "$AWS_BUCKET" -a ! -z "$AWS_KEY" ]; then
echo >&2 'error: SEEDFILE parameters are set.'
if [ ! -z "$AWS_ACCESS_KEY_ID" -a ! -z "$AWS_SECRET_ACCESS_KEY" -a ! -z "$AWS_DEFAULT_REGION" ]; then
echo >&2 'Info: Fetching seed file ...'
$AWS_CLI s3api get-object --bucket $AWS_BUCKET --key $AWS_KEY server/boot/seed.json
if [ $? -ne 0 ]; then
echo >&2 'error: Failed to fetch seed file'
fi
else
echo >&2 'error: anyone from AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION is not set.'
fi
fi
_setup_config ${NODE_ENV}
_deploy_setup ${NODE_ENV}
#_generate_config ${NODE_ENV}
#fi
# Change uid and gid of node user so it matches ownership of current dir
# MAP_NODE_UID=$PWD
# uid=$(stat -c '%u' "$MAP_NODE_UID")
# gid=$(stat -c '%g' "$MAP_NODE_UID")
# usermod -u $uid node 2> /dev/null && {
# groupmod -g $gid node 2> /dev/null || usermod -a -G $gid node
# }
# chown -R node:node .
# exec gosu node "$@"
fi
exec "$@"