guard / listen

The Listen gem listens to file modifications and notifies you about the changes.
https://rubygems.org/gems/listen
MIT License
1.92k stars 246 forks source link

Listen don't observing changes in Docker #453

Closed boggddan closed 3 years ago

boggddan commented 6 years ago

Hello, When I change the file, the changes are not loaded in the docker. I change the files to Windows, the mounted folder to the docker.

In Rails 5.2.0 without gem listen everything works or when create rails new app --skip-active-record --api everything works.

docker-compose.yml

version: '3.6'
services:
  db:
    image: postgres:10.5-alpine
    ports:
      - $POSTGRES_PORT:$POSTGRES_PORT
    volumes:
      - postgres:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: $POSTGRES_USER
      POSTGRES_PASSWORD: $POSTGRES_PASSWORD
      POSTGRES_DB: $POSTGRES_DB
      POSTGRES_PORT: $POSTGRES_PORT

  app:
    build:
      context: ./
    command: >
      bash -c "
      bundle check
      || bundle install --clean
      && rm -f tmp/pids/server.pid
      && bundle exec rails server"
    ports:
      - $PORT:$PORT
    volumes:
      - .:/app
    environment:
      DATABASE_URL: postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB?pool=$POSTGRES_POOL
      BUNDLE_PATH: /app/vendor/ruby/gems
    env_file: .env
    depends_on:
      - db
volumes:
  postgres:

Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'

gem 'rails', '~> 5.2.1'
gem 'pg'
gem 'bootsnap', '1.3.1', require: false
gem 'puma'

group :development, :test do
  gem 'listen', '>= 3.0.5', '< 3.2'
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

If I comment gem 'listen' in Gemfile, then an error occurs:

 /app/gems/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require': Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile (LoadError)
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/evented_file_update_checker.rb:61:in `block in initialize'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/core_ext/kernel/reporting.rb:15:in `block in silence_warnings'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/core_ext/kernel/reporting.rb:28:in `with_warnings'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/core_ext/kernel/reporting.rb:15:in `silence_warnings'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/evented_file_update_checker.rb:59:in `initialize'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/i18n_railtie.rb:61:in `new'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/i18n_railtie.rb:61:in `initialize_i18n'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/i18n_railtie.rb:19:in `block in <class:Railtie>'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
app_1    |      from /app/gems/gems/activesupport-5.2.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
app_1    |      from /app/gems/gems/railties-5.2.1/lib/rails/application/finisher.rb:75:in `block in <module:Finisher>'
app_1    |      from /app/gems/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `instance_exec'
app_1    |      from /app/gems/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `run'

How to fix this, so that the docker loads the changes in the files. Thanks

jeffmess commented 5 years ago

Yeah, the listener gem is not working with docker volumes on Mac. When running the exact same docker-compose file on my Linux Mint machine it works fine. From Mac if I bash into the container and touch a file the listener picks it up fine, but from the host machine it's broken.

LuisErnestoZamb commented 4 years ago

I got the same problem. However, I rebuilt the image by removing "bundle install --without production test" by leaving "bundle install" and problem finished. I hope that help.

daveshah commented 3 years ago

I recently experienced the same problem.

I'm on a Mac running Catalina - 10.15.7 and using Docker Desktop version 2.4.0 with Docker version 19.03.13.

I'm able to work around this by using the legacy osxfs file sharing and not opting into using gRPC FUSE. If you're using Docker Desktop, you can disable through the "General" tab under preferences:

Screen Shot 2020-10-12 at 1 25 46 PM

Screen Shot 2020-10-12 at 1 18 53 PM

normancapule commented 3 years ago

I recently experienced the same problem.

I'm on a Mac running Catalina - 10.15.7 and using Docker Desktop version 2.4.0 with Docker version 19.03.13.

I'm able to work around this by using the legacy osxfs file sharing and not opting into using gRPC FUSE. If you're using Docker Desktop, you can disable through the "General" tab under preferences:

Screen Shot 2020-10-12 at 1 25 46 PM

Screen Shot 2020-10-12 at 1 18 53 PM

Same here. This worked for me. Thanks @daveshah for sharing this.

daveshah commented 3 years ago

@mikegee just informed me that there may be a Docker update addressing this issue: https://github.com/docker/for-mac/issues/4962 which seems related. If that is the case and Docker has resolved this / it's an issue on the Docker end, perhaps this issue can be closed out.

ColinDKelley commented 3 years ago

@ms-ati reported that this could have been a special case of #450 since the Linux driver was not listening for :modify events. This will be fixed with https://github.com/guard/listen/pull/502 that we hope to merge and release in v3.3.0.

ColinDKelley commented 3 years ago

Closing this out as #450 is included in v3.3.0.pre.3.