Why is Guard not detecting file changes after dockerizing Rails app?
I am trying to "dockerize" an existing Rails development app. This is my first time experimenting with Docker.
I want to set up Guard to listen for file changes and run relevant specs.
The Guard service appears to be running correctly, and the logs show:
guard_1 | 16:35:12 - INFO - Guard is now watching at '/app'
But when I edit/save spec files Guard is not running any tests.
This is an existing app that I'm moving into Docker. It has a guardfile that works outside of Docker.
I've searched and read a number of posts (e.g. this one), but I'm not sure where to start debugging this. Can anyone point me in the right direction and get Guard listening to file changes.
My docker-compose.yml looks like this:
version: '3'
services:
postgres:
ports:
- "5432:5432"
volumes:
- $HOME/postgres-data:/var/lib/postgresql
image: postgres:9.6.9
redis:
ports:
- "6379:6379"
depends_on:
- postgres
image: redis:5.0-rc
web:
build: .
ports:
- "3000:3000"
command: /bin/sh -c "rails s -b 0.0.0.0 -p 3000"
depends_on:
- postgres
- redis
env_file:
- .env
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
depends_on:
- postgres
- redis
env_file:
- .env
volumes:
redis:
postgres:
sidekiq:
guard:
Guardfile
guard 'spring', bundler: true do
watch('Gemfile.lock')
watch(%r{^config/})
watch(%r{^spec/(support|factories)/})
watch(%r{^spec/factory.rb})
end
guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# RSpec files
rspec = dsl.rspec
watch(rspec.spec_files)
# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end
# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+).feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
ignore %r{^spec/support/concerns/}
end
guard 'brakeman', :run_on_start => true do
watch(%r{^app/.+.(erb|haml|rhtml|rb)$})
watch(%r{^config/.+.rb$})
watch(%r{^lib/.+.rb$})
watch('Gemfile')
end
ruby-on-rails docker guard
add a comment |
I am trying to "dockerize" an existing Rails development app. This is my first time experimenting with Docker.
I want to set up Guard to listen for file changes and run relevant specs.
The Guard service appears to be running correctly, and the logs show:
guard_1 | 16:35:12 - INFO - Guard is now watching at '/app'
But when I edit/save spec files Guard is not running any tests.
This is an existing app that I'm moving into Docker. It has a guardfile that works outside of Docker.
I've searched and read a number of posts (e.g. this one), but I'm not sure where to start debugging this. Can anyone point me in the right direction and get Guard listening to file changes.
My docker-compose.yml looks like this:
version: '3'
services:
postgres:
ports:
- "5432:5432"
volumes:
- $HOME/postgres-data:/var/lib/postgresql
image: postgres:9.6.9
redis:
ports:
- "6379:6379"
depends_on:
- postgres
image: redis:5.0-rc
web:
build: .
ports:
- "3000:3000"
command: /bin/sh -c "rails s -b 0.0.0.0 -p 3000"
depends_on:
- postgres
- redis
env_file:
- .env
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
depends_on:
- postgres
- redis
env_file:
- .env
volumes:
redis:
postgres:
sidekiq:
guard:
Guardfile
guard 'spring', bundler: true do
watch('Gemfile.lock')
watch(%r{^config/})
watch(%r{^spec/(support|factories)/})
watch(%r{^spec/factory.rb})
end
guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# RSpec files
rspec = dsl.rspec
watch(rspec.spec_files)
# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end
# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+).feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
ignore %r{^spec/support/concerns/}
end
guard 'brakeman', :run_on_start => true do
watch(%r{^app/.+.(erb|haml|rhtml|rb)$})
watch(%r{^config/.+.rb$})
watch(%r{^lib/.+.rb$})
watch('Gemfile')
end
ruby-on-rails docker guard
Can you post your Guardfile? And try addingtty: true
underneath yourguard
service? Also, have you tried running your guard command outside of docker to make sure it's configured correctly? I'd try and run it standalone to make sure it's seeing the changes to make sure you've configured it correctly, then move it into a container. Also, are you using minitest, or rspec?
– Jay Dorsey
Jan 4 at 2:40
Thanks @JayDorsey, I will add the guardfile above. I am using Rspec. If I runbundle exec guard
from the command prompt it runs correctly. I’m away from my dev computer just now, but will try running this from a docker bash prompt and report back. Same with thetty: true
config. Thanks!
– Andy Harvey
Jan 5 at 12:57
add a comment |
I am trying to "dockerize" an existing Rails development app. This is my first time experimenting with Docker.
I want to set up Guard to listen for file changes and run relevant specs.
The Guard service appears to be running correctly, and the logs show:
guard_1 | 16:35:12 - INFO - Guard is now watching at '/app'
But when I edit/save spec files Guard is not running any tests.
This is an existing app that I'm moving into Docker. It has a guardfile that works outside of Docker.
I've searched and read a number of posts (e.g. this one), but I'm not sure where to start debugging this. Can anyone point me in the right direction and get Guard listening to file changes.
My docker-compose.yml looks like this:
version: '3'
services:
postgres:
ports:
- "5432:5432"
volumes:
- $HOME/postgres-data:/var/lib/postgresql
image: postgres:9.6.9
redis:
ports:
- "6379:6379"
depends_on:
- postgres
image: redis:5.0-rc
web:
build: .
ports:
- "3000:3000"
command: /bin/sh -c "rails s -b 0.0.0.0 -p 3000"
depends_on:
- postgres
- redis
env_file:
- .env
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
depends_on:
- postgres
- redis
env_file:
- .env
volumes:
redis:
postgres:
sidekiq:
guard:
Guardfile
guard 'spring', bundler: true do
watch('Gemfile.lock')
watch(%r{^config/})
watch(%r{^spec/(support|factories)/})
watch(%r{^spec/factory.rb})
end
guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# RSpec files
rspec = dsl.rspec
watch(rspec.spec_files)
# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end
# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+).feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
ignore %r{^spec/support/concerns/}
end
guard 'brakeman', :run_on_start => true do
watch(%r{^app/.+.(erb|haml|rhtml|rb)$})
watch(%r{^config/.+.rb$})
watch(%r{^lib/.+.rb$})
watch('Gemfile')
end
ruby-on-rails docker guard
I am trying to "dockerize" an existing Rails development app. This is my first time experimenting with Docker.
I want to set up Guard to listen for file changes and run relevant specs.
The Guard service appears to be running correctly, and the logs show:
guard_1 | 16:35:12 - INFO - Guard is now watching at '/app'
But when I edit/save spec files Guard is not running any tests.
This is an existing app that I'm moving into Docker. It has a guardfile that works outside of Docker.
I've searched and read a number of posts (e.g. this one), but I'm not sure where to start debugging this. Can anyone point me in the right direction and get Guard listening to file changes.
My docker-compose.yml looks like this:
version: '3'
services:
postgres:
ports:
- "5432:5432"
volumes:
- $HOME/postgres-data:/var/lib/postgresql
image: postgres:9.6.9
redis:
ports:
- "6379:6379"
depends_on:
- postgres
image: redis:5.0-rc
web:
build: .
ports:
- "3000:3000"
command: /bin/sh -c "rails s -b 0.0.0.0 -p 3000"
depends_on:
- postgres
- redis
env_file:
- .env
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
depends_on:
- postgres
- redis
env_file:
- .env
volumes:
redis:
postgres:
sidekiq:
guard:
Guardfile
guard 'spring', bundler: true do
watch('Gemfile.lock')
watch(%r{^config/})
watch(%r{^spec/(support|factories)/})
watch(%r{^spec/factory.rb})
end
guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# RSpec files
rspec = dsl.rspec
watch(rspec.spec_files)
# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end
# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+).feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
ignore %r{^spec/support/concerns/}
end
guard 'brakeman', :run_on_start => true do
watch(%r{^app/.+.(erb|haml|rhtml|rb)$})
watch(%r{^config/.+.rb$})
watch(%r{^lib/.+.rb$})
watch('Gemfile')
end
ruby-on-rails docker guard
ruby-on-rails docker guard
edited Jan 5 at 13:01
Andy Harvey
asked Jan 3 at 17:10
Andy HarveyAndy Harvey
5,4051158136
5,4051158136
Can you post your Guardfile? And try addingtty: true
underneath yourguard
service? Also, have you tried running your guard command outside of docker to make sure it's configured correctly? I'd try and run it standalone to make sure it's seeing the changes to make sure you've configured it correctly, then move it into a container. Also, are you using minitest, or rspec?
– Jay Dorsey
Jan 4 at 2:40
Thanks @JayDorsey, I will add the guardfile above. I am using Rspec. If I runbundle exec guard
from the command prompt it runs correctly. I’m away from my dev computer just now, but will try running this from a docker bash prompt and report back. Same with thetty: true
config. Thanks!
– Andy Harvey
Jan 5 at 12:57
add a comment |
Can you post your Guardfile? And try addingtty: true
underneath yourguard
service? Also, have you tried running your guard command outside of docker to make sure it's configured correctly? I'd try and run it standalone to make sure it's seeing the changes to make sure you've configured it correctly, then move it into a container. Also, are you using minitest, or rspec?
– Jay Dorsey
Jan 4 at 2:40
Thanks @JayDorsey, I will add the guardfile above. I am using Rspec. If I runbundle exec guard
from the command prompt it runs correctly. I’m away from my dev computer just now, but will try running this from a docker bash prompt and report back. Same with thetty: true
config. Thanks!
– Andy Harvey
Jan 5 at 12:57
Can you post your Guardfile? And try adding
tty: true
underneath your guard
service? Also, have you tried running your guard command outside of docker to make sure it's configured correctly? I'd try and run it standalone to make sure it's seeing the changes to make sure you've configured it correctly, then move it into a container. Also, are you using minitest, or rspec?– Jay Dorsey
Jan 4 at 2:40
Can you post your Guardfile? And try adding
tty: true
underneath your guard
service? Also, have you tried running your guard command outside of docker to make sure it's configured correctly? I'd try and run it standalone to make sure it's seeing the changes to make sure you've configured it correctly, then move it into a container. Also, are you using minitest, or rspec?– Jay Dorsey
Jan 4 at 2:40
Thanks @JayDorsey, I will add the guardfile above. I am using Rspec. If I run
bundle exec guard
from the command prompt it runs correctly. I’m away from my dev computer just now, but will try running this from a docker bash prompt and report back. Same with the tty: true
config. Thanks!– Andy Harvey
Jan 5 at 12:57
Thanks @JayDorsey, I will add the guardfile above. I am using Rspec. If I run
bundle exec guard
from the command prompt it runs correctly. I’m away from my dev computer just now, but will try running this from a docker bash prompt and report back. Same with the tty: true
config. Thanks!– Andy Harvey
Jan 5 at 12:57
add a comment |
2 Answers
2
active
oldest
votes
I'm assuming you're making changes on your local filesystem and expected guard, inside the container, to trigger.
If so, the missing link is your docker-compose.yml
file.
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
volumes:
- .:/app
You need to mount the volume of your root (Rails root) directory inside the container so that the changes are reflected. Without this line, your container(s) only sees what was available at build time, and not the changes.
thanks @Jay, I think this is working. It's taking me a while to confirm this because: 1. Guard is veeerrryy slow to respond from within the Docker container, 2. none of my gems seem to be autoloading when Guard launches (e.g., NameError: uninitialized constant FactoryBot). Any idea why this might be?
– Andy Harvey
Jan 14 at 8:28
The slowness might be due to how Docker mounts the filesystem in Docker. It's the same on my system (macOS). This is an outstanding known issue. You can look at docker-sync.io. I haven't tested it, but it looks like it exists to combat this issue. Also can look at this: docs.docker.com/docker-for-mac/osxfs-caching Is the autoloading issue only present in your Guard container? Can you confirm it's not just an old(er) log file that's showing the factorybot error? I seem to recall the logs being persistent and showing errors from previous iterations
– Jay Dorsey
Jan 14 at 13:14
Given this slowness issue, do you (or people) actually use Docker in this way with file monitoring and tests? It is close to being unusable on my machine.
– Andy Harvey
Jan 15 at 4:39
The gem thing is odd. For example, I fixed the FactoryBot issue by addingrequire 'factory_bot'
to spec/support/factory_bot.rb. But then I started seeing the same error for whatever gem is called next. So the gems seem to be available, just not enabled. The app works perfectly in all other environments without needing torequire
gems. Not sure where to begin with this one!
– Andy Harvey
Jan 15 at 4:42
I don't use it for local Dev because of that issue. I've never tried the docker-sync to but I suspect it might be a viable solution. I have used it to speed up tests and deploys for pipelines that support Docker. The gem issue sounds weird. Did you try passing bundler: true in your Guardfile? I think you were running bundle exec guard, but I think there's another flag.
– Jay Dorsey
Jan 15 at 12:15
|
show 1 more comment
I faced the exact same problem and have been wondering about existing solutions that didn't really work. The key solution to your problem (if you are on OSX of course) is to understand the difference between "Docker Toolbox" and "Docker for Mac".
This article gives a lot of insight: https://docs.docker.com/docker-for-mac/docker-toolbox/
TL;DR
If you are on Mac, you need to use Docker for Mac to have the benefits of osxfs. If you do this you will not need docker-sync!
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026795%2fwhy-is-guard-not-detecting-file-changes-after-dockerizing-rails-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm assuming you're making changes on your local filesystem and expected guard, inside the container, to trigger.
If so, the missing link is your docker-compose.yml
file.
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
volumes:
- .:/app
You need to mount the volume of your root (Rails root) directory inside the container so that the changes are reflected. Without this line, your container(s) only sees what was available at build time, and not the changes.
thanks @Jay, I think this is working. It's taking me a while to confirm this because: 1. Guard is veeerrryy slow to respond from within the Docker container, 2. none of my gems seem to be autoloading when Guard launches (e.g., NameError: uninitialized constant FactoryBot). Any idea why this might be?
– Andy Harvey
Jan 14 at 8:28
The slowness might be due to how Docker mounts the filesystem in Docker. It's the same on my system (macOS). This is an outstanding known issue. You can look at docker-sync.io. I haven't tested it, but it looks like it exists to combat this issue. Also can look at this: docs.docker.com/docker-for-mac/osxfs-caching Is the autoloading issue only present in your Guard container? Can you confirm it's not just an old(er) log file that's showing the factorybot error? I seem to recall the logs being persistent and showing errors from previous iterations
– Jay Dorsey
Jan 14 at 13:14
Given this slowness issue, do you (or people) actually use Docker in this way with file monitoring and tests? It is close to being unusable on my machine.
– Andy Harvey
Jan 15 at 4:39
The gem thing is odd. For example, I fixed the FactoryBot issue by addingrequire 'factory_bot'
to spec/support/factory_bot.rb. But then I started seeing the same error for whatever gem is called next. So the gems seem to be available, just not enabled. The app works perfectly in all other environments without needing torequire
gems. Not sure where to begin with this one!
– Andy Harvey
Jan 15 at 4:42
I don't use it for local Dev because of that issue. I've never tried the docker-sync to but I suspect it might be a viable solution. I have used it to speed up tests and deploys for pipelines that support Docker. The gem issue sounds weird. Did you try passing bundler: true in your Guardfile? I think you were running bundle exec guard, but I think there's another flag.
– Jay Dorsey
Jan 15 at 12:15
|
show 1 more comment
I'm assuming you're making changes on your local filesystem and expected guard, inside the container, to trigger.
If so, the missing link is your docker-compose.yml
file.
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
volumes:
- .:/app
You need to mount the volume of your root (Rails root) directory inside the container so that the changes are reflected. Without this line, your container(s) only sees what was available at build time, and not the changes.
thanks @Jay, I think this is working. It's taking me a while to confirm this because: 1. Guard is veeerrryy slow to respond from within the Docker container, 2. none of my gems seem to be autoloading when Guard launches (e.g., NameError: uninitialized constant FactoryBot). Any idea why this might be?
– Andy Harvey
Jan 14 at 8:28
The slowness might be due to how Docker mounts the filesystem in Docker. It's the same on my system (macOS). This is an outstanding known issue. You can look at docker-sync.io. I haven't tested it, but it looks like it exists to combat this issue. Also can look at this: docs.docker.com/docker-for-mac/osxfs-caching Is the autoloading issue only present in your Guard container? Can you confirm it's not just an old(er) log file that's showing the factorybot error? I seem to recall the logs being persistent and showing errors from previous iterations
– Jay Dorsey
Jan 14 at 13:14
Given this slowness issue, do you (or people) actually use Docker in this way with file monitoring and tests? It is close to being unusable on my machine.
– Andy Harvey
Jan 15 at 4:39
The gem thing is odd. For example, I fixed the FactoryBot issue by addingrequire 'factory_bot'
to spec/support/factory_bot.rb. But then I started seeing the same error for whatever gem is called next. So the gems seem to be available, just not enabled. The app works perfectly in all other environments without needing torequire
gems. Not sure where to begin with this one!
– Andy Harvey
Jan 15 at 4:42
I don't use it for local Dev because of that issue. I've never tried the docker-sync to but I suspect it might be a viable solution. I have used it to speed up tests and deploys for pipelines that support Docker. The gem issue sounds weird. Did you try passing bundler: true in your Guardfile? I think you were running bundle exec guard, but I think there's another flag.
– Jay Dorsey
Jan 15 at 12:15
|
show 1 more comment
I'm assuming you're making changes on your local filesystem and expected guard, inside the container, to trigger.
If so, the missing link is your docker-compose.yml
file.
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
volumes:
- .:/app
You need to mount the volume of your root (Rails root) directory inside the container so that the changes are reflected. Without this line, your container(s) only sees what was available at build time, and not the changes.
I'm assuming you're making changes on your local filesystem and expected guard, inside the container, to trigger.
If so, the missing link is your docker-compose.yml
file.
guard:
build: .
env_file:
- .env
command: bundle exec guard --no-bundler-warning --no-interactions
volumes:
- .:/app
You need to mount the volume of your root (Rails root) directory inside the container so that the changes are reflected. Without this line, your container(s) only sees what was available at build time, and not the changes.
answered Jan 6 at 1:38
Jay DorseyJay Dorsey
1,93511115
1,93511115
thanks @Jay, I think this is working. It's taking me a while to confirm this because: 1. Guard is veeerrryy slow to respond from within the Docker container, 2. none of my gems seem to be autoloading when Guard launches (e.g., NameError: uninitialized constant FactoryBot). Any idea why this might be?
– Andy Harvey
Jan 14 at 8:28
The slowness might be due to how Docker mounts the filesystem in Docker. It's the same on my system (macOS). This is an outstanding known issue. You can look at docker-sync.io. I haven't tested it, but it looks like it exists to combat this issue. Also can look at this: docs.docker.com/docker-for-mac/osxfs-caching Is the autoloading issue only present in your Guard container? Can you confirm it's not just an old(er) log file that's showing the factorybot error? I seem to recall the logs being persistent and showing errors from previous iterations
– Jay Dorsey
Jan 14 at 13:14
Given this slowness issue, do you (or people) actually use Docker in this way with file monitoring and tests? It is close to being unusable on my machine.
– Andy Harvey
Jan 15 at 4:39
The gem thing is odd. For example, I fixed the FactoryBot issue by addingrequire 'factory_bot'
to spec/support/factory_bot.rb. But then I started seeing the same error for whatever gem is called next. So the gems seem to be available, just not enabled. The app works perfectly in all other environments without needing torequire
gems. Not sure where to begin with this one!
– Andy Harvey
Jan 15 at 4:42
I don't use it for local Dev because of that issue. I've never tried the docker-sync to but I suspect it might be a viable solution. I have used it to speed up tests and deploys for pipelines that support Docker. The gem issue sounds weird. Did you try passing bundler: true in your Guardfile? I think you were running bundle exec guard, but I think there's another flag.
– Jay Dorsey
Jan 15 at 12:15
|
show 1 more comment
thanks @Jay, I think this is working. It's taking me a while to confirm this because: 1. Guard is veeerrryy slow to respond from within the Docker container, 2. none of my gems seem to be autoloading when Guard launches (e.g., NameError: uninitialized constant FactoryBot). Any idea why this might be?
– Andy Harvey
Jan 14 at 8:28
The slowness might be due to how Docker mounts the filesystem in Docker. It's the same on my system (macOS). This is an outstanding known issue. You can look at docker-sync.io. I haven't tested it, but it looks like it exists to combat this issue. Also can look at this: docs.docker.com/docker-for-mac/osxfs-caching Is the autoloading issue only present in your Guard container? Can you confirm it's not just an old(er) log file that's showing the factorybot error? I seem to recall the logs being persistent and showing errors from previous iterations
– Jay Dorsey
Jan 14 at 13:14
Given this slowness issue, do you (or people) actually use Docker in this way with file monitoring and tests? It is close to being unusable on my machine.
– Andy Harvey
Jan 15 at 4:39
The gem thing is odd. For example, I fixed the FactoryBot issue by addingrequire 'factory_bot'
to spec/support/factory_bot.rb. But then I started seeing the same error for whatever gem is called next. So the gems seem to be available, just not enabled. The app works perfectly in all other environments without needing torequire
gems. Not sure where to begin with this one!
– Andy Harvey
Jan 15 at 4:42
I don't use it for local Dev because of that issue. I've never tried the docker-sync to but I suspect it might be a viable solution. I have used it to speed up tests and deploys for pipelines that support Docker. The gem issue sounds weird. Did you try passing bundler: true in your Guardfile? I think you were running bundle exec guard, but I think there's another flag.
– Jay Dorsey
Jan 15 at 12:15
thanks @Jay, I think this is working. It's taking me a while to confirm this because: 1. Guard is veeerrryy slow to respond from within the Docker container, 2. none of my gems seem to be autoloading when Guard launches (e.g., NameError: uninitialized constant FactoryBot). Any idea why this might be?
– Andy Harvey
Jan 14 at 8:28
thanks @Jay, I think this is working. It's taking me a while to confirm this because: 1. Guard is veeerrryy slow to respond from within the Docker container, 2. none of my gems seem to be autoloading when Guard launches (e.g., NameError: uninitialized constant FactoryBot). Any idea why this might be?
– Andy Harvey
Jan 14 at 8:28
The slowness might be due to how Docker mounts the filesystem in Docker. It's the same on my system (macOS). This is an outstanding known issue. You can look at docker-sync.io. I haven't tested it, but it looks like it exists to combat this issue. Also can look at this: docs.docker.com/docker-for-mac/osxfs-caching Is the autoloading issue only present in your Guard container? Can you confirm it's not just an old(er) log file that's showing the factorybot error? I seem to recall the logs being persistent and showing errors from previous iterations
– Jay Dorsey
Jan 14 at 13:14
The slowness might be due to how Docker mounts the filesystem in Docker. It's the same on my system (macOS). This is an outstanding known issue. You can look at docker-sync.io. I haven't tested it, but it looks like it exists to combat this issue. Also can look at this: docs.docker.com/docker-for-mac/osxfs-caching Is the autoloading issue only present in your Guard container? Can you confirm it's not just an old(er) log file that's showing the factorybot error? I seem to recall the logs being persistent and showing errors from previous iterations
– Jay Dorsey
Jan 14 at 13:14
Given this slowness issue, do you (or people) actually use Docker in this way with file monitoring and tests? It is close to being unusable on my machine.
– Andy Harvey
Jan 15 at 4:39
Given this slowness issue, do you (or people) actually use Docker in this way with file monitoring and tests? It is close to being unusable on my machine.
– Andy Harvey
Jan 15 at 4:39
The gem thing is odd. For example, I fixed the FactoryBot issue by adding
require 'factory_bot'
to spec/support/factory_bot.rb. But then I started seeing the same error for whatever gem is called next. So the gems seem to be available, just not enabled. The app works perfectly in all other environments without needing to require
gems. Not sure where to begin with this one!– Andy Harvey
Jan 15 at 4:42
The gem thing is odd. For example, I fixed the FactoryBot issue by adding
require 'factory_bot'
to spec/support/factory_bot.rb. But then I started seeing the same error for whatever gem is called next. So the gems seem to be available, just not enabled. The app works perfectly in all other environments without needing to require
gems. Not sure where to begin with this one!– Andy Harvey
Jan 15 at 4:42
I don't use it for local Dev because of that issue. I've never tried the docker-sync to but I suspect it might be a viable solution. I have used it to speed up tests and deploys for pipelines that support Docker. The gem issue sounds weird. Did you try passing bundler: true in your Guardfile? I think you were running bundle exec guard, but I think there's another flag.
– Jay Dorsey
Jan 15 at 12:15
I don't use it for local Dev because of that issue. I've never tried the docker-sync to but I suspect it might be a viable solution. I have used it to speed up tests and deploys for pipelines that support Docker. The gem issue sounds weird. Did you try passing bundler: true in your Guardfile? I think you were running bundle exec guard, but I think there's another flag.
– Jay Dorsey
Jan 15 at 12:15
|
show 1 more comment
I faced the exact same problem and have been wondering about existing solutions that didn't really work. The key solution to your problem (if you are on OSX of course) is to understand the difference between "Docker Toolbox" and "Docker for Mac".
This article gives a lot of insight: https://docs.docker.com/docker-for-mac/docker-toolbox/
TL;DR
If you are on Mac, you need to use Docker for Mac to have the benefits of osxfs. If you do this you will not need docker-sync!
add a comment |
I faced the exact same problem and have been wondering about existing solutions that didn't really work. The key solution to your problem (if you are on OSX of course) is to understand the difference between "Docker Toolbox" and "Docker for Mac".
This article gives a lot of insight: https://docs.docker.com/docker-for-mac/docker-toolbox/
TL;DR
If you are on Mac, you need to use Docker for Mac to have the benefits of osxfs. If you do this you will not need docker-sync!
add a comment |
I faced the exact same problem and have been wondering about existing solutions that didn't really work. The key solution to your problem (if you are on OSX of course) is to understand the difference between "Docker Toolbox" and "Docker for Mac".
This article gives a lot of insight: https://docs.docker.com/docker-for-mac/docker-toolbox/
TL;DR
If you are on Mac, you need to use Docker for Mac to have the benefits of osxfs. If you do this you will not need docker-sync!
I faced the exact same problem and have been wondering about existing solutions that didn't really work. The key solution to your problem (if you are on OSX of course) is to understand the difference between "Docker Toolbox" and "Docker for Mac".
This article gives a lot of insight: https://docs.docker.com/docker-for-mac/docker-toolbox/
TL;DR
If you are on Mac, you need to use Docker for Mac to have the benefits of osxfs. If you do this you will not need docker-sync!
edited Jan 15 at 12:45
answered Jan 15 at 9:02
bastianweggebastianwegge
2,00111524
2,00111524
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026795%2fwhy-is-guard-not-detecting-file-changes-after-dockerizing-rails-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you post your Guardfile? And try adding
tty: true
underneath yourguard
service? Also, have you tried running your guard command outside of docker to make sure it's configured correctly? I'd try and run it standalone to make sure it's seeing the changes to make sure you've configured it correctly, then move it into a container. Also, are you using minitest, or rspec?– Jay Dorsey
Jan 4 at 2:40
Thanks @JayDorsey, I will add the guardfile above. I am using Rspec. If I run
bundle exec guard
from the command prompt it runs correctly. I’m away from my dev computer just now, but will try running this from a docker bash prompt and report back. Same with thetty: true
config. Thanks!– Andy Harvey
Jan 5 at 12:57