/
stellar
executable file
·95 lines (87 loc) · 2.87 KB
/
stellar
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
#!/usr/bin/env bash
export STELLAR_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
export CURRENT_UID=$(id -u):$(id -g)
export COMPOSE_IGNORE_ORPHANS=true
find_up () {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
done
echo "$path"
}
container_list () {
echo "CONTAINERS:"
echo "web ${PREFIX}_web"
echo "artisan ${PREFIX}_artisan"
echo "phpunit ${PREFIX}_phpunit"
echo "php ${PREFIX}_php"
echo "mailhog stellar_mailhog"
echo "pgsql stellar_pgsql"
echo "mysql stellar_mysql"
echo "redis stellar_redis"
echo "NETWORK: stellar_network"
}
init() {
if [[ -f ".stellar" ]]; then
export BACKEND_PATH="$( pwd -P)"
else
export BACKEND_PATH="$( find_up .stellar )"
fi
set -a
source "${BACKEND_PATH}/.stellar"
set +a
if [[ $# -gt 0 ]]; then
start_command "${@}"
else
echo "init Init Stellar."
echo "stop Stop Stellar."
echo "start Start Stellar."
echo "refresh Refresh Stellar."
echo "artisan Pass through command to php artisan."
echo "test Run phpunit tests."
fi
}
start_command() {
if [[ ${1} == "init" ]]; then
run_command docker-compose -f docker-compose.base.yml up -d
run_command docker-compose -p "${PREFIX}" up -d web
container_list
elif [[ ${1} == "stop" ]]; then
run_command docker-compose -f docker-compose.base.yml down
run_command docker-compose down
elif [[ "${1}" == "refresh" ]]; then
run_command docker-compose down
run_command docker-compose build --no-cache php phpunit artisan
run_command docker-compose -p "${PREFIX}" up -d --force-recreate web
container_list
elif [[ "${1}" == "start" ]]; then
run_command docker-compose -p "${PREFIX}" up -d web
container_list
elif [[ "${1}" == "setup" ]]; then
docker exec -e DB_NAME="${DB_NAME}" -e DB_USERNAME="${DB_USERNAME}" -e DB_PASSWORD="${DB_PASSWORD}" stellar_mysql ./scripts/setup.sh
docker exec -e DB_NAME="${DB_NAME}" -e DB_USERNAME="${DB_USERNAME}" -e DB_PASSWORD="${DB_PASSWORD}" stellar_pgsql ./scripts/setup.sh
elif [[ "${1}" == "artisan" ]]; then
shift 1
dcr artisan "${@}"
elif [[ "${1}" == "test" ]]; then
shift 1
dcr phpunit "${@}"
elif [[ "${1}" == "list" ]]; then
container_list
elif [[ "${1}" == "destroyall" ]]; then
docker stop $(docker ps -a -q)
docker system prune --force
elif [[ $# -gt 0 ]]; then
run_command docker-compose "${@}"
fi
exit 0
}
dcr() {
run_command docker-compose run --rm "${@}"
}
run_command() {
if [[ $# -gt 0 ]]; then
(cd ${STELLAR_PATH} && $*)
fi
}
init "${@}"