Skip to content

Commit 73975e5

Browse files
authored
Merge pull request #50 from glo47154/feature/single-dockerfile
- Improved and fixed help for m2d command; - Fixed issue with a configuration file path when it is not yet created; - Exclude .env.back file from the repository; - Added project suffix; - Fixed mailcatcher configuration; - Project clean-up;
2 parents 854520a + 952206b commit 73975e5

File tree

9 files changed

+126
-41
lines changed

9 files changed

+126
-41
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Set the base path were you want to keep Magento source files
66
# e.g. /var/www/html or ~/src/html
77
M2D_SOURCE_DIRECTORY='/var/www/html'
8+
# Set the project suffix. It will be used to distinguish different instances of Magento2Docker
9+
# If you only work with one instance, you can skip it.
10+
M2D_PROJECT_SUFFIX=''
811
# Define a synchronisation type used to sync source directory between host and container
912
# - 'mutagen' container will use named volume and Mutagen [https://mutagen.io/] will be used to sync files (default)
1013
# - 'sshfs' container will use named volume and SSHFS will be used to mount it to the host
@@ -60,6 +63,8 @@ M2D_WEB_SERVER_VENDOR='apache'
6063
# Set which PHP version you want to use:
6164
# - PHP versions: 7.3, 7.4, 8.1, 8.2
6265
M2D_WEB_SERVER_PHP_VERSION='8.1'
66+
# Sets amount of memory available for PHP (php.ini: memory_limit)
67+
M2D_WEB_SERVER_PHP_MEMORY_LIMIT='2G'
6368
# Set the port number used by SSH:
6469
M2D_PORT_FOR_WEB_SERVER_SSH='2222'
6570
# Set the port number used by HTTP:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.env
2+
.env.back

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Key features of the project:
1515
- Single docker-compose.yaml file approach with .env file to configure everything.
1616
## Contents
1717
- [Pre-requirements](#pre-requirements)
18+
- [How to install it on Mac](#how-to-install-it-on-mac)
19+
- [Directory requirements](#directory-requirements)
1820
- [Installation](#installation)
1921
- [Supported services and tools](#supported-services-and-tools)
2022
- [Usage](#usage)
@@ -32,7 +34,24 @@ Key features of the project:
3234
## Pre-requirements
3335
- [Install Docker](https://docs.docker.com/engine/installation/mac/)
3436
- [Install Mutagen](https://mutagen.io/documentation/introduction/installation/)
35-
- [Install bash completion (optional)](https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion)
37+
- Bash > 4.0
38+
- Realpath
39+
40+
### How to install it on Mac
41+
```bash
42+
# Mutagen:
43+
brew install mutagen-io/mutagen/mutagen
44+
# Bash:
45+
brew install bash
46+
# Realpath:
47+
brew install coreutils
48+
```
49+
50+
### Directory requirements
51+
1. Magento2Docker as a tool can be located in any directory, e.g. ~/tools/m2d
52+
2. Web container will use /var/www/html as its root folder for web content.
53+
3. The M2D_SOURCE_DIRECTORY must point to a local path where you want to sync /var/www/html from the web container.
54+
4. The M2D_SOURCE_DIRECTORY must not point to symlink or it will trigger errors when Mutagen is responsible for sync process.
3655

3756
## Installation
3857
You can download archive of this project on [Release Page](https://github.com/yvoronoy/magento2docker/releases).

bin/m2d

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ function _m2d_display_help_main ()
66
echo "
77
Usage: ./bin/m2d COMMAND [OPTIONS]
88
9+
Examples:
10+
- initial setup:
11+
./bin/m2d setup init
12+
13+
- build and start containers:
14+
./bin/m2d up --build
15+
16+
- stop and remove containers and networks:
17+
./bin/m2d down
18+
19+
920
Options:
1021
-h, --help Disply help for command
1122
@@ -14,6 +25,7 @@ Commands:
1425
disable Disable selected service or tool
1526
down Stop and remove containers and networks
1627
enable Enable selected service or tool
28+
go Enters a running container
1729
logs View logs from containers
1830
set Sets configuration value
1931
setup Configure project
@@ -29,11 +41,20 @@ function _m2d_display_help_set ()
2941
echo "
3042
Usage: ./bin/m2d set [OPTIONS] PARAMETER VALUE
3143
44+
Sets configuration value.
45+
46+
Examples:
47+
./bin/m2d set M2D_XDEBUG_IDE_KEY VSCODE
48+
./bin/m2d set es 8.4
49+
3250
Options:
3351
-h, --help Disply help for command
3452
3553
Parameters:
54+
es Alias for setting Elasticsearch as the search engine. It will set M2D_SEARCH_ENGINE_VENDOR to 'elasticsearch',
55+
and M2D_SEARCH_ENGINE_VERSION to '7' if expected version is not provided as a value
3656
php Alias for parameter M2D_WEB_SERVER_PHP_VERSION
57+
suffix Alias for parameter M2D_PROJECT_SUFFIX
3758
[M2D_*] Parameter name. List of possible parameters and their values is in .env.example
3859
"
3960
}
@@ -43,6 +64,11 @@ function _m2d_display_help_show ()
4364
echo "
4465
Usage: ./bin/m2d show [OPTIONS] PARAMETER
4566
67+
Shows configuration value.
68+
69+
Example:
70+
./bin/m2d show M2D_SOURCE_DIRECTORY
71+
4672
Options:
4773
-h, --help Disply help for command
4874
@@ -56,6 +82,11 @@ function _m2d_display_help_setup ()
5682
echo "
5783
Usage: ./bin/m2d setup [OPTIONS] [COMMAND] [PROJECT_ID]
5884
85+
Configure project.
86+
87+
Example:
88+
./bin/m2d setup init
89+
5990
Options:
6091
-h, --help Disply help for command
6192
@@ -68,27 +99,35 @@ Commands:
6899

69100
function _m2d_display_help_enable_disable ()
70101
{
102+
local command=$1
103+
local Command=${1^}
104+
71105
echo "
72-
Usage: ./bin/m2d $1 [OPTIONS] COMMAND
106+
Usage: ./bin/m2d $command [OPTIONS] COMMAND
107+
108+
$Command selected service or tool.
109+
110+
Example:
111+
./bin/m2d $command mailcatcher
73112
74113
Options:
75114
-h, --help Disply help for command
76115
77116
Commands:
78-
blackfire ${1^} blackfire container
79-
db-cache ${1^} db-cache container
117+
blackfire $Command blackfire container
118+
db-cache $Command db-cache container
80119
elastic Alias for 'search-engine ' command
81120
m Alias for 'mailcatcher' command
82-
mailcatcher ${1^} mailcatcher container
83-
message-broker ${1^} message broker container
121+
mailcatcher $Command mailcatcher container
122+
message-broker $Command message broker container
84123
rabbit Alias for 'message-broker' command
85124
redis Alias for 'db-cache' command
86-
search-engine ${1^} search engine container
87-
selenium ${1^} selenium container
125+
search-engine $Command search engine container
126+
selenium $Command selenium container
88127
varnish Alias for 'web-cache' command
89-
web-cache ${1^} web-cache container
128+
web-cache $Command web-cache container
90129
91-
After container is $1 it must be rebuild with: \`./bin/m2d build\` or \`./bin/m2d up --build\`
130+
After container is $command it must be rebuild with: \`./bin/m2d build\` or \`./bin/m2d up --build\`
92131
"
93132
}
94133

@@ -97,6 +136,8 @@ function _m2d_display_help_up ()
97136
echo "
98137
Usage: ./bin/m2d up [OPTIONS]
99138
139+
Create and start containers.
140+
100141
Options:
101142
-h, --help Disply help for command
102143
-b, --build Build images before starting containers.
@@ -118,6 +159,11 @@ function _m2d_display_help_go ()
118159
echo "
119160
Usage: ./bin/m2d go [OPTIONS] CONTAINER_NAME
120161
162+
Enters a running container.
163+
164+
Example:
165+
./bin/m2d go web
166+
121167
Options:
122168
-h, --help Disply help for command
123169
@@ -134,6 +180,8 @@ function _m2d_display_help_logs ()
134180
echo "
135181
Usage: ./bin/m2d logs [OPTIONS] CONTAINER_NAME
136182
183+
View logs from containers.
184+
137185
Options:
138186
-h, --help Disply help for command
139187
@@ -147,6 +195,8 @@ function _m2d_display_help_sync ()
147195
echo "
148196
Usage: ./bin/m2d sync [OPTIONS] ACTION
149197
198+
Manage data sync from between host an containers.
199+
150200
Options:
151201
-h, --help Disply help for command
152202
@@ -292,14 +342,14 @@ function _m2d_sync ()
292342
local sync_type=$(_m2d_env_get_parameter "$env_file" M2D_SOURCE_DIRECTORY_SYNC_TYPE)
293343
local sync_dir=$(_m2d_env_get_parameter "$env_file" M2D_SOURCE_DIRECTORY)
294344
local server_vendor=$(_m2d_env_get_parameter "$env_file" M2D_WEB_SERVER_VENDOR)
295-
local ssh_port=$(_m2d_env_get_parameter "$env_file" M2D_PORT_FOR_WEB_SERVER_SSH)
296345
local project_path="$3"
297346

298347
case $sync_type in
299348
'bind')
300349
echo "Nothing to do for '$action' in '$sync_type' sync type"
301350
;;
302351
'sshfs')
352+
local ssh_port=$(_m2d_env_get_parameter "$env_file" M2D_PORT_FOR_WEB_SERVER_SSH)
303353
case $action in
304354
'start')
305355
local identity_file="$project_path/services/web-servers/$server_vendor/etc/ssh/magento2docker"
@@ -321,12 +371,14 @@ function _m2d_sync ()
321371
esac
322372
;;
323373
'mutagen')
374+
local sync_name="m2d-sync$(_m2d_env_get_parameter $env_file M2D_PROJECT_SUFFIX)"
375+
local sync_web="m2d-web$(_m2d_env_get_parameter $env_file M2D_PROJECT_SUFFIX)"
324376
case $action in
325377
'start')
326-
if [[ -n $(mutagen sync list | grep m2d-sync) ]]; then
327-
mutagen sync resume m2d-sync
378+
if [[ -n $(mutagen sync list | grep $sync_name) ]]; then
379+
mutagen sync resume $sync_name
328380
else
329-
mutagen sync create --name=magento2web \
381+
mutagen sync create --name=$sync_name \
330382
--default-group-beta=magento \
331383
--default-owner-beta=magento \
332384
--sync-mode=two-way-resolved \
@@ -344,17 +396,17 @@ function _m2d_sync ()
344396
--ignore=/**/.DS_Store \
345397
--symlink-mode=posix-raw \
346398
"$sync_dir" \
347-
docker://magento@m2d-web/var/www/html/
399+
"docker://magento@$sync_web/var/www/html/"
348400
fi
349401
;;
350402
'pause')
351-
mutagen sync pause m2d-sync
403+
mutagen sync pause $sync_name
352404
;;
353405
'stop')
354-
mutagen sync terminate m2d-sync
406+
mutagen sync terminate $sync_name
355407
;;
356408
'status')
357-
mutagen sync monitor m2d-sync
409+
mutagen sync monitor $sync_name
358410
;;
359411
'restart')
360412
_m2d_sync stop "$env_file"
@@ -374,20 +426,23 @@ function _m2d_sync ()
374426

375427
M2D_SCRIPT_DIRECTORY=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
376428
M2D_PROJECT_PATH="$(realpath $M2D_SCRIPT_DIRECTORY/../)"
377-
M2D_ENV_FILE="$(realpath $M2D_PROJECT_PATH/.env)"
429+
M2D_ENV_FILE="$M2D_PROJECT_PATH/.env"
378430

379431
case $1 in
380432
'set')
381433
case $2 in
382434
'-h'|'--help')
383435
_m2d_display_help_set
384436
;;
437+
'suffix')
438+
_m2d_env_set_parameter "$M2D_ENV_FILE" M2D_PROJECT_SUFFIX "$3"
439+
;;
385440
'php')
386441
_m2d_env_set_parameter "$M2D_ENV_FILE" "M2D_WEB_SERVER_PHP_VERSION" "$3"
387442
;;
388443
'es')
389444
_m2d_env_set_parameter "$M2D_ENV_FILE" "M2D_SEARCH_ENGINE_VENDOR" elasticsearch
390-
_m2d_env_set_parameter "$M2D_ENV_FILE" "M2D_SEARCH_ENGINE_VERSION" "$3"
445+
_m2d_env_set_parameter "$M2D_ENV_FILE" "M2D_SEARCH_ENGINE_VERSION" "${3:-7}"
391446
;;
392447
*)
393448
_m2d_env_set_parameter "$M2D_ENV_FILE" "$2" "$3"

docker-compose.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ version: '3'
22

33
services:
44
web:
5-
hostname: magento2.test
6-
container_name: m2d-web
5+
container_name: "m2d-web${M2D_PROJECT_SUFFIX:-}"
76
restart: unless-stopped
87
build:
98
context: .
@@ -13,11 +12,12 @@ services:
1312
- M2D_WEB_SERVER_PHP_VERSION=${M2D_WEB_SERVER_PHP_VERSION:-8.1}
1413
- M2D_ENABLE_BLACKFIRE=${M2D_ENABLE_BLACKFIRE:-no}
1514
- M2D_XDEBUG_IDE_KEY=${M2D_XDEBUG_IDE_KEY:-PHPSTORM}
15+
- M2D_HOSTNAME_FOR_MAILCATCHER="m2d-mailcatcher${M2D_PROJECT_SUFFIX:-}"
1616
environment:
1717
- BLACKFIRE_CLIENT_ID
1818
- BLACKFIRE_CLIENT_TOKEN
1919
- MAGENTO_CLOUD_CLI_TOKEN
20-
- COMPOSER_AUTH
20+
# - COMPOSER_AUTH
2121
ports:
2222
- "${M2D_PORT_FOR_WEB_SERVER_HTTP:-80}:80"
2323
- "${M2D_PORT_FOR_WEB_SERVER_HTTPS:-443}:443"
@@ -38,7 +38,7 @@ services:
3838
args:
3939
- M2D_DB_ENGINE_VENDOR=${M2D_DB_ENGINE_VENDOR:-mariadb}
4040
- M2D_DB_ENGINE_VERSION=${M2D_DB_ENGINE_VERSION:-10}
41-
container_name: m2d-db
41+
container_name: "m2d-db${M2D_PROJECT_SUFFIX:-}"
4242
restart: unless-stopped
4343
environment:
4444
MYSQL_DATABASE: magento
@@ -59,7 +59,7 @@ services:
5959
- M2D_ENABLE_SEARCH_ENGINE=${M2D_ENABLE_SEARCH_ENGINE:-yes}
6060
- M2D_SEARCH_ENGINE_VENDOR=${M2D_SEARCH_ENGINE_VENDOR:-elasticsearch}
6161
- M2D_SEARCH_ENGINE_VERSION=${M2D_SEARCH_ENGINE_VERSION:-7}
62-
container_name: m2d-searchengine
62+
container_name: "m2d-searchengine${M2D_PROJECT_SUFFIX:-}"
6363
environment:
6464
- "ES_JAVA_OPTS=-Xms128m -Xmx1g"
6565
- "OPENSEARCH_JAVA_OPTS=-Xms128m -Xmx1g"
@@ -75,7 +75,7 @@ services:
7575
- M2D_ENABLE_MESSAGE_BROKER=${M2D_ENABLE_MESSAGE_BROKER:-no}
7676
- M2D_MESSAGE_BROKER_VENDOR=${M2D_MESSAGE_BROKER_VENDOR:-rabbitmq}
7777
- M2D_MESSAGE_BROKER_VERSION=${M2D_MESSAGE_BROKER_VERSION:-3.8}
78-
container_name: m2d-messagebroker
78+
container_name: "m2d-messagebroker${M2D_PROJECT_SUFFIX:-}"
7979
restart: unless-stopped
8080
ports:
8181
- "${M2D_PORT_FOR_MESSAGE_BROKER:-15672}:15672"
@@ -89,7 +89,7 @@ services:
8989
- M2D_ENABLE_WEB_CACHE=${M2D_ENABLE_WEB_CACHE:-no}
9090
- M2D_WEB_CACHE_VENDOR=${M2D_WEB_CACHE_VENDOR:-varnish}
9191
- M2D_WEB_CACHE_VERSION=${M2D_WEB_CACHE_VERSION:-6}
92-
container_name: m2d-webcache
92+
container_name: "m2d-webcache${M2D_PROJECT_SUFFIX:-}"
9393
restart: unless-stopped
9494
ports:
9595
- "${M2D_PORT_FOR_WEB_CACHE:-8080}:8080"
@@ -103,7 +103,7 @@ services:
103103
- M2D_ENABLE_DB_CACHE=${M2D_ENABLE_DB_CACHE:-no}
104104
- M2D_DB_CACHE_VENDOR=${M2D_DB_CACHE_VENDOR:-redis}
105105
- M2D_DB_CACHE_VERSION=${M2D_DB_CACHE_VERSION:-6.0}
106-
container_name: m2d-dbcache
106+
container_name: "m2d-dbcache${M2D_PROJECT_SUFFIX:-}"
107107
restart: unless-stopped
108108

109109
mailcatcher:
@@ -113,7 +113,7 @@ services:
113113
target: m2d_mailcatcher
114114
args:
115115
- M2D_ENABLE_MAILCATCHER=${M2D_ENABLE_MAILCATCHER:-no}
116-
container_name: m2d-mailcatcher
116+
container_name: "m2d-mailcatcher${M2D_PROJECT_SUFFIX:-}"
117117
ports:
118118
- "${M2D_PORT_FOR_MAILCATCHER:-1080}:1080"
119119

@@ -124,7 +124,7 @@ services:
124124
target: m2d_blackfire
125125
args:
126126
- M2D_ENABLE_BLACKFIRE=${M2D_ENABLE_BLACKFIRE:-no}
127-
container_name: m2d-blackfire
127+
container_name: "m2d-blackfire${M2D_PROJECT_SUFFIX:-}"
128128
environment:
129129
- BLACKFIRE_SERVER_ID
130130
- BLACKFIRE_SERVER_TOKEN
@@ -138,7 +138,7 @@ services:
138138
- M2D_CPU_TYPE=${M2D_CPU_TYPE:-m1}
139139
- M2D_ENABLE_SELENIUM=${M2D_ENABLE_SELENIUM:-no}
140140
- M2D_SELENIUM_VERSION=${M2D_SELENIUM_VERSION:-'3.14.0'}
141-
container_name: m2d-selenium
141+
container_name: "m2d-selenium${M2D_PROJECT_SUFFIX:-}"
142142
volumes:
143143
- /dev/shm:/dev/shm
144144
ports:
@@ -148,7 +148,7 @@ services:
148148

149149
networks:
150150
default:
151-
name: m2d-network
151+
name: "m2d-network${M2D_PROJECT_SUFFIX:-}"
152152

153153
volumes:
154154
home-volume:

0 commit comments

Comments
 (0)