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.

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 and Install Unison.

Download and install Unison by Drag'n Drop into the Applications folder.

Download Unison

  1. Install the Unison command-line tool.

Click on "Yes" to install the Unison command-line tool.

Install Unison Command Line Tool

  1. Open the terminal and install xcode, pip and macfsevents which are needed for unison-fsmonitor.
xcode-select --install
sudo easy_install pip
sudo pip install macfsevents
sudo pip install watchdog
  1. Install the unison-fsmonitor binary:
sudo curl https://db5iu3k4j1efi.cloudfront.net/unison-fsmonitor-IKzJ1fQDsA. > /usr/local/bin/unison-fsmonitor && 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/stefan/PhpstormProjects/magento2.mgt/

to

/home/cloudpanel/htdocs/magento2.mgt

We create the file:

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

with the following content:

#!/bin/bash
#rm -rf /Users/$(whoami)/Library/Application\ Support/Unison/*
unison -repeat watch /Users/stefan/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\stefan\PhpstormProjects\magento2.mgt\

to

/home/cloudpanel/htdocs/magento2.mgt/

For this we create the file:

C:\Users\stefan\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\stefan\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\stefan\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.