MGT Development Environment - File Sync

File Synchronization on MacOS

To work with a PHP IDE like PhpStorm on your host system, you need to sync your code into the container.
The integrated file sharing solution from docker is very slow and not recommended for Magento 2.

To have a good performance, we need to sync the files from the host system into the container.

For the two-way file-synchronization, we use the great tool Unison.

Setup Unison on MacOS

To work with Unison, it's very important to have the right versions installed.

  1. Download Unison and extract the file tar.gz and copy the binary bin/unison to /usr/local/bin:
sudo cp unison /usr/local/bin/
  1. Open the terminal and install xcode, pip and macfsevents which are needed for unison-fsmonitor.
xcode-select --install
sudo easy_install pip
sudo pip3.9 install macfsevents
sudo pip3.9 install watchdog

Python 3

For pip, python 3 is required. You can install it via Homebrew.

Install python 3 via brew.

brew install python

Set python 3 as default:

ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python
  1. Install the unison-fsmonitor binary:
sudo curl https://db5iu3k4j1efi.cloudfront.net/unison-fsmonitor-IKzJ1fQDsA. -o "/usr/local/bin/unison-fsmonitor" && sudo chmod 775 /usr/local/bin/unison-fsmonitor
  1. Create a sync.sh file for each project you want to sync.

In our example, we want to sync the files from our host system into the container from:

/Users/admin/PhpstormProjects/magento2.mgt/

to

/home/cloudpanel/htdocs/magento2.mgt

We create the file:

/Users/admin/PhpstormProjects/magento2.mgt/bin/sync.sh

with the following content:

#!/bin/bash
#rm -rf /Users/$(whoami)/Library/Application\ Support/Unison/*
unison -repeat watch /Users/admin/PhpstormProjects/magento2.mgt/ ssh://root@127.0.0.1//home/cloudpanel/htdocs/magento2.mgt/ -ui text
Permissions

Make sure the file sync.sh is executable.

To make it executable run: chmod 775 sync.sh

  1. Start file-synchronisation
./sync.sh

Enter the password root to start the file-synchronization.

File Synchronization on Linux

With linux, you can mount a directory from your host to the container without setting up two-way sync.

Run the MGT Development Environment Docker Container with a volume.

File Synchronization on Windows

Setup Unison on Windows

To work with Unison, it's very important to have the right versions installed.

  1. Download and Install OpenSSH.
Download OpenSSH

  1. Download Unison.

Download Unison and extract files to: C:\Program Files\unison

Download Unison

  1. Create a file sync.bat for each project you want to sync.

In our example, we want to sync the files from our host system into the container from

C:\Users\admin\PhpstormProjects\magento2.mgt\

to

/home/cloudpanel/htdocs/magento2.mgt/

For this we create the file:

C:\Users\admin\PhpstormProjects\magento2.mgt\bin\sync.bat

with the following content:

setlocal
set PATH=C:\Program Files\OpenSSH\bin;C:\Program Files\unison
unison -repeat watch C:\Users\admin\PhpstormProjects\magento2.mgt\ ssh://root@127.0.0.1//home/cloudpanel/htdocs/magento2.mgt/ -ui text
  1. Start the file synchronization.

To start the file synchronization open the PowerShell and run sync.bat file

C:\Users\admin\PhpstormProjects\magento2.mgt\bin\sync.bat

Troubleshooting

If you see the error message "Fatal error: inconsistent state. The archive file is missing on some hosts", do the following:

  1. Delete unison archives on host system with the following command:
rm -rf /Users/$(whoami)/Library/Application\ Support/Unison/*
  1. Delete the unison archive in container:
ssh root@127.0.0.1 rm -rf /root/.unison
  1. Start the sync process again.