If you follow my blog, you will have seen I was doing some recent exploration of Gulp. You may also know I am quite interested in Docker. So it was interesting to try them out together.
For Docker, you can have files located in the container. But I frequently blow the container away and start again if it goes “strange” (or just to reset to a known state). If the master files are inside the container, you lose your work. Ugg.
Docker has the concept of volumes, which are useful. You can have directories of the host OS mounted inside the container. Deleting the container does not lose the files in the host mounted directories.
But, in addition, I work on Windows (yeah, yeah, I know! I have to do lots of PowerPoint decks and Outlook stuff, so until Microsoft does a better job on OS X I am sticking with Windows). This means I run Docker inside a VM. That means if I lose the VM instance I lose my files again. So I not only want volumes, I want them going all the way back to the host OS (through the VM layer).
And this is where the reports of slowness come in. VirtualBox for example is known to be somewhat slow for sharing Windows/OS X files system with the Docker running in the VM. Some approaches have improved performance (e.g. using NFS), but there are less options here for Windows than OS X.
For Windows, I was getting reasonable performance for having app/code, app/design, and app/i18n mounted but everything else living inside the container. Not perfect, but it was working pretty well and my files were protected against loss.
(Oh, I am quite liking the simplicity of installation for the latest “Docker Tools” available from Docker. Kitematic (alpha) is a little buggy still, but the installation was a breeze. Volume mounting is also pretty easy – just a few clicks in a GUI and one.)
Then I hit my next problem. Gulp works by using inotify to watch for file system changes. On file change, it automatically triggers a Less compilation build. Combined also with Live Reload, this greatly helps front end devs. Well, of course it would be too easy if Windows/OS X files system inotify events were exported through VirtualBox. So if you mount app/design this way, Gulp does not spot the file system changes. Bummer.
So more recently I have been exploring a few text editors to see how good a job of file syncing over say SFTP. (I picked SFTP because it was easy to install inside Docker and easy to authenticate – no messing with keys. This might not be a good long term solution.)
For example, editors that seem to support SFTP syncing include
- PHP Storm – but only after fiddling with the server side configuration to accept the protocol versions PHP Storm uses, and pushing ‘vendor’ killed it (exponential slow down with number of files), so back to just pushing selected files or directories.
- Atom, by GitHub – but I could not actually get it to work yet.
- Sublime Text – I have not actually tried it yet, but numerous people said “it’s good”.
- Bluefish – but I could not get it to work either.
Hmmmm. It was not the easy setup and configuration experience I was hoping for.
But the file system sync approach seems to have the following benefits:
- Inside the container things run fast – all local file system.
- The source files are protected – the master copy is not inside the container.
- Gulp works – the push into the container generates inotify events correctly.
- You can use composer inside the container to download everything into the ‘vendor’ directory, then just have the “real” project files pushed over on top (one-way sync).
- It’s easy to put all the files you change under source code management without committing all of Magento – you commit the local files only.
So I am starting to warm up to the “sync files from local OS into the Docker image” approach, even though the setup of text editors seemed a bit harder than I expected.
That led me to browsing around and finding tools like lsyncd. That way, you can use *any* tools or editors modifying the local file system and have changes efficiently pushed into the Docker container (in one direction). It would be nice to have an easy to install tool for Windows and OS X that was easy to configure to sync to the Docker image. (lsyncd looks good, but is provided as source code – so Magento developers first need to get a C compiler installed? Not exactly a frictionless install experience!)
[Update: Feb 4, 2016: WinSCP seems to have a “continuously watch and copy” mode (Ctl-U) that looks pretty close to lsyncd.]
So how about “install vanilla Magento inside the Docker container, then do all customizations in your local file system and use an inotify based approach to efficiently sync file system changes into the Docker container”. With this approach, sometimes you do log in and do things inside the container, but most of the time you are editing source code locally. You then put only the local files in Git. The web server however runs inside the Docker container making it easy to share configuration between developers.
Do you use an inotify (or similar) based file sync scheme for your projects? Any experiences you want to share? Any “easy to set up perfect tool” that you use to sync files from Windows and OS X to Linux?