forked from laravel/laravel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nge
executable file
·103 lines (89 loc) · 2.54 KB
/
nge
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
#!/bin/bash
set -Eeo pipefail
set -o errexit # Used to exit upon error, avoiding cascading errors
IFS=$'\n\t'
# read .env file
# shellcheck disable=SC1090
source <(grep -v '^#' .env | sed -E 's|^(.+)=(.*)$|: ${\1=\2}; export \1|g')
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
install() {
echo "installing in 5 seconds"
sleep 5
printf "\n\n${YELLOW}[core]${NC} installing package...\n"
composer install
printf "\n\n${YELLOW}[core]${NC} run post installation script...\n"
composer run post-root-package-install
printf "\n\n${YELLOW}[core]${NC} put application under maintenance...\n"
if [[ -z "$APP_KEY" ]]; then
artisan key:generate
fi
artisan down
printf "\n\n${YELLOW}[core]${NC} running database migration and seeders...\n"
artisan migrate --seed
printf "\n\n${YELLOW}[core]${NC} upping application\n"
artisan up
printf "\n\n${BLUE}[app]${NC} building node packages...\n"
npm install
npm run production
}
composer() {
file_env 'USER_CONTAINER' 'dokar'
echo "run composer on user : ${USER_CONTAINER}"
docker-compose run --rm --user=${USER_CONTAINER} core composer $@
}
shell() {
file_env 'USER_CONTAINER' 'dokar'
echo "run shell on user : ${USER_CONTAINER}"
docker-compose run --rm --user=${USER_CONTAINER} core bash
}
artisan() {
file_env 'USER_CONTAINER' 'dokar'
echo "run artisan on user : ${USER_CONTAINER}"
docker-compose run --rm --user=${USER_CONTAINER} core php artisan $@
}
npm() {
file_env 'USER_CONTAINER' 'dokar'
echo "run npm on user : ${USER_CONTAINER}"
docker-compose run --rm --user=${USER_CONTAINER} core npm $@
}
up() {
echo "Nge up service $@..."
docker-compose up -d $@
}
down() {
echo "Nge down all service..."
docker-compose down
}
check() {
docker-compose ps
}
# Check if the function exists (bash specific)
if declare -f "$1" > /dev/null
then
# call arguments verbatim
"$@"
else
# Show a helpful error
echo "'$1' is not a known function name" >&2
exit 1
fi