Skip to content

Commit 05ef109

Browse files
author
Alan Kent
committed
Refetch unison port number in case it changes after a container restart.
1 parent 85ddcf8 commit 05ef109

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ laptop batteries. To manually trigger background index updates, run `magento
352352
cron:run` twice in a row (sometimes the first cron schedules jobs for the
353353
second cron to run).
354354

355+
cd /var/www/magento2
355356
magento cron:run
356357
magento cron:run
357358

@@ -473,6 +474,8 @@ Magento 2.2 onwards.
473474

474475
To turn on usage of Redis for session caching, run
475476

477+
cd /var/www/magento2
478+
rm var/session/*
476479
magento setup:config:set --session-save=redis --session-save-redis-host=redis --session-save-redis-log-level=3 --session-save-redis-timeout=10
477480

478481
To turn on usage of Redis for default data caching, run
@@ -554,15 +557,23 @@ directory).
554557
Next, add a repository reference to all the directories containing packages
555558
(that is, all directories containing a `composer.json` file). You may use `*`
556559
in path wildcards to include multiple directories at a time. Make sure you use
557-
quotes to make sure the shell does not expand the wildcards.
560+
quotes to make sure the shell does not expand the wildcards. (The wildcard will
561+
match directories such as modules in `app/code/Magento/*` and themes in
562+
`app/design/MyVendor/*`.)
563+
564+
composer config repositories.myrepo path "../myrepo/app/*/*/*"
565+
566+
If developing a module, set the minimum stability to `dev` (and set it back to
567+
a stable level when going live). See the Composer documentation for more
568+
options.
558569

559-
composer config repositories.myrepo path "../myrepo/app/*/myvendor/*"
570+
composer config minimum-stability dev
560571

561572
You can then add dependencies to any of the packages in the specified
562573
directories. Composer will create a symlink from under the `vendor/myvendor`
563574
directory to the appropriate git repository directory.
564575

565-
composer require myvendor/module-mymodule:*
576+
composer require "myvendor/module-mymodule:*"
566577

567578
Note that while Unison will not sync the symlink, if you specify the
568579
`shared/www` local directory as the "source code root" in PHP Storm, it will

m2unison.bat

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ REM Add Windows\system32 to start of path to find the right "timeout" command
1616
REM Cygwin can end up with 'unix like' timeout in path instead otherwise
1717
PATH C:\Windows\System32;%PATH%
1818

19-
REM Fetch the external Docker Unison port number
20-
FOR /f "delims=" %%A IN ('docker-compose port web 5000') DO SET "CMD_OUTPUT=%%A"
21-
FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "UNISON_PORT=%%B"
22-
2319
@SET LOCAL_ROOT=./shared/www
24-
@SET REMOTE_ROOT=socket://localhost:%UNISON_PORT%//var/www
2520

2621
@SET IGNORE=
2722

@@ -34,8 +29,6 @@ REM Magento files not worth pulling locally.
3429
@SET IGNORE=%IGNORE% -ignore "Path magento2/var/tmp"
3530
@SET IGNORE=%IGNORE% -ignore "Path magento2/var/.setup_cronjob_status"
3631
@SET IGNORE=%IGNORE% -ignore "Path magento2/var/.update_cronjob_status"
37-
@SET IGNORE=%IGNORE% -ignore "Path magento2/pub/media"
38-
@SET IGNORE=%IGNORE% -ignore "Path magento2/pub/static"
3932

4033
REM Other files not worth pushing to the container.
4134
@SET IGNORE=%IGNORE% -ignore "Path magento2/.git"
@@ -46,6 +39,11 @@ REM Other files not worth pushing to the container.
4639
@SET IGNORE=%IGNORE% -ignore "Name {.*.swp}"
4740
@SET IGNORE=%IGNORE% -ignore "Name {.unison.*}"
4841

42+
REM Fetch the external Docker Unison port number
43+
FOR /f "delims=" %%A IN ('docker-compose port web 5000') DO SET "CMD_OUTPUT=%%A"
44+
FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "UNISON_PORT=%%B"
45+
@SET REMOTE_ROOT=socket://localhost:%UNISON_PORT%//var/www
46+
4947
@set UNISONARGS=%LOCAL_ROOT% %REMOTE_ROOT% -prefer %LOCAL_ROOT% -preferpartial "Path var -> %REMOTE_ROOT%" -auto -batch %IGNORE%
5048

5149
IF NOT EXIST %LOCAL_ROOT%/magento2/vendor (
@@ -57,6 +55,14 @@ REM **** Entering file watch mode ****
5755
:loop_sync
5856
.\unison %UNISONARGS% -repeat watch
5957
TIMEOUT 5
58+
59+
REM Re-fetch the external Docker Unison port number in case it changed.
60+
FOR /f "delims=" %%A IN ('docker-compose port web 5000') DO SET "CMD_OUTPUT=%%A"
61+
FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "UNISON_PORT=%%B"
62+
@SET REMOTE_ROOT=socket://localhost:%UNISON_PORT%//var/www
63+
64+
@set UNISONARGS=%LOCAL_ROOT% %REMOTE_ROOT% -prefer %LOCAL_ROOT% -preferpartial "Path var -> %REMOTE_ROOT%" -auto -batch %IGNORE%
65+
6066
@GOTO loop_sync
6167

6268
:exit

m2unison.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ if [[ ! -f unison ]]; then
1212
chmod +x unison unison-fsmonitor
1313
fi
1414

15-
# Fetch the external Docker Unison port number
16-
UNISON_PORT=$(docker-compose port web 5000 | awk -F: '{print $2}')
17-
1815
LOCAL_ROOT=./shared/www
19-
REMOTE_ROOT=socket://localhost:$UNISON_PORT//var/www
2016

2117
IGNORE=
2218

@@ -29,8 +25,6 @@ IGNORE="$IGNORE -ignore 'Path magento2/var/session'"
2925
IGNORE="$IGNORE -ignore 'Path magento2/var/tmp'"
3026
IGNORE="$IGNORE -ignore 'Path magento2/var/.setup_cronjob_status'"
3127
IGNORE="$IGNORE -ignore 'Path magento2/var/.update_cronjob_status'"
32-
IGNORE="$IGNORE -ignore 'Path magento2/pub/media'"
33-
IGNORE="$IGNORE -ignore 'Path magento2/pub/static'"
3428

3529
# Other files not worth pushing to the container.
3630
IGNORE="$IGNORE -ignore 'Path magento2/.git'"
@@ -41,6 +35,10 @@ IGNORE="$IGNORE -ignore 'Name {.idea}'"
4135
IGNORE="$IGNORE -ignore 'Name {.*.swp}'"
4236
IGNORE="$IGNORE -ignore 'Name {.unison.*}'"
4337

38+
# Fetch the external Docker Unison port number
39+
UNISON_PORT=$(docker-compose port web 5000 | awk -F: '{print $2}')
40+
41+
REMOTE_ROOT=socket://localhost:$UNISON_PORT//var/www
4442
UNISONARGS="$LOCAL_ROOT $REMOTE_ROOT -prefer $LOCAL_ROOT -preferpartial 'Path var -> $REMOTE_ROOT' -auto -batch $IGNORE"
4543

4644
if [[ ! -f $LOCAL_ROOT/magento2/vendor ]]; then
@@ -51,5 +49,13 @@ fi
5149
while true; do
5250
echo "**** Entering file watch mode ****"
5351
./unison $UNISONARGS -repeat watch
52+
5453
sleep 5
54+
55+
# Re-fetch the external Docker Unison port number in changes
56+
UNISON_PORT=$(docker-compose port web 5000 | awk -F: '{print $2}')
57+
58+
REMOTE_ROOT=socket://localhost:$UNISON_PORT//var/www
59+
UNISONARGS="$LOCAL_ROOT $REMOTE_ROOT -prefer $LOCAL_ROOT -preferpartial 'Path var -> $REMOTE_ROOT' -auto -batch $IGNORE"
60+
5561
done

0 commit comments

Comments
 (0)