Module: RakeCompilerDock
- Defined in:
- lib/rake_compiler_dock.rb,
lib/rake_compiler_dock/version.rb
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
-
.exec(*args) ⇒ Object
Run the command cmd within a fresh rake-compiler-dock container.
- .image_name ⇒ Object
-
.sh(cmd, &block) ⇒ Object
Run the command cmd within a fresh rake-compiler-dock container and within a shell.
Class Method Details
.exec(*args) ⇒ Object
Run the command cmd within a fresh rake-compiler-dock container. The command is run directly, without the shell.
If a block is given, upon command completion the block is called with an OK flag (true on a zero exit status) and a Process::Status object. Without a block a RuntimeError is raised when the command exits non-zero.
Examples:
RakeCompilerDock.exec 'bash', '-c', 'echo $RUBY_CC_VERSION'
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rake_compiler_dock.rb', line 36 def exec(*args) if RUBY_PLATFORM =~ /mingw|mswin/ # Change Path from "C:\Path" to "/c/Path" as used by boot2docker pwd = Dir.pwd.gsub(/^([a-z]):/i){ "/#{$1.downcase}" } uid = 1000 gid = 1000 else pwd = Dir.pwd uid = Process.uid gid = Process.gid end user = `id -nu`.chomp group = `id -ng`.chomp cmd = ["docker", "run", "--rm", "-i", "-t", "-v", "#{pwd}:#{pwd}", "-e", "UID=#{uid}", "-e", "GID=#{gid}", "-e", "USER=#{user}", "-e", "GROUP=#{group}", "-e", "ftp_proxy=#{ENV['ftp_proxy']}", "-e", "http_proxy=#{ENV['http_proxy']}", "-e", "https_proxy=#{ENV['https_proxy']}", "-w", pwd, image_name, "sigfw", "runas", *args] ok = system(*cmd) if block_given? yield(ok, $?) elsif !ok show_command = cmd.join(" ") fail "Command failed with status (#{$?.exitstatus}): " + "[#{show_command}]" end end |
.image_name ⇒ Object
23 24 25 |
# File 'lib/rake_compiler_dock.rb', line 23 def image_name ENV['RAKE_COMPILER_DOCK_IMAGE'] || "larskanis/rake-compiler-dock:#{VERSION}" end |
.sh(cmd, &block) ⇒ Object
Run the command cmd within a fresh rake-compiler-dock container and within a shell.
If a block is given, upon command completion the block is called with an OK flag (true on a zero exit status) and a Process::Status object. Without a block a RuntimeError is raised when the command exits non-zero.
Examples:
RakeCompilerDock.sh 'bundle && rake cross native gem'
# check exit status after command runs
sh %{bundle && rake cross native gem} do |ok, res|
if ! ok
puts "windows cross build failed (status = #{res.exitstatus})"
end
end
19 20 21 |
# File 'lib/rake_compiler_dock.rb', line 19 def sh(cmd, &block) exec('bash', '-c', cmd, &block) end |