-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev
executable file
·245 lines (215 loc) · 5.61 KB
/
dev
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/env bash
export USERID="$(id -u)"
ARTISAN="docker-compose exec api php artisan"
COMPOSER="docker-compose exec api composer"
REDIS="docker exec -it devops_redis"
ENV_FILE=".env"
ENV_FILE_EXAMPLE=".env.example"
ICON="🤖"
devops_dir=~/dev/work/devops/devops-docker-compose
project_dir=$(pwd)
show_commands () {
echo
echo "$ICON Comandos disponíveis:"
echo
echo "sh dev build - (Re)Builda as imagens dos containers"
echo "sh dev start-dev - Inicia os containers em modo Dev"
echo "sh dev status - Exibe o status dos containers"
echo "sh dev redis-clean - Apaga os dados do Redis"
echo "sh dev stop - Desliga os containers"
echo "sh dev logs NOME - Exibe e acompanha os logs do container"
echo "sh dev artisan COMANDO - Executa os comandos do Artisan"
echo "sh dev composer COMANDO - Executa os comandos do Composer"
echo "sh dev test - Executa os testes da aplicação (PHPUnit)"
echo "sh dev test-report - Executa os testes unitários da aplicação (PHPUnit) mostrando a listagem de testes executados."
echo
}
devops_exists (){
if [ ! -d "$devops_dir" ]; then
git clone [email protected]:jfoza/devops-docker-compose.git
fi
}
devops_start () {
devops_exists
# shellcheck disable=SC2164
cd $devops_dir;
if ! docker ps | grep -F -q "devops_rabbitmq"; then
sh dev start rabbitmq
fi
if ! docker ps | grep -F -q "devops_traefik"; then
sh dev start traefik
fi
if ! docker ps | grep -F -q "devops_mailhog"; then
sh dev start mailhog
fi
if ! docker ps | grep -F -q "devops_redis"; then
sh dev start redis
fi
if ! docker ps | grep -F -q "postgresql10"; then
sh dev start postgresql10
fi
# shellcheck disable=SC2164
cd $project_dir
}
compose_build () {
echo
echo "$ICON Buildando as imagens..."
echo
check_env_exists
docker-compose build
}
compose_up_dev () {
echo
echo "$ICON Iniciando os containers em modo Dev..."
echo
check_env_exists
docker-compose up -d api nginx scheduler supervisord-email
execute_composer_install
}
execute_composer_install () {
echo
echo "$ICON Instalando dependências PHP (vendor)..."
echo
$COMPOSER install
}
compose_status () {
echo
echo "$ICON Exibindo o status dos containers..."
echo
docker-compose ps
}
compose_down () {
echo
echo "$ICON Parando os containers..."
echo
docker-compose down
}
compose_logs () {
shift 1
if [ $# -gt 0 ]; then
echo
echo "$ICON Exibindo logs do container $@"
echo
docker-compose logs -f $@
else
echo
echo "$ICON Exibindo logs de todos os containers"
echo
docker-compose logs -f
fi
}
check_api_is_up () {
if ! docker-compose ps | grep -F -q "api"; then
echo
echo "$ICON Você precisa iniciar os containers da aplicação!"
echo "$ICON Comandos: sh dev start-dev"
echo
exit 1
fi
}
execute_artisan () {
check_api_is_up
echo
echo "$ICON Executando Artisan..."
echo
shift 1
$ARTISAN $@
}
execute_composer () {
check_api_is_up
echo
echo "$ICON Executando Composer..."
echo
shift 1
$COMPOSER $@
}
execute_unit_tests () {
check_api_is_up
echo
echo "$ICON Executando testes..."
echo
$ARTISAN test --filter 'Tests\\Unit'
}
execute_feature_tests () {
check_api_is_up
echo
echo "$ICON Executando testes..."
echo
$ARTISAN test --filter 'Tests\\Feature'
}
execute_feature_tests_membership () {
check_api_is_up
echo
echo "$ICON Executando testes no módulo Membresia..."
echo
$ARTISAN test --filter 'Tests\\Feature\\App\\Modules\\Membership'
}
execute_feature_tests_store () {
check_api_is_up
echo
echo "$ICON Executando testes no módulo Loja..."
echo
$ARTISAN test --filter 'Tests\\Feature\\App\\Modules\\Store'
}
execute_tests () {
check_api_is_up
echo
echo "$ICON Executando testes..."
echo
$ARTISAN test
docker-compose exec api ./vendor/bin/phpunit --colors --coverage-text=tests/coverage.txt --coverage-html=tests/coverage/
xdg-open tests/coverage/index.html
}
execute_tests_with_report () {
check_api_is_up
echo
echo "$ICON Executando testes..."
echo
shift 1
docker-compose exec api ./vendor/bin/phpunit --filter 'Tests\\Unit' --testdox $@
}
start_dev () {
compose_down
devops_start
compose_up_dev
$ARTISAN custom:clear-policy-cache
$ARTISAN custom:create-queue-rabbitmq
echo
echo "$ICON Iniciando aplicação em modo Dev"
echo
docker-compose logs -f api
}
check_env_exists () {
if [ ! -f "$ENV_FILE" ]; then
echo "$ICON Criando arquivo de configuração $ENV_FILE..."
cp $ENV_FILE_EXAMPLE $ENV_FILE
echo
fi
}
redis_clean () {
echo
echo "$ICON Limpando dados do Redis"
echo
$REDIS redis-cli -a redis flushall
}
if [ $# -gt 0 ]; then
case "$1" in
"build") compose_build ;;
"start-dev") start_dev ;;
"status") compose_status ;;
"stop") compose_down ;;
"redis-clean") redis_clean ;;
"logs") compose_logs $@ ;;
"artisan") execute_artisan $@ ;;
"composer") execute_composer $@ ;;
"test") execute_tests $@ ;;
"test-unit") execute_unit_tests $@ ;;
"test-feature") execute_feature_tests $@ ;;
"test-feature-membership") execute_feature_tests_membership $@ ;;
"test-feature-store") execute_feature_tests_store $@ ;;
"test-report") execute_tests_with_report $@ ;;
*) show_commands;;
esac
else
show_commands
fi