docker run , guard is outside :issue . idea ?

Skip to first unread message


Jul 15, 2017, 4:40:32 AM7/15/17
to guard-dev
the problem :
I am setting the test running in a container , and I have set up guard OUTSIDE ( on my Mac) , triggering the test inside the container.( to avoid the polling issue) 

the details :
but the rspec command passes some arguments to the "command" that are base on the assumption of the the Mac, which are false inside

 the command is : rspec -f documentation -r /Users/luc_taesch/.rvm/gems/ruby-2.4.0/gems/guard-rspec-4.7.3/lib/guard/rspec_formatter.rb -f Guard::RSpecFormatter --failure-exit-code 2 spec/guard_template_spec.rb

of course : this is failing inside the container : -r /Users/luc_taesch/.rvm/gems/ruby-2.4.0/gems/guard-rspec-4.7.3/lib/guard/rspec_formatter.rb

where it should be :  /usr/local/rvm/gems/ruby-2.4.0/gems/guard-rspec-4.7.3/lib/guard/rspec_formatter.rb

-f documentation -r /usr/local/rvm/gems/ruby-2.4.0/gems/guard-rspec-4.7.3/lib/guard/rspec_formatter.rb -f Guard::RSpecFormatter --failure-exit-code 2 spec/guard_template_spec.rb


- is there a way to fix the -r ( runner ?) option. an argument to differ it to an evaluation inside the container ( lazy) .
- have this pb already been seen before ?

i am thinking other wise to watch the files externally, and trigger an internal guard "manually" from "outside". any way to do that? 


other wise :

what is the best option to run guard : inside or outside docker ?

( thanks for the -d options that helped me understand this : bundle exec guard -d)

guard file :

# A sample Guardfile
# More info at

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'
require 'open3'

def run_distant_spec
#'cd docker; docker-compose up -d kairo-test; docker exec -t kairot /project/scripts/;exit'
# -f html -o ./tmp/spec_results.html', launchy: './tmp/spec_results.html'
#, launchy: './tmp/spec_results.html'
# these are for distant rspec start ( docker), not local
guard :rspec, cmd: run_distant_spec do
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }


# these are for local rspec start , not distant ( docker)
guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl =

# Feel free to open issues for suggestions and improvements

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }

# Ruby files
ruby = dsl.ruby

# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))

watch(rails.controllers) do |m|

# 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|"features/#{m[1]}") }
watch(rails.layouts) { |m|"features/#{m[1]}") }

# Turnip features and steps
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"

# Add files and commands to this file, like the example:
# watch(%r{file/path}) { `command(s)` }
guard :shell do

watch(/(.*)docker-compose.yaml/) {|m| p m; docker_actions }
watch(/(.*)Dockerfile/) {|m| docker_actions }
watch(/(.*)scripts/) {|m| docker_actions }


notification :terminal_notifier, app_name:'guard_template ::' if `uname` =~ /Darwin/

#, activate: 'com.googlecode.iterm2'

# these are for local rspec start , not distant ( docker)
guard :bundler do
require 'guard/bundler'
require 'guard/bundler/verify'
helper =

files = ['Gemfile']
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }

# Assume files are symlinked from somewhere
files.each { |file| watch(helper.real_path(file)) }

def docker_actions
p '------\n'
`cd docker; docker-compose stop kairo-test;`
`cd docker; docker rmi kairo-test;`
`cd docker; docker-compose build kairo-test;`
p 'running \n'
stdin, stdout, stderr = Open3.popen3(
'cd docker; docker-compose up -d kairo-test'
p 'stdout',stdout.readlines
p 'stderr',stderr.readlines
p "\ndocker done !"
Reply all
Reply to author
0 new messages