apogiatzis / docker-compose-livereloader

A docker compose pattern to enable automatic container reloading.
77 stars 12 forks source link

Multiple instances #4

Closed rfreis closed 2 years ago

rfreis commented 4 years ago

First of all, congratulations for this contribution! It is really useful!

I succeed using livereloader with my backend container but when I'm trying to create a second one to watch my frontend container, it clashes. Did you try do something like this?

See, this is my backend reloading compose file:

version: '3'

services:
  backend-live-reloader:
    image: apogiatzis/livereloading
    container_name: doc-backend-livereloader
    privileged: true
    environment:
      - RELOAD_DELAY=2 # seconds
      - RELOAD_CONTAINER=doc-backend
      - RELOAD_DIRS=.
      - RESTART_TIMEOUT=1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - .:/app

And this is my frontend watcher file:

version: '3'

services:
  frontend-live-reloader:
    image: apogiatzis/livereloading
    container_name: doc-frontend-livereloader
    privileged: true
    environment:
      - RELOAD_DELAY=2 # seconds
      - RELOAD_CONTAINER=doc-frontend
      - RELOAD_DIRS=./src
      - RESTART_TIMEOUT=1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./src:/home/node/app/src

Both of them works good separately as expeected, but then, when I try to run both of them at the same time, it clashes, and one of them behave like it was the other one.

In this log, backend watcher behave like it was frontend watcher

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    reloader.start()
  File "/reloader/reloader.py", line 128, in start
    observer.start()
  File "/usr/local/lib/python3.7/site-packages/watchdog/observers/api.py", line 253, in start
    emitter.start()
  File "/usr/local/lib/python3.7/site-packages/watchdog/utils/__init__.py", line 110, in start
    self.on_thread_start()
  File "/usr/local/lib/python3.7/site-packages/watchdog/observers/inotify.py", line 121, in on_thread_start
    self._inotify = InotifyBuffer(path, self.watch.is_recursive)
  File "/usr/local/lib/python3.7/site-packages/watchdog/observers/inotify_buffer.py", line 35, in __init__
    self._inotify = Inotify(path, recursive)
  File "/usr/local/lib/python3.7/site-packages/watchdog/observers/inotify_c.py", line 200, in __init__
    self._add_dir_watch(path, recursive, event_mask)
  File "/usr/local/lib/python3.7/site-packages/watchdog/observers/inotify_c.py", line 387, in _add_dir_watch
    raise OSError(errno.ENOTDIR, os.strerror(errno.ENOTDIR), path)
NotADirectoryError: [Errno 20] Not a directory: b'/home/node/app/src'

Do you know what is probably going on?

Thanks for your attention

apogiatzis commented 4 years ago

Hello. I am glad you liked the tool and thanks for the feedback:)

Yes, it becomes a little bit problematic when attempting to run on more than two containers. Ideally you should be able to do that without even adding two separate reloaders.

Unfortunately, this feature is not implanted in the repository yet. I really need to find some time to add this because it is something that has been asked a lot and seems really practical. I will try to do it this week but I can't promise :D . Any PRs are more than welcome of course :)

jdulik commented 3 years ago

@apogiatzis have you added this feature yet?