Skip to content

Instantly share code, notes, and snippets.

@brendanstennett
Created April 30, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brendanstennett/aad056f077c5b70880e7 to your computer and use it in GitHub Desktop.
Save brendanstennett/aad056f077c5b70880e7 to your computer and use it in GitHub Desktop.
Docker+Fig+Guard
#!/bin/bash
trap "kill 0" SIGINT SIGTERM EXIT
listen -f 0.0.0.0:4000 &
docker exec -it myproject_web_1 bundle exec guard -o 10.0.2.2:4000
guard :rspec, cmd: 'rspec' do
watch(%r{spec/(.+)_spec.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{lib/(.+).rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
watch(%r{app/(.+).rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{app/(.*)(.erb|.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{app/controllers/(.+)_(controller).rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{spec/support/(.+).rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
end
@brendanstennett
Copy link
Author

Basically, I put the file guard in bin/ and we start it with ./bin/guard. It sends the file changes over the network and guard listens to it. 10.0.2.2 is the host ip (your mac) when running boot2docker.

The trap command will kill both of these commands when Ctrl+C is used or guard exits after typing exit into the prompt.

@thecatwasnot
Copy link

@HuffMoody Thanks for the update and pointers, I'm a lot closer than I was, and after some fiddling I thought I got it, it stopped complaining about not making a connection but no events seemed to arrive. How did you get the IP for the guard command? I'm not using boot2docker, but a CoreOS vagrant instance.

@thecatwasnot
Copy link

I got the host IP figured out (umm, not enough coffee that day I guess).

For newer versions of guard/listen you need to also pass -r on the listen command. And unfortunately in listen 2.10.0 I'm getting an error, which appears to be fixed on guard/listen master.
Here's what I ended up with: https://gist.github.com/thecatwasnot/9dde2e100ccad19660cf
Ubuntu 14.04 -> Vagrant(CoreOS) -> docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment