forked from andreaskoch/dockerized-magento
-
Notifications
You must be signed in to change notification settings - Fork 2
/
magento
executable file
·236 lines (195 loc) · 5.07 KB
/
magento
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
#!/bin/sh
#
# A control-script for managing the docker-infrastructure components for Magento
# The first parameter is the action name
action=$1
# All other arguments are parameters
if [ "$#" -gt "1" ]; then
shift
parameters=$@
fi
# Paths
SCRIPTNAME=`basename $0`
SCRIPTPATH=$(readlink -f "$0" 2>/dev/null)
if [ "$?" != 0 ]; then
if [ ! -f "docker-compose.yml" ]; then
>&2 echo " The $SCRIPTNAME-script will only work (on Mac OS) if you execute it from the project directory itself."
exit 1
fi
SCRIPTPATH="$(pwd -P)/$SCRIPTNAME"
fi
PROJECTPATH=$(dirname "$SCRIPTPATH")
# Switch into the project directory
cd $PROJECTPATH
# Mandatory Tools
DOCKER=`which docker`
if [ -z "$DOCKER" ];
then
echo "'docker' was not found on your system." >&2
exit 1
fi
DOCKERCOMPOSE=`which docker-compose`
if [ -z "$DOCKERCOMPOSE" ];
then
echo "'docker-compose' was not found on your system." >&2
exit 1
fi
# Utils
XARGS=`which xargs`
GREP=`which grep`
SED=`which sed`
#########################################################################
# Get the full container name for the given container type (e.g. "php")
# Arguments:
# CONTAINER_TYPE
# Returns:
# The full name of the (first) container with the given type
#########################################################################
getContainerNameByType() {
# abort if no type is specified
local CONTAINER_TYPE="$1"
if [ -z "$CONTAINER_TYPE" ];
then
echo "No container type specified. Please specifiy a container type (e.g. php, installer, mysql, nginx, ...)." >&2
return 1
fi
# check if xargs is available
if [ -z "$XARGS" ];
then
echo "The tool 'xargs' was not found on your system." >&2
return 1
fi
# check if grep is available
if [ -z "$GREP" ];
then
echo "The tool 'grep' was not found on your system." >&2
return 1
fi
# check if sed is available
if [ -z "$SED" ];
then
echo "The tool 'sed' was not found on your system." >&2
return 1
fi
local containerName=$($DOCKER ps -q | $XARGS $DOCKER inspect --format '{{.Name}}' | $GREP "$CONTAINER_TYPE" | $SED 's:/::' | $GREP "$CONTAINER_TYPE_1")
echo $containerName
return 0
}
executeMagerun() {
local containerType="installer"
local containerName=$(getContainerNameByType "$containerType")
if [ -z "$containerName" ];
then
echo "Cannot determine the name of the container." >&2
return 1
fi
$DOCKER exec -ti $containerName magerun --skip-root-check --root-dir="/var/www/html/web" $@
return 0
}
executeComposer() {
local containerType="installer"
local containerName=$(getContainerNameByType $containerType)
if [ -z "$containerName" ];
then
echo "Cannot determine the name of the container." >&2
return 1
fi
$DOCKER exec $containerName composer --working-dir="/var/www/html" $@
return 0
}
enterContainer() {
local containerType="$1"
if [ -z "$containerType" ];
then
echo "No container type specified. Please specifiy a container type (e.g. php, installer, mysql, nginx, ...)." >&2
return 1
fi
local containerName=$(getContainerNameByType $containerType)
if [ -z "$containerName" ];
then
echo "Cannot determine the name of the container." >&2
return 1
fi
$DOCKER exec -ti $containerName bash
return 0
}
start() {
$DOCKERCOMPOSE up -d && $DOCKERCOMPOSE logs
}
stop() {
$DOCKERCOMPOSE stop
}
restart() {
$DOCKERCOMPOSE restart
executeMagerun cache:clean
}
status() {
$DOCKERCOMPOSE ps
}
stats() {
# check if sed is available
if [ -z "$SED" ];
then
echo "Stats requires 'sed'. The tool was not found on your system." >&2
return 1
fi
$DOCKER ps -q | $XARGS $DOCKER inspect --format '{{.Name}}' | $SED 's:/::' | $XARGS $DOCKER stats
}
magerun() {
executeMagerun $parameters
}
composer() {
executeComposer $parameters
}
enter() {
enterContainer $parameters
}
destroy() {
$DOCKERCOMPOSE stop
$DOCKERCOMPOSE rm --force
rm -rf $PROJECTPATH/web $PROJECTPATH/db $PROJECTPATH/vendor
}
case "$action" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
stats)
stats
;;
magerun)
magerun
;;
composer)
composer
;;
enter)
enter
;;
destroy)
destroy
;;
*)
echo "usage : $0 start|stop|restart|status|stats|magerun|composer|enter|destroy
start Starts the docker containers (and triggers the
installation if magento is not yet installed)
stop Stops all docker containers
restart Restarts all docker containers
status Prints the status of all docker containers
stats Displays live resource usage statistics of all containers
magerun Executes magerun in the magento root directory
composer Executes composer in the magento root directory
enter Enters the bash of a given container type (e.g. php, mysql)
destroy Stops all containers and removes all data
"
;;
esac
exit 0