forked from everlutionsk/symfony-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathops
executable file
·117 lines (107 loc) · 3.93 KB
/
ops
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
#!/usr/bin/env bash
# directory where this script is located
cd $(dirname "$0")
if [ ! -f ./infrastructure/env/symfony.env ]; then
cp ./infrastructure/env/symfony.env.dist ./infrastructure/env/symfony.env
echo -e "\e[01;31mThe ./infrastructure/env/symfony.env file has been created. Please change it according to README.md before continuing.\e[0m"
exit 1
fi
if [ ! -f ./infrastructure/env/docker.env ]; then
cp ./infrastructure/env/docker.env.dist ./infrastructure/env/docker.env
echo -e "\e[01;31mThe ./infrastructure/env/docker.env file has been created. Please change it according to README.md before continuing.\e[0m"
exit 1
fi
# source env files
source ./infrastructure/env/docker.env
set -a
source ./infrastructure/env/symfony.env
set +a
echo -e "\e[96m ENV=$DOCKER_INFRASTRUCTURE_ENV; DOMAIN=$NGINX_DOMAIN \e[0m"
if [ "$DOCKER_INFRASTRUCTURE_ENV" == "prod" ]; then
COMPOSE="docker-compose -p ${PWD##*/} -f infrastructure/docker-compose.yml"
else
COMPOSE="docker-compose -p ${PWD##*/} -f infrastructure/docker-compose.yml -f infrastructure/docker-compose-dev.yml"
fi
print_help () {
echo "Usage: $0 [command] [argument, ...]
init - initializes the project from scratch
up - brings containers up
stop - stops containers
down - stops and removes containers
restart - stops, rebuilds and starts specified containers eg. '$0 restart nginx fpm' will restart nginx and fpm
bin/console - runs Symfony's bin/console within cli container
composer - runs composer within cli container
npm - runs npm within node container
encore - runs encore within cli container (you need to install encore and set-up your project for proper use with Symfony's webpack first)
cs - checks your src/ and tests/ with php-cs-fixer and phpmd utilities
test - run tests with phpunit
permissions - fixes permissions in var/ folder
mysql - connects to the database within db container
mysqldump - dumps the database to ./infrastructure/volumes/sqldump
compose - wrapper for docker-compose"
exit 1
}
if [ $# -lt 1 ]; then
print_help
fi
case "$1" in
init)
sudo ./infrastructure/bin/init $NGINX_DOMAIN
;;
up)
$COMPOSE stop && $COMPOSE build && $COMPOSE up -d
;;
stop)
$COMPOSE stop
;;
down)
$COMPOSE down
;;
restart)
shift 1
$COMPOSE stop "$@" && $COMPOSE build "$@" && $COMPOSE up -d "$@"
;;
bin/console)
shift 1
$COMPOSE exec cli bin/console "$@"
;;
composer)
shift 1
$COMPOSE exec cli composer "$@"
;;
npm)
shift 1
$COMPOSE exec node npm "$@"
;;
encore)
shift 1
$COMPOSE exec node ./node_modules/.bin/encore "$@"
;;
cs)
$COMPOSE exec test bash -c "php-cs-fixer fix src/ --allow-risky yes --diff --verbose --using-cache=no --rules=@Symfony,declare_strict_types,-simplified_null_return,-phpdoc_align && \
php-cs-fixer fix tests/ --allow-risky yes --diff --verbose --using-cache=no --rules=@Symfony,declare_strict_types,-simplified_null_return,-phpdoc_align && \
phpmd src/ text cleancode, codesize, controversial, design, naming, unusedcode --suffixes php && \
phpmd tests/ text cleancode, codesize, controversial, design, naming, unusedcode --suffixes php"
;;
test)
$COMPOSE exec test phpunit --log-junit phpunit/junit.xml
;;
permissions)
./infrastructure/bin/fix-permissions
;;
mysql)
shift 1
$COMPOSE exec db mysql -u$DB_USER -p$DB_USER $DB_NAME
;;
mysqldump)
FILENAME=/sqldump/$(date +%d-%m-%Y_%H-%M)_$NGINX_DOMAIN.sql
$COMPOSE exec db mysqldump -u$DB_USER -p$DB_USER $DB_NAME > $FILENAME
echo "You can find your dump at ./infrastructure/volumes$FILENAME"
;;
compose)
shift 1
$COMPOSE "$@"
;;
*)
print_help
esac