Skip to content

Commit 27c1d5d

Browse files
author
Alan Kent
committed
Moving over to docker-sync for Mac support.
Unison is written in OCaml. OCaml 4.02 changed the serialization format over 4.01 so Unison binaries compiled with different versions of OCaml are not compatible! The PHP-FPM container is based on Jessie where OCaml 4.01 is available. Using docker-sync allows a newer Linux container to be used for Unison with OCaml 4.02. There are almost no working binaries still available for Mac using OCaml 4.01. The Windows binary for OCaml 4.02 is now included. So finally managed to find a combination that works across all platforms. Egad!
1 parent a327da8 commit 27c1d5d

File tree

5 files changed

+197
-81
lines changed

5 files changed

+197
-81
lines changed

README.md

Lines changed: 85 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ control.
1414
DevBox contains all the the software packages you need to develop a Magento
1515
site, except for IDEs and web browsers. A local development environment
1616
typically starts with a database container (holding MySQL) and a web server
17-
container (holding the Magento source code). Other containers can be added as
18-
required for Varnish (recommended), Redis, RabbitMQ, and ElasticSearch. All
19-
containers run Linux inside.
17+
container (holding the Magento source code). On Mac and Windows, another
18+
container is used for file sharing (discussed below). Other containers can be
19+
added as required for Varnish (recommended), Redis, RabbitMQ, and
20+
ElasticSearch. All containers run Linux inside.
2021

2122
Developers mainly interact with the web container. The other containers are
2223
relatively shrink wrap.
@@ -43,16 +44,30 @@ Mac and Windows cannot directly access the file system inside the web container
4344
works fine. By default the volume mounts are commented out in the
4445
`docker-compose.yml` file for improved performance.
4546

47+
* Docker volume mounts for Mac and Windows are slow for large projects like
48+
Magento.
49+
4650
* Some frontend developer tools like Gulp and Grunt rely on file watching
4751
"iNotify" file system events. Docker Volume mounting on Windows does not
4852
support iNotify events at this time.
4953

5054
Where volume mounts are not suitable (specifically, the Magento source code
5155
directory on Mac and Windows), DevBox syncs the local and container file
52-
systems using a program called Unison. Whenever a file in the watched local file
53-
system is changed, it is copied into the web container, and vice versa. This
54-
allows IDEs to be natively used on a laptop (or desktop) - Unison copies file
55-
changes as soon as they are written to disk into the web conatiner.
56+
systems using a program called Unison. Whenever a file in the watched local
57+
file system is changed, it is copied into the web container, and vice versa.
58+
This allows IDEs to be natively used on a laptop (or desktop) - Unison copies
59+
file changes as soon as they are written to disk into the web conatiner.
60+
61+
DevBox uses the "Docker Sync" project (http://docker-sync.io/) for file
62+
sharing, but only uses the Unison mode of file sharing.
63+
64+
(Insiders secret: Unison is written in a language called OCaml. OCaml 4.01 and
65+
4.02 changed a serialization algorithm in a backwards incompatible way. So you
66+
need to make sure you have Unison binaries on Windows, Mac, and Linux compiled
67+
with the same version of OCaml. Brew + Docker-Sync + the supplied Windows
68+
binary currently all match. If you try experimenting with other binaries,
69+
beware the pit of despair when things start going strange for no apparent
70+
reason!)
5671

5772
# Installation
5873

@@ -70,6 +85,7 @@ ready to get up and going with DevBox.
7085
(https://git-for-windows.github.io/). As well as Git, it includes SSH, an
7186
xterm terminal emulator, and a useful collection of commonly used Linux
7287
commands.
88+
* On Mac, install "Brew" (https://brew.sh/) if you have not done so already.
7389

7490
## Setting Up a New Environment
7591

@@ -91,15 +107,19 @@ this GitHub repository to the project directory.
91107
Review the `docker-compose.yml` file in a text editor, making necessary
92108
adjustments as described by comments in the file. This includes:
93109

94-
* To enable volume mounting for the Magento source code (e.g. for Linux
95-
laptops), uncomment the volume mount line for `/var/www` in the provided
96-
`docker-compose.yml` file. For Unison (e.g. for Mac and Windows), ensure the
97-
line is commented out.
110+
* For Mac and Windows, make sure the `src:/var/www` volume is uncommented and
111+
the `./shared/www:/var/www` line is commented out. Make sure the "unison"
112+
service is also uncommented. This is required for Unison to access the
113+
Magento source code.
114+
115+
* For Linux, direct file sharing can be used. Make sure the
116+
`./shared/www:/var/www` line is uncommented and the `src:/var/www` line is
117+
commented out. Also comment out the "unison" service as it is not required.
98118

99119
* Check the port numbers. By default Docker will allocate random free port
100-
numbers. Change "80" to "8080:80" if you want the web server port to be
101-
always 8080. You cannot run different containers at the same time using
102-
the same port numbers.
120+
numbers. Change ports such as "80" to "8080:80" if you want the web server
121+
port to be always 8080. You cannot run different containers at the same time
122+
using the same port numbers.
103123

104124
* The recommended way to create and update projects is via Composer, a PHP
105125
package manager. Magento provides a Composer repository from which Magento
@@ -157,6 +177,11 @@ If you are running Docker in VirtualBox, you may need to edit the local `m2ssh`
157177
and `m2unison` scripts to replace "localhost" with the IP address allocated by
158178
VirtualBox.
159179

180+
Note: If you destroy and recreate containers, SSH may report warnings about
181+
changes in identity and refuse to connect. Use a text editor to remove
182+
"localhost" lines from your `~/.ssh/known_hosts` file to overcome this issue
183+
(you will then be prompted to accept new fingerprints on restart).
184+
160185
### 4. Install Magento
161186

162187
Next you need to install your Magento project inside the web container under
@@ -330,18 +355,17 @@ be added when the project was created above.
330355

331356
**Loading Sample Data (Optional)**
332357

333-
To *download* the Luma sample data, you may need to provide Composer
358+
To download the Luma sample data, you may need to provide Composer
334359
authentication details. If you already have a `~/.composer/auth.json` file you
335360
can run
336361

337362
COMPOSER_AUTH=$(cat ~/.composer/auth.json) magento sampledata:deploy
338363

339-
OTHERWISE run the following command and enter your public and private keys when
364+
If you don't have a `~/.composer/auth.json` file, just run
365+
`magento sampledata:deploy` and enter your public and private keys when
340366
prompted.
341367

342-
magento sampledata:deploy
343-
344-
To *load* the downloaded sample data into the database, run
368+
To load the downloaded sample data into the database, run
345369

346370
magento setup:upgrade
347371

@@ -368,6 +392,9 @@ purposes, but makes all PHP scripts slower to execute.
368392
magento deploy:mode:set developer
369393
xdebug-on
370394

395+
TODO: SEPARATE CLI AND WEB SERVER PHP CONFIGURATION, SO XDEBUG ON BY DEFAULT
396+
FOR WEB SERVER BUT OFF FOR CLI. THEN WE CAN DROP xdebug-on AND xdebug-off.
397+
371398
### 8. Connect with a Web Browser
372399

373400
Run the following command to determine the web server port number to use when
@@ -399,25 +426,51 @@ If you are using Unison for file syncing, you also need to start up a Unison
399426
process (and keep it running). It is generally recommended to start this up
400427
after you have installed Magento above.
401428

429+
Each time you log to your laptop, make sure you restart Unison, but be careful
430+
to not have multiple copies running in parallel. It is not recommended to do
431+
significant work on the project without Unison running to avoid merge conflicts
432+
(rare).
433+
434+
**Mac**
435+
436+
TODO: VERIFY WHEN TESTING FINISHED.
437+
438+
On Mac, first install Unison using "brew". This installs the correct command
439+
line version of Unison. Also install "unox" for a companion file watching
440+
utility.
441+
442+
brew install unison
443+
brew tap eugenmayer/dockersync
444+
brew install eugenmayer/dockersync/unox
445+
446+
For Mac, create a "profile" file in `~/.unison/m2devbox-{myproj}.prf` ({myproj}
447+
is the current directory name) by running the following command.
448+
449+
./m2unison-profile TODO: THIS SHOULD RUN SSH TO ACCEPT SSH FINGERPRINT
450+
451+
To perform a "once off" file synchronization, run
452+
453+
unison m2devbox-{myproj}
454+
455+
To continuously synchronize files (recommended), run
456+
457+
unison -repeat watch m2devbox-{myproj}
458+
459+
It is recommended to run Unison in a separate Terminal window so you can refer
460+
to its output if you ever need to do troubleshooting.
461+
462+
**Windows**
463+
402464
On Windows, run the supplied BAT file to launch Unison in a separate window
403465
using the START command or by double clicking the BAT file via Windows file
404466
explorer. This will automatically retrieve a copy of the `unison.exe` binary
405-
from the web container. Close the window to kill Unison.
467+
from the web container. A profile is not required as the BAT file uses command
468+
line arguments. Close the window to kill Unison.
406469

407470
START m2unison.bat
408471

409-
Mac binaries and a shell script are also provided. It is recommended to run the
410-
sync shell script in a separate Terminal window so you can refer to its output
411-
if you ever need to do troubleshooting.
412-
413-
./m2unison.sh
414-
415-
This shell script cannot be used on Linux, only Mac OSX. Use volume mounting on
416-
Linux (not Unison).
417-
418-
Each time you log in, make sure you restart Unison, but be careful to not have
419-
multiple copies running in parallel. It is not recommended to do significant
420-
work on the project without Unison running to avoid merge conflicts (rare).
472+
There is a setting at the top of the script to choose between SSH access and
473+
direct sockets. Using a plain socket has been reported to hang occasionally.
421474

422475
### 10. Configure PHP Storm (Optional)
423476

docker-compose.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ services:
99
restart: always
1010
image: alankent/magento2devbox-web:latest
1111

12-
# Uncomment this line if you uncomment any of the following volumes.
13-
#volumes:
12+
volumes:
1413

15-
# LEAVE THIS LINE COMMENTED OUT IF YOU ARE USING UNISON.
16-
# Uncomment to use Docker volume mounts to share files with
17-
# local file system.
14+
# Uncomment the first line for use with Unison and the "unison" service
15+
# below (Mac, Windows). Uncomment the second line instead to mount
16+
# the volume directly (Linux). Comment out both lines if file sharing
17+
# is not required.
18+
- "src:/var/www"
1819
#- "./shared/www:/var/www"
1920

2021
# Uncomment to share your ~/.ssh directory with the container.
@@ -67,15 +68,30 @@ services:
6768
# Storm reconfiguration.)
6869
- "2222:22"
6970

70-
# Pick a random unused unison port.
71-
# (Only needed if using Unison for file syncing.)
72-
- "5000"
73-
7471
# Expose the BrowserSync ports.
7572
# (Only needed if using BrowserSync for frontend development.)
7673
- "3000"
7774
- "3001"
7875

76+
# This container contains the Unison process.
77+
# Remove this service if not using Unison.
78+
unison:
79+
restart: always
80+
image: alankent/magento2devbox-unison:latest
81+
82+
# Mount the /var/www directory from the "web" container.
83+
volumes_from:
84+
- "web"
85+
86+
ports:
87+
# Pick a random unused unison "socket" port.
88+
# This can be commented out if "ssh" access is used instead.
89+
- "5000"
90+
91+
# Pick a random port for ssh based Unison connections (developers
92+
# normally do not log in to this container).
93+
- "22"
94+
7995
db:
8096
restart: always
8197
image: mysql:5.6

m2ssh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ SSH_HOST=$(docker-compose port web 22 | awk -F: '{
1515

1616
SSH_PORT=$(docker-compose port web 22 | awk -F: '{print $2}')
1717

18+
exec ssh -p ${SSH_PORT} magento2@${SSH_HOST} $*
19+
20+
# The following version quietens more messages due to recreating containers
1821
exec ssh -o LogLevel=error -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${SSH_PORT} magento2@${SSH_HOST} $*

m2ssh.bat

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ FOR /f "delims=" %%A IN ('docker-compose port web 22') DO SET "CMD_OUTPUT=%%A"
55
FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "SSH_PORT=%%B"
66

77
REM Run SSH
8-
ssh -o LogLevel=error -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p %SSH_PORT% magento2@localhost %*
8+
ssh -p %SSH_PORT% magento2@localhost %*
9+
10+
REM This version avoids problems when containers are destroyed and recreated
11+
REM ssh -o LogLevel=error -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p %SSH_PORT% magento2@localhost %*

0 commit comments

Comments
 (0)