Skip to content

Commit 9820814

Browse files
committed
2 parents 75ea0ea + f1942c0 commit 9820814

File tree

9 files changed

+174
-165
lines changed

9 files changed

+174
-165
lines changed

README.md

Lines changed: 145 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,15 @@
1010

1111
## Motivation
1212

13-
This project aims to offer a good performance solution for MAC users that want to use docker on development.
14-
This is a docker setup optimised for Magento2 on Mac. It has same performance as Linux or local setups.
13+
This project aims to offer a good performance solution for Mac users that want to use docker on development.
14+
This is a docker setup optimised for Magento 2 on Mac. It has same performance as Linux or local setups.
1515

1616
## Main Features
1717

18-
### Overcome Docker for Mac performance issues on Magento 2
19-
20-
* Use docker volumens for following directories:
21-
22-
* vendor
23-
* generated
24-
* var
25-
* pub/static
26-
* pub/media
27-
28-
* Sincronise `vendor` and `generated` using a specific `sync` container. See [Sync vendor & generated section](#sync)
18+
### Overcome Docker for Mac performance issue
2919

3020
<details>
31-
<summary>Docker for Mac performance issues</summary>
21+
<summary>Open to read issue explanation</summary>
3222

3323
From docker for mac documentation: https://docs.docker.com/docker-for-mac/troubleshoot/#known-issues
3424

@@ -45,13 +35,55 @@ As a work-around for this behavior, you can put vendor or third-party library di
4535

4636
</details>
4737

38+
**Solution:**
39+
40+
* Use docker volumes for following directories:
41+
42+
* vendor
43+
* generated
44+
* var
45+
* pub/static
46+
* pub/media
47+
48+
* Synchronise `vendor` and `generated` volumes using a specific `unison` container.
49+
50+
<details>
51+
<summary>How to sync volumes between host and container</summary>
52+
53+
See [dockergento workflow](#workflow) for a better understanding about whole development process with dockergento.
54+
55+
There are 2 options to sync the volumes `vendor` and `generated`
56+
57+
**Option 1: One time sync**
58+
59+
This option must be used most of the times. You should only need to sync `vendor` and `generated` from time to time for debugging purposes
60+
61+
```
62+
docker-compose run --rm unison sync -path vendor -path generated
63+
```
64+
65+
NOTE: For faster and more specific syncs, you can specify a subfolder like `sync -path vendor/<company_name>`.
66+
67+
**Option 2: Watch**
68+
69+
This option is only recommended if you are implementing code in a vendor module.
70+
71+
```
72+
docker-compose run --rm unison watch -path vendor/<company_name>/<module_name>`
73+
```
74+
75+
</details>
76+
77+
4878
## Preconditions
4979

5080
1. Configure your docker `File Sharing` settings
5181

5282
![File Sharing Configuration](docs/img/file_sharing.png)
83+
84+
NOTE: You do not need to have `Composer` installed. You only need to create a `.composer` folder in your computer, so it can be used by containers to cache composer dependecies instead of downloading them everytime.
5385

54-
2. Optionally apply these performance tweaks
86+
2. Optionally you can also apply these performance tweaks
5587

5688
* [http://markshust.com/2018/01/30/performance-tuning-docker-mac](http://markshust.com/2018/01/30/performance-tuning-docker-mac)
5789

@@ -60,10 +92,91 @@ As a work-around for this behavior, you can put vendor or third-party library di
6092
1. Copy this docker configuration repository in your project
6193

6294
```
95+
cd <path_to_your_project>
6396
curl -L https://api.github.com/repos/ModestCoders/magento2-dockergento/tarball | tar xz --strip=1
6497
```
6598

66-
2. Edit your magento paths or nginx configuration if needed
99+
2. Edit binded paths or nginx configuration if needed
100+
101+
<details>
102+
<summary>More info about custom configurations</summary>
103+
104+
**Binded Paths:**
105+
106+
If you install magento code in a different folder than your project root, you might need to replace `<magento_dir>` on the following files:
107+
108+
* `docker-compose.yml`
109+
110+
```
111+
app-volumes:
112+
build: ./config/docker/image/app-volumes
113+
volumes: &appvolumes
114+
- .:/var/www/html:delegated
115+
- ~/.composer:/var/www/.composer:delegated
116+
- sockdata:/sock
117+
- app-vendor:/var/www/html/<magento_dir>/vendor
118+
- app-generated:/var/www/html/<magento_dir>/generated
119+
- app-var:/var/www/html/<magento_dir>/var
120+
- pub-static:/var/www/html/<magento_dir>/pub/static
121+
- pub-media:/var/www/html/<magento_dir>/pub/media
122+
- integration-test-sandbox:/var/www/html/<magento_dir>/dev/tests/integration/tmp
123+
124+
unison:
125+
image: modestcoders/unison:2.51.2
126+
volumes:
127+
- app-vendor:/var/www/html/<magento_dir>/vendor
128+
- app-generated:/var/www/html/<magento_dir>/generated
129+
- ./vendor:/sync/vendor
130+
- ./generated:/sync/generated
131+
environment:
132+
- SYNC_SOURCE_BASE_PATH=/sync
133+
- SYNC_DESTINATION_BASE_PATH=/var/www/html/<magento_dir>
134+
- SYNC_MAX_INOTIFY_WATCHES=60000
135+
```
136+
137+
* `config/docker/image/app-volumes/Dockerfile`
138+
139+
```
140+
RUN mkdir -p /var/www/html/<magento_dir>/vendor \
141+
/var/www/html/<magento_dir>/generated \
142+
/var/www/html/<magento_dir>/var \
143+
/var/www/html/<magento_dir>/pub/static \
144+
/var/www/html/<magento_dir>/pub/media \
145+
/var/www/html/<magento_dir>/dev/tests/integration/tmp \
146+
&& chown -R 1000:1000 /var/www/html/<magento_dir>
147+
```
148+
149+
* `config/docker/image/nginx/conf/default.conf`
150+
151+
```
152+
server {
153+
# ...
154+
set $MAGE_ROOT /var/www/html/<magento_dir>;
155+
# ...
156+
```
157+
158+
**Nginx Multi-store:**
159+
160+
If you have a multi-store magento, you need to add your website codes to the ngnix configuration as follows:
161+
162+
* `config/docker/image/nginx/conf/default.conf`
163+
164+
```
165+
# WEBSITES MAPPING
166+
map $http_host $MAGE_RUN_CODE {
167+
168+
default base;
169+
## For multi-store configuration add here your domain-website codes
170+
dominio-es.lo es;
171+
dominio-ch.lo ch;
172+
dominio-de.lo de;
173+
}
174+
```
175+
</details>
176+
177+
3. (Recommended) Install [magento2-dockergento-console](https://github.com/ModestCoders/magento2-dockergento-console)
178+
179+
It is recommended to use this bash script tool for easier development workflow. See [dockergento workflow](#workflow)
67180

68181
## Usage
69182

@@ -82,63 +195,35 @@ sudo vim /etc/hosts
82195
// Add -> 127.0.0.1 <your-domain>
83196
```
84197

85-
### Execute Magento commands
86-
87-
Magento commands must be executed inside the `php` container
88-
89-
```
90-
docker-compose exec phpfpm bash
91-
```
92-
93-
### <a name="sync"></a> Sync vendor and generated
94-
95-
There are 2 options to sync the volumes `vendor` and `generated`
198+
### <a name="workflow"></a> Workflow
96199

97-
#### Option 1: One time sync
98-
99-
This option must be used most of the times. You should only need to sync `vendor` and `generated` from time to time for debugging purposes
100-
101-
```
102-
docker-compose run --rm unison sync -path <path_to_sync>
103-
```
200+
See detailed documentation about development workflow with dockergento
104201

105-
**NOTE:** `<path_to_sync>` should be `vendor` or `generated`. For faster and more specific syncs, you can include the subfolder path inside `vendor` like `sync -path vendor/<company_name>`.
202+
* `magento2-dockergento-console` > [Development Workflow](https://github.com/ModestCoders/magento2-dockergento-console/blob/master/docs/workflow.md)
106203

107-
#### Option 2: Watch
204+
## Xdebug
108205

109-
This option is only recommended if you are implementing code in a vendor module.
206+
* [PHPStorm + Xdebug Setup](docs/xdebug_phpstorm.md)
110207

111-
```
112-
docker-compose run --rm unison watch -path <path_to_sync>
113-
```
208+
## Grumphp
114209

115-
Example: `docker-compose run --rm unison watch -path vendor/<company_name>/<module_name>`
210+
* [Grumphp Setup](docs/grumphp_setup.md)
116211

117-
### Frontend
212+
## Docker Images
118213

119-
1. NPM config setup (Only first time)
214+
* [Docker Images List](docs/docker_images.md)
120215

121-
```
122-
docker-compose run --rm node sh -c "cp -n package.json.sample package.json \
123-
&& cp -n Gruntfile.js.sample Gruntfile.js \
124-
&& npm install"
125-
```
216+
## Troubleshooting
126217

127-
2. Grunt watch
218+
### Named volumes suddenly binded to host
128219

129-
```
130-
docker-compose run --rm node sh -c "grunt exec:<theme>"
131-
docker-compose run --rm node sh -c "grunt watch"
132-
```
220+
There is bug in docker that causes volumes to stop working and start behabing like a binded mount. If you notice a performance decrease, try the following:
133221

134-
## Xdebug
222+
* `dockergento volumes-check`
135223

136-
* [Xdebug enable/disable](docs/xdebug.md)
137-
* [PHPStorm + Xdebug Setup](docs/xdebug_phpstorm.md)
224+
In case of confirmation that volumes are broken, restart dockergento
138225

139-
## Grumphp
140-
141-
* [Grumphp Setup](docs/grumphp_setup.md)
226+
* `dockergento restart`
142227

143228
## ChangeLog
144229

@@ -163,4 +248,4 @@ This project has been possible thanks to the following resources:
163248
[GNU General Public License, version 3 (GPLv3)](http://opensource.org/licenses/gpl-3.0)
164249

165250
## Copyright
166-
(c) ModestCoders
251+
(c) ModestCoders

config/docker/image/nginx/conf/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
map $http_host $MAGE_RUN_CODE {
33

44
default base;
5-
## For multi-store configuration add here your "domains <> website codes"
5+
## For multi-store configuration add here your domain-website codes
66
# dominio-es.lo es;
77
# dominio-ch.lo ch;
88
# dominio-de.lo de;

config/docker/image/phpfpm/Dockerfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ services:
2323
- phpfpm
2424

2525
phpfpm:
26-
build: ./config/docker/image/phpfpm
26+
image: modestcoders/php:7.1-fpm
2727
volumes: *appvolumes
2828
environment:
2929
PHP_IDE_CONFIG: serverName=localhost
@@ -61,8 +61,6 @@ services:
6161
node:
6262
image: modestcoders/node-php:node8-php7.1
6363
volumes: *appvolumes
64-
environment:
65-
- NPM_CONFIG_PREFIX=/home/app/.npm-global # To avoid permission error on npm install. It tries to save it at /var/www (root is the owner)
6664
depends_on:
6765
- app-volumes
6866

docs/docker_images.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Docker images
2+
3+
## Ngnix
4+
5+
* [markoshust/magento-nginx](https://hub.docker.com/r/markoshust/magento-nginx/)
6+
7+
## PHP-FPM
8+
9+
* [modestcoders/php](https://hub.docker.com/r/modestcoders/unison/)
10+
11+
## UNISON
12+
13+
* [modestcoders/unison](https://hub.docker.com/r/modestcoders/unison/)
14+
15+
## NODE-PHP
16+
17+
* [modestcoders/node-php](https://hub.docker.com/r/modestcoders/node-php/)

docs/img/file_sharing.png

-7.96 KB
Loading

docs/img/interpreter_phpfpm_image.png

-395 Bytes
Loading

0 commit comments

Comments
 (0)