Skip to content

Commit 3f05945

Browse files
author
Alan Kent
committed
Revised Unison support for Mac.
Fixed typo in m2unison.bat.
1 parent b7b9fbd commit 3f05945

File tree

5 files changed

+95
-71
lines changed

5 files changed

+95
-71
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@ significant work on the project without Unison running to avoid merge conflicts
433433

434434
**Mac**
435435

436-
TODO: VERIFY WHEN TESTING FINISHED.
437-
438436
On Mac, first install Unison using "brew". This installs the correct command
439437
line version of Unison. Also install "unox" for a companion file watching
440438
utility.
@@ -446,7 +444,7 @@ utility.
446444
For Mac, create a "profile" file in `~/.unison/m2devbox-{myproj}.prf` ({myproj}
447445
is the current directory name) by running the following command.
448446

449-
./m2unison-profile TODO: THIS SHOULD RUN SSH TO ACCEPT SSH FINGERPRINT
447+
./m2unison-profile
450448

451449
To perform a "once off" file synchronization, run
452450

@@ -459,6 +457,12 @@ To continuously synchronize files (recommended), run
459457
It is recommended to run Unison in a separate Terminal window so you can refer
460458
to its output if you ever need to do troubleshooting.
461459

460+
If you ever restart the Docker containers, you may need to rerun
461+
`m2unison-profile` as the profile file containers the SSH port number used
462+
by the Unison container from the `docker-compose.yml` file. (Using the
463+
`2223:22` syntax for the SSH port number in `docker-composer.yml` can avoid
464+
this problem.)
465+
462466
**Windows**
463467

464468
On Windows, run the supplied BAT file to launch Unison in a separate window

docker-compose.yml

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

12+
depends_on:
13+
- db
14+
#- rabbitmq
15+
#- elastic
16+
#- rabbitmq
17+
1218
volumes:
1319

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"
20+
# Uncomment the first line for use with Unison and the "unison"
21+
# service below (Mac, Windows). Uncomment the second line instead
22+
# to mount the volume directly (Linux). Comment out both lines if
23+
# file sharing is not required.
24+
- "/var/www"
1925
#- "./shared/www:/var/www"
2026

2127
# Uncomment to share your ~/.ssh directory with the container.
@@ -74,11 +80,14 @@ services:
7480
- "3001"
7581

7682
# This container contains the Unison process.
77-
# Remove this service if not using Unison.
83+
# Comment out / remove this service if not using Unison (e.g. on Linux).
7884
unison:
7985
restart: always
8086
image: alankent/magento2devbox-unison:latest
8187

88+
depends_on:
89+
- "web"
90+
8291
# Mount the /var/www directory from the "web" container.
8392
volumes_from:
8493
- "web"
@@ -90,6 +99,7 @@ services:
9099

91100
# Pick a random port for ssh based Unison connections (developers
92101
# normally do not log in to this container).
102+
# Use "2223:22" to lock the port number across container restarts.
93103
- "22"
94104

95105
db:

m2unison-profile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
4+
# Unison can connect over SSH or via a socket. SSH is used be default as there
5+
# have been some reports of the socket mode hanging at times.
6+
USE_SOCKET=0
7+
8+
9+
PROJ=$COMPOSE_PROJECT_NAME
10+
if [[ -z $PROJ ]]; then
11+
PROJ=$(basename $PWD)
12+
fi
13+
M2PROFILE=m2devbox-$PROJ
14+
15+
mkdir -p ~/.unison
16+
17+
LOCAL_ROOT=$(pwd)/shared/www
18+
if [[ $USE_SOCKET == 1 ]]; then
19+
# Fetch the external Docker Unison port number
20+
SSH_ARGS_LINE=
21+
UNISON_PORT=$(docker-compose port unison 5000 | awk -F: '{print $2}')
22+
REMOTE_ROOT=socket://localhost:$UNISON_PORT//var/www
23+
else
24+
SSH_PORT=$(docker-compose port unison 22 | awk -F: '{print $2}')
25+
echo "Testing 'ssh' connection to container..."
26+
ssh -p $SSH_PORT magento2@localhost echo Connection successful
27+
SSH_ARGS_LINE="sshargs = -p $SSH_PORT"
28+
REMOTE_ROOT=ssh://magento2@localhost//var/www
29+
fi
30+
31+
cat << EOF > ~/.unison/$M2PROFILE.prf
32+
33+
# WARNING: This file is automatically generated. Changes may be over-written.
34+
35+
$SSH_ARGS_LINE
36+
37+
# Local root
38+
root = $LOCAL_ROOT
39+
40+
# Remote root (Docker container)
41+
root = $REMOTE_ROOT
42+
43+
# Magento files not worth pulling locally.
44+
ignore = Path magento2/var/cache
45+
ignore = Path magento2/var/composer_home
46+
ignore = Path magento2/var/log
47+
ignore = Path magento2/var/page_cache
48+
ignore = Path magento2/var/session
49+
ignore = Path magento2/var/tmp
50+
ignore = Path magento2/var/.setup_cronjob_status
51+
ignore = Path magento2/var/.update_cronjob_status
52+
53+
# Magento files not worth pushing remotely.
54+
ignore = Path magento2/.git
55+
ignore = Path magento2/.gitignore
56+
ignore = Path magento2/.gitattributes
57+
ignore = Path magento2/.magento
58+
ignore = Name .idea
59+
ignore = Name .*.swp
60+
ignore = Name .unison.*
61+
62+
prefer = $LOCAL_ROOT
63+
preferpartial = Path var -> $REMOTE_ROOT
64+
auto = true
65+
batch = true
66+
67+
EOF
68+
69+
echo "Unison profile '$M2PROFILE' has been created in '~/.unison'."
70+
echo "Run 'unison -repeat watch $M2PROFILE' for file syncing mode."
71+

m2unison.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ REM **** Entering file watch mode ****
9999
SET REMOTE_ROOT=socket://localhost:%UNISON_PORT%//var/www
100100
:done2
101101

102-
set UNISONARGS=%LOCAL_ROOT% %REMOTE_ROOT% -sshargs "%SSH_ARGS" -prefer %LOCAL_ROOT% -preferpartial "Path var -> %REMOTE_ROOT%" -auto -batch %IGNORE%
102+
set UNISONARGS=%LOCAL_ROOT% %REMOTE_ROOT% -sshargs "%SSH_ARGS%" -prefer %LOCAL_ROOT% -preferpartial "Path var -> %REMOTE_ROOT%" -auto -batch %IGNORE%
103103

104104
@ECHO ON
105105
REM **** Unison exited - Restarting file watch mode ****

m2unison.sh

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

0 commit comments

Comments
 (0)