-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdockerize
executable file
·695 lines (573 loc) · 20.6 KB
/
dockerize
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
#!/bin/bash
SCRIPTNAME="dockerize"
ETC_HOSTS=/etc/hosts
IP="0.0.0.0"
PORT=80
NETWORK_NAME="dockerizenet"
PROJECT_PATH=$(eval pwd)
DOCKERIZE_PATH=".dockerize"
MYSQL_ROOT_PASSWORD="root"
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
if [ -z $(eval command -v docker) ]; then
echo "Docker is not installed"
exit 1
fi
if [ ! -z $(eval command -v md5sum) ]; then
PROJECT_PATH_MD5=$(echo $PROJECT_PATH | md5sum)
elif [ ! -z $(eval command -v md5) ]; then
PROJECT_PATH_MD5=$(echo $PROJECT_PATH | md5)
else
echo "Md5 is not installed"
exit 1
fi
if [ ! -d ~/$DOCKERIZE_PATH ]; then
mkdir -p ~/$DOCKERIZE_PATH
fi
# Check if locally dockerized
if [ -e $PROJECT_PATH/.dockerized ]; then
mv $PROJECT_PATH/.dockerized ~/$DOCKERIZE_PATH/${PROJECT_PATH_MD5}
fi
IS_DOCKERIZED=$(eval [ ! -e ~/$DOCKERIZE_PATH/$PROJECT_PATH_MD5 ]; echo $?)
# Check if is dockerized
if [ ! $IS_DOCKERIZED -eq 0 ]; then
HOST_NAME=$(cat ~/$DOCKERIZE_PATH/$PROJECT_PATH_MD5 | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["HOST_NAME"]')
MVERSION=$(cat ~/$DOCKERIZE_PATH/$PROJECT_PATH_MD5 | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["MVERSION"]')
MAGE_TYPE=$(cat ~/$DOCKERIZE_PATH/$PROJECT_PATH_MD5 | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["MAGE_TYPE"]')
DBNAME=$(cat ~/$DOCKERIZE_PATH/$PROJECT_PATH_MD5 | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["DBNAME"]')
BASE_URL=http://$HOST_NAME/
CONTAINER_NAME="magento${MVERSION}"
fi
# Creates dockerized network if doesnt exists
if [ ! "$(docker network ls | grep $NETWORK_NAME)" ]; then
docker network create --subnet=172.77.0.0/16 $NETWORK_NAME
fi
# Get container IP Address
DB_IPADDRESS=$(docker inspect mysql | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[0]["NetworkSettings"]["Networks"]["'${NETWORK_NAME}'"]["IPAddress"]')
######################################################
#### Functions
######################################################
function install {
echo -e "${BLUE}\n-------------------------------------${NC}"
echo -e "${BLUE}Installing containers:${NC}"
echo -e "${BLUE}-------------------------------------${NC}"
docker pull fsspencer/magento
docker pull fsspencer/magento2
docker pull mysql
if [ ! "$(docker ps -a | grep mysql)" ]; then
# Create and start container
docker stop $(docker ps | grep "3306/tcp") &> /dev/null
docker run --net $NETWORK_NAME -d -ti -e MYSQL_ROOT_PASSWORD="$MYSQL_ROOT_PASSWORD" --ip 172.77.0.2 -p 3306:3306 --name mysql mysql
echo -e "${BLUE}Setting up mysql...${NC}"
sleep 5s
docker start mysql
echo -e "Your current MySQL root password is: $MYSQL_ROOT_PASSWORD\n"
fi
echo -e "${GREEN}Installation finished${NC}"
}
function setup {
if [ -z $(eval command -v git) ]; then
echo "${RED}GIT is not installed${NC}"
exit 1
fi
mkdir -p ~/.dockerize/bin
if [ -f ~/.dockerize/bin/dockerize ]; then
rm -rf ~/.dockerize/bin
rm /usr/local/bin/dockerize
fi
git clone https://github.com/fsspencer/dockerize-magento ~/.dockerize/bin &> /dev/null
ln -s ~/.dockerize/bin/dockerize /usr/local/bin/dockerize
install
echo -e "${GREEN}Dockerize installed properly. Now you can use it as 'dockerize' in your terminal${NC}"
}
function update {
echo -e "${BLUE}\n-------------------------------------${NC}"
echo -e "${BLUE}Checking for updates:${NC}"
echo -e "${BLUE}-------------------------------------${NC}"
docker pull fsspencer/magento
docker pull fsspencer/magento2
docker pull mysql
}
function stop {
# Stop and Remove existing container
docker stop $(docker ps -q -a --filter name=magento) &>/dev/null
docker rm $CONTAINER_NAME &>/dev/null
}
function start {
docker start mysql &>/dev/null
if [ -z $MVERSION ]; then
read -p "Magento Version [1 or 2]: " MVERSION
if [ -z "$MVERSION" ]; then
MVERSION="2"
echo "Selected Magento 2";
fi
fi
if [ -z $MAGE_TYPE ]; then
read -p "Magento Type [ce/ee]: " MAGE_TYPE
if [ -z "$MAGE_TYPE" ]; then
MAGE_TYPE="ce"
fi
if [ "$MAGE_TYPE" = "ee" ]; then
REPO_M2="--repository-url=https://repo.magento.com/ magento/project-enterprise-edition"
else
REPO_M2="magento/community-edition"
fi
fi
CONTAINER_NAME="magento${MVERSION}"
if [ -z "$HOST_NAME" ]; then
read -p "Base URL [dev.local]: " HOST_NAME
if [ -z "$HOST_NAME" ]; then
HOST_NAME="dev.local"
fi
fi
BASE_URL=http://${HOST_NAME}/
stop
if [ "$MVERSION" -eq "1" ]; then
REPO=fsspencer/magento
else
REPO=fsspencer/magento2
fi
# Create and start container
echo -e "${BLUE}\n-------------------------------------${NC}"
echo -e "${BLUE}Container creation response:${NC}"
echo -e "${BLUE}-------------------------------------${NC}"
docker run --net $NETWORK_NAME -d --name $CONTAINER_NAME -v $PROJECT_PATH:/var/www/html --ip 172.77.0.3 -p $PORT:80 $REPO
echo -e "\n"
# Get container IP Address
M2_IPADDRESS=$(docker inspect ${CONTAINER_NAME} | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[0]["NetworkSettings"]["IPAddress"]')
}
function deploymentScript {
if [ $IS_DOCKERIZED -eq 0 ]; then
read -p "Do you have a deployment script? [Y/n]: " HAS_DEPLOYMENT_SCRIPT
if [ "$HAS_DEPLOYMENT_SCRIPT" = "Y" ] || [ "$HAS_DEPLOYMENT_SCRIPT" = "y" ]; then
read -p "Deployment script location (relative path + filename): " DEPLOYMENT_SCRIPT
echo -e "${BLUE}\n-------------------------------------${NC}"
echo -e "${BLUE}Deployment script:${NC}"
echo -e "${BLUE}-------------------------------------${NC}"
docker exec --user www-data -ti $CONTAINER_NAME sh $DEPLOYMENT_SCRIPT
else
if [ -f ${PROJECT_PATH}/composer.json ]; then
docker exec --user www-data -ti $CONTAINER_NAME composer install
fi
fi
fi
}
function createConfigFile {
echo -e "${BLUE}\nDownloading config file...${NC}"
echo -e "\n"
read -p "Crypt [783eee839c0396cf398e07e218e89e0a]: " CRYPT
if [ -z $CRYPT ]; then
CRYPT="783eee839c0396cf398e07e218e89e0a"
fi
read -p "Table Prefix: " TABLE_PREFIX
if [ -z $TABLE_PREFIX ]; then
TABLE_PREFIX=""
fi
read -p "Backend Frontname [backend]: " BACKEND_FRONTNAME
if [ -z $BACKEND_FRONTNAME ]; then
BACKEND_FRONTNAME="backend"
fi
if [ "$MVERSION" -eq "2" ]; then
# If config.php exists, download an env.php template
if [ -f ${PROJECT_PATH}/app/etc/config.php ]; then
CONFIG_FILE=$PROJECT_PATH/app/etc/env.php
curl -k https://raw.githubusercontent.com/fsspencer/dockerize-magento/master/config/m2/${MAGE_TYPE}/env.php > $CONFIG_FILE
replaceConfigValues
else
# if not, install magento
if [ ! "$TABLE_PREFIX" == "" ]; then
docker exec --user www-data -ti $CONTAINER_NAME php bin/magento setup:install \
--db-host="$DB_IPADDRESS" \
--db-user="root" \
--db-password="$MYSQL_ROOT_PASSWORD" \
--db-name="$DBNAME" \
--db-prefix="$TABLE_PREFIX" \
--admin-user="admin" \
--admin-password="admin123" \
--admin-firstname="Admin" \
--admin-lastname="Web" \
--admin-email="admin@sample.com" \
--base-url="$BASE_URL" \
--use-rewrites=1 \
--backend-frontname="$BACKEND_FRONTNAME"
else
docker exec --user www-data -ti $CONTAINER_NAME php bin/magento setup:install \
--db-host="$DB_IPADDRESS" \
--db-user="root" \
--db-password="$MYSQL_ROOT_PASSWORD" \
--db-name="$DBNAME" \
--admin-user="admin" \
--admin-password="admin123" \
--admin-firstname="Admin" \
--admin-lastname="Web" \
--admin-email="admin@sample.com" \
--base-url="$BASE_URL" \
--use-rewrites=1 \
--backend-frontname="$BACKEND_FRONTNAME"
fi
fi
else
CONFIG_FILE=$PROJECT_PATH/app/etc/local.xml
curl -k https://raw.githubusercontent.com/fsspencer/dockerize-magento/master/config/m1/local.xml.sample > $CONFIG_FILE
replaceConfigValues
fi
rm -rf $PROJECT_PATH/var/cache/*
}
function replaceConfigValues {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/CRYPT/${CRYPT}/1" $CONFIG_FILE
sed -i '' "s/TBL_PREFIX/${TABLE_PREFIX}/1" $CONFIG_FILE
sed -i '' "s/DB_HOST/${DB_IPADDRESS}/1" $CONFIG_FILE
sed -i '' "s/DB_USER/root/1" $CONFIG_FILE
sed -i '' "s/DB_PASSWORD/${MYSQL_ROOT_PASSWORD}/1" $CONFIG_FILE
sed -i '' "s/DB_NAME/${DBNAME}/1" $CONFIG_FILE
sed -i '' "s/BACKEND_FRONTNAME/backend/1" $CONFIG_FILE
else
sed -i "s/CRYPT/${CRYPT}/1" $CONFIG_FILE
sed -i "s/TBL_PREFIX/${TABLE_PREFIX}/1" $CONFIG_FILE
sed -i "s/DB_HOST/${DB_IPADDRESS}/1" $CONFIG_FILE
sed -i "s/DB_USER/root/1" $CONFIG_FILE
sed -i "s/DB_PASSWORD/${MYSQL_ROOT_PASSWORD}/1" $CONFIG_FILE
sed -i "s/DB_NAME/${DBNAME}/1" $CONFIG_FILE
sed -i "s/BACKEND_FRONTNAME/backend/1" $CONFIG_FILE
fi
}
function createMysql {
# Stop and Remove existing container
echo -e "${BLUE}\n-------------------------------------${NC}"
echo -e "${BLUE}Mysql container response:${NC}"
echo -e "${BLUE}-------------------------------------${NC}"
docker start mysql
}
function setStoreConfigurations {
echo -e "${BLUE}\nSetting up Magento configurations${NC}"
if [ "$MVERSION" -eq "2" ]; then
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set web/unsecure/base_url $BASE_URL
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set web/secure/base_url $BASE_URL
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set web/cookie/cookie_domain $HOST_NAME
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set dev/js/merge_files 0
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set dev/js/enable_js_bundling 0
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set dev/js/minify_files 0
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set dev/css/merge_css_files 0
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set dev/css/minify_files 0
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun2.phar config:store:set dev/static/sign 0
docker exec --user www-data -ti $CONTAINER_NAME mysql -h $DB_IPADDRESS -uroot -proot $DBNAME -e "REPLACE INTO authorization_role (role_id, parent_id, tree_level, sort_order, role_type, user_id, user_type, role_name) VALUES (1, 0, 1, 1, 'G', 0, '2', 'Administrators');"
docker exec --user www-data -ti $CONTAINER_NAME mysql -h $DB_IPADDRESS -uroot -proot $DBNAME -e "REPLACE INTO authorization_rule (rule_id, role_id, resource_id, privileges, permission) VALUES (1, 1, 'Magento_Backend::all', NULL, 'allow');"
docker exec --user www-data -ti $CONTAINER_NAME php bin/magento setup:upgrade
docker exec --user www-data -ti $CONTAINER_NAME php bin/magento cache:clean
else
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun config:set web/unsecure/base_url $BASE_URL
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun config:set web/secure/base_url $BASE_URL
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun config:set web/cookie/cookie_domain $HOST_NAME
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun config:set dev/js/merge_files 0
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun config:set dev/css/merge_css_files 0
docker exec --user www-data -ti $CONTAINER_NAME n98-magerun cache:clean
fi
echo -e "${BLUE}\nFinished Setting up Magento configurations${NC}"
}
function createAdminUser {
if [ "$MVERSION" -eq "2" ]; then
read -p "Create Admin User? [Y/n]: " CREATE_ADMINUSER
if [ "$CREATE_ADMINUSER" = "Y" ] || [ "$CREATE_ADMINUSER" = "y" ]; then
read -p "Admin Password: " ADMIN_PASSWORD
docker exec --user www-data -ti $CONTAINER_NAME php bin/magento admin:user:create --admin-user="admin" --admin-firstname="Admin" --admin-lastname="Web" --admin-email="admin@sample.com" --admin-password="$ADMIN_PASSWORD"
fi
fi
}
function importDatabase {
echo -e "${BLUE}\nImporting sql file into database...${NC}"
# IF is a mac
if [[ "$OSTYPE" == "darwin"* ]]; then
LC_ALL=C sed -i '' 's/ROW_FORMAT=FIXED//g' ${SQLNAME}
else
sed -i 's/ROW_FORMAT=FIXED//g' ${SQLNAME}
fi
docker exec --user www-data -ti $CONTAINER_NAME mysql -h $DB_IPADDRESS -uroot -proot -e "set @@global.show_compatibility_56=ON;"
docker exec --user www-data -ti $CONTAINER_NAME mysql -h $DB_IPADDRESS -uroot -proot -e "USE ${DBNAME}; SOURCE ${SQLNAME};"
echo -e "${BLUE}\nDB Import process finished${NC}"
setStoreConfigurations
createAdminUser
}
function dbImport {
read -p "SQL Filename (Must be placed in project root)?: " SQLNAME
docker exec --user www-data -ti $CONTAINER_NAME mysql -h $DB_IPADDRESS -uroot -proot -e "set @@global.show_compatibility_56=ON;"
docker exec --user www-data -ti $CONTAINER_NAME n98 db:import --drop $SQLNAME
setStoreConfigurations
createAdminUser
}
function dbDump {
read -p "SQL Filename (Will be generated in project root)?: " SQLNAME
docker exec --user www-data -ti $CONTAINER_NAME n98 db:dump --compression="gzip" $SQLNAME
}
function dbCreate {
read -p "DB Name?: " DBNAME
if [ -z ${DBNAME} ]; then
echo "You need to specify a database name"
exit 1
fi
createMysql
docker exec --user www-data -ti $CONTAINER_NAME mysql -h $DB_IPADDRESS -uroot -proot -e "DROP DATABASE IF EXISTS ${DBNAME}; CREATE DATABASE ${DBNAME};"
echo -e "\n"
read -p "Import database? [Y/n]: " IMPORTDB
if [ "$IMPORTDB" = "Y" ] || [ "$IMPORTDB" = "y" ]; then
echo -e "${BLUE}\n-------------------------------------${NC}"
echo -e "${BLUE}Import Database:${NC}"
echo -e "${BLUE}-------------------------------------${NC}"
read -p "SQL Filename (Must be placed in project root)?: " SQLNAME
if [ ! -f ${PROJECT_PATH}/${SQLNAME} ]; then
echo "${PROJECT_PATH}/${SQLNAME} File not found!"
exit 1
fi
createConfigFile
importDatabase
else
if [ "$MVERSION" -eq "2" ]; then
read -p "Install Magento? [Y/n]: " INSTALLMAGE
if [ "$INSTALLMAGE" = "Y" ] || [ "$INSTALLMAGE" = "y" ]; then
installMagento
fi
fi
fi
}
function installMagento {
echo -e "\n"
if [ "$MVERSION" -eq "2" ]; then
read -p "Admin Username: " ADM_USER
read -p "Admin Password: " ADM_PWD
read -p "Admin First Name: " ADM_FNAME
read -p "Admin Last Name: " ADM_LNAME
read -p "Admin Email: " ADM_EMAIL
read -p "Backend Frontname [backend]: " BACKEND_FRONTNAME
if [ -z $BACKEND_FRONTNAME ]; then
BACKEND_FRONTNAME="backend"
fi
if [ ! -f ${PROJECT_PATH}/bin/magento ]; then
echo -e "\n"
rm -rf _src
read -p "Version Number [2.2.0]: " M2_VERSIONNUM
docker exec --user www-data -ti $CONTAINER_NAME composer create-project ${REPO_M2}:${M2_VERSIONNUM} _src
rsync -az --ignore-existing _src/ ./
rm -rf _src
fi
docker exec --user www-data -ti $CONTAINER_NAME php bin/magento setup:install \
--db-host="$DB_IPADDRESS" \
--db-user="root" \
--db-password="$MYSQL_ROOT_PASSWORD" \
--db-name="$DBNAME" \
--admin-user="$ADM_USER" \
--admin-password="$ADM_PWD" \
--admin-firstname="$ADM_FNAME" \
--admin-lastname="$ADM_LNAME" \
--admin-email="$ADM_EMAIL" \
--base-url="$BASE_URL" \
--backend-frontname="$BACKEND_FRONTNAME" \
--use-rewrites=1
fi
}
function installDB {
if [ $IS_DOCKERIZED -eq 0 ]; then
read -p "Create database? (Drop if exists) [Y/n]: " CREATEDB
if [ "$CREATEDB" = "Y" ] || [ "$CREATEDB" = "y" ]; then
dbCreate
else
CREATEDB=0
fi
addHost
fi
}
function addHost {
echo -e "${BLUE}\n-------------------------------------${NC}"
echo -e "${BLUE}Adding Host Entry:${NC}"
echo -e "${BLUE}-------------------------------------${NC}"
echo -e "${BLUE}This operation needs super privileges${NC}"
HOSTS_LINE="$IP $HOST_NAME"
if grep -Fxq "$HOST_NAME" $ETC_HOSTS
then
# host registry not found
# if is mac
if [[ "$OSTYPE" == "darwin"* ]]; then
sudo sed -i "" "/$HOST_NAME/d" $ETC_HOSTS
else
sudo sed -i "/$HOST_NAME/d" $ETC_HOSTS
fi
sudo -- sh -c -e "echo '$HOSTS_LINE' >> $ETC_HOSTS"
fi
}
function finish {
DOCKERIZED_DATA="{\"HOST_NAME\":\""$HOST_NAME"\",\"MVERSION\":\""$MVERSION"\",\"MAGE_TYPE\":\""$MAGE_TYPE"\",\"DBNAME\":\""$DBNAME"\"}"
echo $DOCKERIZED_DATA > ~/$DOCKERIZE_PATH/$PROJECT_PATH_MD5
}
function outputData {
echo -e "${GREEN}\n-------------------------------------${NC}"
echo -e "${GREEN}Magento IP Address: ${M2_IPADDRESS}${NC}"
if [ ! $CREATEDB = 0 ]; then
echo -e "${GREEN}MYSQL HOST: ${DB_IPADDRESS}${NC}"
echo -e "${GREEN}MYSQL USER: root${NC}"
echo -e "${GREEN}MYSQL PASS: ${MYSQL_ROOT_PASSWORD}${NC}"
fi
echo -e "${GREEN}-------------------------------------${NC}"
echo -e "${GREEN}\nFrontend: ${BASE_URL}${NC}"
echo -e "${GREEN}-------------------------------------${NC}"
}
function checkIsRunning {
if [ -z $CONTAINER_NAME ]; then
echo -e "${RED}Project is not initialized/started${NC}"
exit 1
fi
}
function usage {
echo -e "Usage:\n\n $SCRIPTNAME <action> <arguments...>"
echo -e ""
echo -e "Installation:"
echo -e " " "${GREEN}install${NC}" "\t" "Install Magento and MySQL"
echo -e " " "${GREEN}update${NC}" "\t" "Check for updates"
echo -e ""
echo -e "Project:"
echo -e " " "${GREEN}init${NC}" "\t\t" "Initialize new/existing Magento project"
echo -e " " "${GREEN}bash${NC}" "\t\t" "Connect to your docker container"
echo -e ""
echo -e "Tools:"
echo -e " " "${GREEN}php${NC}" "\t\t" "Executes php cli within your project root"
echo -e " " "${GREEN}composer${NC}" "\t" "Executes composer within your project root"
echo -e " " "${GREEN}grunt${NC}" "\t" "Executes grunt-cli Utility within your project root"
echo -e " " "${GREEN}gulp${NC}" "\t\t" "Executes gulp Utility within your project root"
echo -e " " "${GREEN}npm${NC}" "\t\t" "Executes npm within your project root"
echo -e " " "${GREEN}mysql${NC}" "\t" "Connect to the MySQL client server"
echo -e " " "${GREEN}n98${NC}" "\t\t" "Executes n98-magerun within your project root"
echo -e " " "${GREEN}magento${NC}" "\t" "Executes Magento 2 command line tool (e.g: dockerize magento setup:upgrade)"
echo ""
echo -e "Magento:"
echo -e " " "${GREEN}config:url${NC}" "\t" "Set automatically the Store URL among other things"
echo ""
echo "Database:"
echo -e " " "${GREEN}db:create${NC}" "\t" "Creates new database"
echo -e " " "${GREEN}db:import${NC}" "\t" "Imports a specified .sql file into the database"
echo -e " " "${GREEN}db:dump${NC}" "\t" "Generates a database file in the project root compressed using gzip"
echo ""
echo "Docker:"
echo -e " " "${GREEN}start${NC}" "\t" "Start the server and all of its components"
echo -e " " "${GREEN}stop${NC}" "\t\t" "Stop the server"
echo -e " " "${GREEN}remove${NC}" "\t" "Remove dockerize local config"
echo ""
echo "Dockerize:"
echo -e " " "${GREEN}setup${NC}" "\t" "Installs dockerize locally on your computer"
echo -e " " "${GREEN}self-update${NC}" "\t" "Updates dockerize locally on your computer"
echo ""
}
######################################################
#### User Interaction
######################################################
case "$1" in
install)
shift 1
install
;;
update)
shift 1
update
;;
init)
shift 1
start
deploymentScript
installDB
outputData
finish
;;
bash)
shift 1
checkIsRunning
docker exec --user www-data -ti $CONTAINER_NAME bash
;;
php)
shift 1
checkIsRunning
docker exec --user www-data -ti $CONTAINER_NAME php $*
;;
composer)
shift 1
checkIsRunning
docker exec --user www-data -ti $CONTAINER_NAME composer $*
;;
grunt)
shift 1
checkIsRunning
docker exec --user www-data -ti $CONTAINER_NAME grunt $*
;;
gulp)
shift 1
checkIsRunning
docker exec --user www-data -ti $CONTAINER_NAME gulp $*
;;
npm)
shift 1
checkIsRunning
docker exec --user www-data -ti $CONTAINER_NAME npm $*
;;
mysql)
shift 1
checkIsRunning
docker exec --user www-data -ti $CONTAINER_NAME mysql -h $DB_IPADDRESS -uroot -p$MYSQL_ROOT_PASSWORD $*
;;
n98)
shift 1
checkIsRunning
docker exec --user www-data -ti $CONTAINER_NAME n98 $*
;;
magento)
shift 1
checkIsRunning
if [ -f ${PROJECT_PATH}/bin/magento ]; then
docker exec --user www-data -ti $CONTAINER_NAME php bin/magento $*
else
echo -e "${RED}File bin/magento does not exists${NC}"
fi
;;
config:url)
shift 1
checkIsRunning
setStoreConfigurations
;;
db:create)
shift 1
checkIsRunning
dbCreate
finish
;;
db:import)
shift 1
checkIsRunning
dbImport
finish
;;
db:dump)
shift 1
checkIsRunning
dbDump
;;
start)
start
outputData
finish
;;
stop)
stop
finish
;;
remove)
rm ~/$DOCKERIZE_PATH/$PROJECT_PATH_MD5
;;
setup)
setup
;;
self-update)
echo -e "${BLUE}Fetching latest version...${NC}"
setup
;;
*)
usage
;;
esac
exit 0