Skip to content

Commit

Permalink
Better check of is-in-a-docker-container?
Browse files Browse the repository at this point in the history
Allow to add local task
  • Loading branch information
toch committed Oct 11, 2015
1 parent 694e00e commit 79b4a5e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
37 changes: 28 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
def is_in_a_docker_container?
`grep -q docker /proc/self/cgroup`
$?.success?
end

if !ENV["RUN_RAKE_TASK_LOCALLY"] && !is_in_a_docker_container?
abort("Not running in docker, you should type \"docker-compose run <task>\".")
end

file :mruby do
sh "git clone --depth=1 https://github.com/mruby/mruby"
end
Expand Down Expand Up @@ -111,3 +102,31 @@ task :release => :compile do
end
end
end

namespace :local do
desc "show help"
task :version do
require_relative 'mrblib/mruby-cli/version'
puts "mruby-cli #{MRubyCLI::Version::VERSION}"
end
end

def is_in_a_docker_container?
`grep -q docker /proc/self/cgroup`
$?.success?
end

Rake.application.tasks.each do |task|
next if ENV["RUN_RAKE_TASK_LOCALLY"]
unless task.name.start_with?("local:")
# Inspired by rake-hooks
# https://github.com/guillermo/rake-hooks
old_task = Rake.application.instance_variable_get('@tasks').delete(task.name)
desc old_task.full_comment
task old_task.name => old_task.prerequisites do
abort("Not running in docker, you should type \"docker-compose run <task>\".") \
unless is_in_a_docker_container?
old_task.invoke
end
end
end
37 changes: 28 additions & 9 deletions mrblib/mruby-cli/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,6 @@ def docker_compose_yml

def rakefile
<<RAKEFILE
def is_in_a_docker_container?
`grep -q docker /proc/self/cgroup`
$?.success?
end
if !ENV["RUN_RAKE_TASK_LOCALLY"] && !is_in_a_docker_container?
abort("Not running in docker, you should type \\"docker-compose run <task>\\".")
end
file :mruby do
sh "git clone --depth=1 https://github.com/mruby/mruby"
end
Expand Down Expand Up @@ -391,6 +382,34 @@ def clean_env(envs)
task :clean do
sh "rake deep_clean"
end
namespace :local do
desc "show help"
task :version do
require_relative 'mrblib/mruby-cli/version'
puts "mruby-cli \#{MRubyCLI::Version::VERSION}"
end
end
def is_in_a_docker_container?
`grep -q docker /proc/self/cgroup`
$?.success?
end
Rake.application.tasks.each do |task|
next if ENV["RUN_RAKE_TASK_LOCALLY"]
unless task.name.start_with?("local:")
# Inspired by rake-hooks
# https://github.com/guillermo/rake-hooks
old_task = Rake.application.instance_variable_get('@tasks').delete(task.name)
desc old_task.full_comment
task old_task.name => old_task.prerequisites do
abort("Not running in docker, you should type \\"docker-compose run <task>\\".") \
unless is_in_a_docker_container?
old_task.invoke
end
end
end
RAKEFILE
end
end
Expand Down

0 comments on commit 79b4a5e

Please sign in to comment.