docker run , guard is outside :issue . idea ?

28 views
Skip to first unread message

Luc TAESCH

unread,
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

fixes:
-------

- 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 https://github.com/guard/guard#readme

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



=begin

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

# 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 }
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
end
=end

# 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 }

end



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 = Guard::Bundler::Verify.new

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)) }
end

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 !"
end
Reply all
Reply to author
Forward
0 new messages