-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathacli
executable file
·124 lines (103 loc) · 2.61 KB
/
acli
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
_help() {
cat <<HELP
Usage: acli <command> [options] <args>
Commands:
---------
import-db Restore database using backups from database/
export-db Create database backups and export them to database/
cli [--service=SERVICE_NAME] Run commoncli on the given service or all the services.
run <command> Execute an arbitrary command in the containers
drush [--publishers|--subscribers] Execute drush in the containers, only on publishers or subscribers or both
HELP
}
_remove_arg() {
args="${args[@]/$1}"
}
args="$@"
for flag in ${args[@]}; do
case $flag in
'--subscribers')
siteList=subscriber
_remove_arg $flag
;;
'--publishers')
siteList=publisher
_remove_arg $flag
;;
--service=*)
optService=${flag#'--service='}
_remove_arg $flag
;;
esac
done
declare -A sites
_init_service_mapping() {
local containers=(`docker-compose config --service | grep -v database`)
local uris=(`docker-compose config | grep -A 11 ${siteList:-''} | grep hostname | grep -v database | awk '{print $2}'`)
for ((i=0; i<${#containers[@]}; i++)); do
sites[${containers[$i]}]=${uris[$i]}
done
}
_init_service_mapping
_get_containers() {
`docker-compose images | sed -n '1,2!p' | cut -f 1 -d ' ' | grep -v database`
}
_drush() {
local service=$1
shift
local uri=${1#'--uri '}
docker-compose exec -T $service /bin/bash -c "echo -e '\n \033[0;33mExecuting drush command for: $uri\033[0;m\n'"
docker-compose exec -T $service ./vendor/bin/drush $@
}
_backup_db() {
local containers=$(_get_containers)
for cont in ${containers[@]}; do
./chf $cont ${1} ./database/${cont}.sql.gz &
done
}
_cli() {
local services=$optService
if [[ -z $services ]]; then
services=${!sites[@]}
fi
for s in $services; do
echo "docker-compose exec $s ./vendor/bin/commoncli --uri ${sites[$s]} '$@'"
done
}
uris=$(docker-compose config | grep -A 11 ${siteList:-''} | grep hostname | grep -v database | awk '{print $2}')
_run() {
local services=$optService
if [[ -z $services ]]; then
services=${!sites[@]}
fi
for s in $services; do
eval "docker-compose exec -T ${s} /bin/bash -c '${@}'" &
done
}
cmd=(${args[0]})
_remove_arg $cmd
case $cmd in
'drush')
for uri in $uris; do
_drush publisher1 "--uri $uri ${args[@]}" &
printf "\n\n"
done
;;
'cli')
_cli $args
;;
'import-db')
_backup_db import-db
;;
'export-db')
_backup_db export-db
;;
'run')
shift
_run $@
;;
*)
_help
;;
esac