-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.sh
executable file
·77 lines (63 loc) · 1.94 KB
/
dev.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
#!/usr/bin/env bash
set -e
# set -x # Uncomment to debug
MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${MY_DIR}"
if [ -f "${MY_DIR}/.env" ]; then
eval "$(sed '/^$/d' "${MY_DIR}/.env"| sed -e 's/^/export /')"
fi
export PATH="${PATH}:${MY_DIR}/bin"
"${MY_DIR}/bin/setup-dependencies"
OSX="false"
if uname | grep -q Darwin; then
OSX="true"
fi
DOCKER_IP='127.0.0.1'
if [ "$OSX" == "true" ]; then
DOCKER_MACHINE_NAME="${DOCKER_MACHINE_NAME:-default}"
if [ "Running" != "$(docker-machine status "${DOCKER_MACHINE_NAME}")" ]; then
docker-machine start "${DOCKER_MACHINE_NAME}"
fi
DOCKER_IP="$(docker-machine ip "${DOCKER_MACHINE_NAME}")"
eval "$(docker-machine env)"
fi
if [ ! -f "${MY_DIR}/Gemfile.lock" ]; then
touch "${MY_DIR}/Gemfile.lock"
fi
if [ ! -f "${MY_DIR}/Gemfile.lock.md5" ]; then
touch "${MY_DIR}/Gemfile.lock.md5"
fi
if [ "${OSX}" == "true" ]; then
MD5_SUM_COMMAND="md5 -q Gemfile.lock"
else
MD5_SUM_COMMAND="md5sum Gemfile.lock | awk '{print \$1}'"
fi
TEMP_MD5=$(mktemp)
${MD5_SUM_COMMAND} > "${TEMP_MD5}"
if [ ! -z "$(diff -q "${MY_DIR}/Gemfile.lock.md5" "${TEMP_MD5}")" ]; then
cp "${TEMP_MD5}" "${MY_DIR}/Gemfile.lock.md5"
docker-compose build
fi
docker-compose up -d
WEB_PORT=$(docker-compose port web 3000 | sed -e 's|[\.0-9]*:||g')
DB_PORT=$(docker-compose port sql_db 5432 | sed -e 's|[\.0-9]*:||g')
echo "Use postgres://postgres:s3kr3t@${DOCKER_IP}:${DB_PORT}/identity_development to connect to your dev DB"
wait-for-it "${DOCKER_IP}:${WEB_PORT}" -s -t 30
WEB_URL="http://${DOCKER_IP}:${WEB_PORT}/"
if [ "$OSX" == "true" ]; then
if [ -z "${BROWSER+x}" ]; then
open "${WEB_URL}"
else
open -a "${BROWSER}" "${WEB_URL}"
fi
else
if [ ! -z "$(which xdg-open)" ]; then
xdg-open "${WEB_URL}"
elif [ ! -z "$(which x-www-browser)" ]; then
x-www-browser "${WEB_URL}"
else
echo "Navigate using the following url: ${WEB_URL}"
fi
fi
echo "Stop all services with Ctrl+C"
docker-compose up