Skip to content

Commit 8566b62

Browse files
tochhone
authored andcommitted
By default, rake task has to be run in-docker
* abort the task if not run in-docker * env var MRUBY_CLI_LOCAL allows to run the rake task locally * local task can be added * refactoring of the check is-in-a-docker-container?
1 parent b489932 commit 8566b62

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

Rakefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,31 @@ task :release => :compile do
107107
end
108108
end
109109
end
110+
111+
namespace :local do
112+
desc "show help"
113+
task :version do
114+
require_relative 'mrblib/mruby-cli/version'
115+
puts "mruby-cli #{MRubyCLI::Version::VERSION}"
116+
end
117+
end
118+
119+
def is_in_a_docker_container?
120+
`grep -q docker /proc/self/cgroup`
121+
$?.success?
122+
end
123+
124+
Rake.application.tasks.each do |task|
125+
next if ENV["MRUBY_CLI_LOCAL"]
126+
unless task.name.start_with?("local:")
127+
# Inspired by rake-hooks
128+
# https://github.com/guillermo/rake-hooks
129+
old_task = Rake.application.instance_variable_get('@tasks').delete(task.name)
130+
desc old_task.full_comment
131+
task old_task.name => old_task.prerequisites do
132+
abort("Not running in docker, you should type \"docker-compose run <task>\".") \
133+
unless is_in_a_docker_container?
134+
old_task.invoke
135+
end
136+
end
137+
end

mrblib/mruby-cli/setup.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,34 @@ def clean_env(envs)
382382
task :clean do
383383
sh "rake deep_clean"
384384
end
385+
386+
namespace :local do
387+
desc "show help"
388+
task :version do
389+
require_relative 'mrblib/mruby-cli/version'
390+
puts "mruby-cli \#{MRubyCLI::Version::VERSION}"
391+
end
392+
end
393+
394+
def is_in_a_docker_container?
395+
`grep -q docker /proc/self/cgroup`
396+
$?.success?
397+
end
398+
399+
Rake.application.tasks.each do |task|
400+
next if ENV["MRUBY_CLI_LOCAL"]
401+
unless task.name.start_with?("local:")
402+
# Inspired by rake-hooks
403+
# https://github.com/guillermo/rake-hooks
404+
old_task = Rake.application.instance_variable_get('@tasks').delete(task.name)
405+
desc old_task.full_comment
406+
task old_task.name => old_task.prerequisites do
407+
abort("Not running in docker, you should type \\"docker-compose run <task>\\".") \
408+
unless is_in_a_docker_container?
409+
old_task.invoke
410+
end
411+
end
412+
end
385413
RAKEFILE
386414
end
387415
end

0 commit comments

Comments
 (0)