-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·149 lines (125 loc) · 3.57 KB
/
run
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
#!/bin/bash -e
# TODO: review and refactoring needed
APP_NAME='phalcon-api'
LIST_OF_UNIX_FILES=(
"/usr/bin/cs"
"/usr/bin/edit"
"/usr/bin/cli"
"/usr/bin/unit"
"/etc/mc/mc.keymap"
)
check_db() {
if [ "$(docker exec -ti "$APP_NAME" bash -c "cli Common:CheckDbState" 2>&1)" == 1 ]; then
DB_STATUS=1
else
echo "Waiting for database..."
for i in {1..60}; do
sleep 1
if [ "$(docker exec -ti "$APP_NAME" bash -c "cli Common:CheckDbState" 2>&1)" == 1 ]; then
DB_STATUS=1
return
fi
done
echo "Couldn't connect to DB."
fi
}
run_unix_files_formatter() {
# TODO: find better way to submit host os to app inside container
docker exec -ti "$APP_NAME" bash -c "echo '$OSTYPE' >> /var/cache/host_os.txt"
if [ "$OSTYPE" == "msys" ]; then
for FILE in "${LIST_OF_UNIX_FILES[@]}"
do
docker exec -ti "$APP_NAME" bash -c "sed -i -e 's/\r$//' $FILE"
done
fi
}
if [ -z "$1" ]; then
echo "
Docker arguments:
${0} up - run app
${0} exec - exec to $APP_NAME
${0} ps - docker ps -a
${0} down - stop app
${0} build - rebuild project
${0} clear - clear data folder (may need to be run with sudo on Linux)
${0} fix - fix unix files when running docker from windows
CLI:
${0} cli {task} {...params}
Testing arguments:
${0} test - run full test (cs && unit)
${0} cs - run Code Standard tests
${0} cs fix - run code autofix
${0} cs {dir} - run Code Standard in exact directory
${0} unit - run paratest
${0} unit {test_name} - run exact test class or test method
${0} db - check if DB is online
"
exit
elif [ "$1" == "up" ]; then
docker-compose down
docker-compose up -d
docker exec -ti "$APP_NAME" bash -c "composer install"
run_unix_files_formatter
check_db
if [ "$DB_STATUS" == "1" ]; then
docker exec -ti "$APP_NAME" bash -c "cli migration:run"
else
echo "Please run migration manually."
fi
elif [ "$1" == "exec" ]; then
docker exec -ti "$APP_NAME" bash
elif [ "$1" == "ps" ]; then
docker ps -a
elif [ "$1" == "build" ]; then
docker-compose down
docker-compose up --build -d
docker exec -ti "$APP_NAME" bash -c "composer install"
run_unix_files_formatter
check_db
if [ "$DB_STATUS" == "1" ]; then
docker exec -ti "$APP_NAME" bash -c "cli migration:run"
else
echo "Please run migration manually."
fi
elif [ "$1" == "clear" ]; then
PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/data"
STRUCTURE=(
"mysql"
"log"
)
for FILE in $PATH/*; do
echo "Removing "$FILE;
/bin/rm -rf $FILE
done;
for DIR in "${STRUCTURE[@]}"; do
echo "Creating dir" $DIR;
/bin/mkdir $PATH/$DIR
/bin/chmod 0777 $PATH/$DIR
> "$PATH"/"$DIR"/.gitkeep
done
elif [ "$1" == "down" ]; then
docker-compose down
elif [ "$1" == "cs" ] && [ -z "$2" ]; then
docker exec -ti "$APP_NAME" bash -c "cs"
elif [ "$1" == "cs" ]; then
docker exec -ti "$APP_NAME" bash -c "cs $2"
elif [ "$1" == "unit" ] && [ -z "$2" ]; then
docker exec -ti "$APP_NAME" bash -c "unit"
elif [ "$1" == "unit" ]; then
docker exec -ti "$APP_NAME" bash -c "unit $2"
elif [ "$1" == "test" ]; then
docker exec -ti "$APP_NAME" bash -c "cs && unit"
elif [ "$1" == "cli" ]; then
docker exec -ti "$APP_NAME" bash -c "cli $2 $3 $4 $5 $6 $7 $8 $9"
elif [ "$1" == "fix" ]; then
run_unix_files_formatter
elif [ "$1" == "db" ]; then
check_db
if [ "$DB_STATUS" == "1" ]; then
echo "DB is online"
else
echo "Couldn't access DB :("
fi
else
echo "Argument \"$1\" not found"
fi