sobota, 14 października 2017

Watchman - How to automatically copy modified files to the docker container

Watchman package is a really great tool but requires a while to understand its magic. To install it just type
$ brew install watchman
In 4.9 version it comes with three commands:
  • watchman
  • watchman-wait
  • watchman-make

The latter two are just utilities under the first one.

Lets focus on watchman itself and one of its outstanding feature called triggers. Actually, it is what it sounds to be - a mechanism that causes invoking given action on a given event happened (for example copying file to the remote server once it appear in certain folder)

Watchman Trigger Examples

Copying js files
 watchman -- trigger $PWD cr '**/*.js' '**/*.css' '**/*.html' '**/*.php' -- sh push.sh
Which basically causes all js, css, html and php files from the current folder are passed to push.sh script.

Push.sh script can look like this:

for i in $@
do
 docker cp $i centrum:/var/www/html/$i
done