Sha256: 0ba37a92c344eb608e9a08a7ad1aa54842d6b13f4df8288fcb3d578bf5f65d5f

Contents?: true

Size: 1.61 KB

Versions: 31

Compression:

Stored size: 1.61 KB

Contents

module Docker
  def self.run(image,cmd, options)
    mounts, job_inputs, directory, pipe = Misc.process_options options, :mounts, :job_inputs, :directory, :pipe

    if mounts
      mount_cmd = mounts.sort.collect{|t,s| "-v " + ["'" + s + "'", "'" + t + "'"] * ":" } * " "
    else
      mount_cmd = ""
    end

    image_cmd = "-t #{image}"

    if directory
      Path.setup(directory) unless Path === directory
      FileUtils.mkdir_p directory unless File.directory? directory
      mount_cmd += " -v '#{directory}':/job"
      job_inputs.each do |name,obj|
        case obj
        when File 
          FileUtils.cp obj.filename, directory[name]
        when IO
          Open.write(tmpfile[name], obj)
        when String
          if obj.length < 256 and File.exists?(obj)
            FileUtils.cp obj, directory[name]
          else
            Open.write(directory[name], obj)
          end
        end
      end
    else
      TmpFile.with_file do |tmpfile|
        Path.setup(tmpfile)
        FileUtils.mkdir_p tmpfile
        mount_cmd += " -v '#{tmpfile}':/job"
        job_inputs.each do |name,obj|
          case obj
          when File 
            FileUtils.cp obj.filename, tmpfile[name]
          when IO
            Open.write(tmpfile[name], obj)
          when String
            if obj.length < 256 and File.exists?(obj)
              FileUtils.cp obj, tmpfile[name]
            else
              Open.write(tmpfile[name], obj)
            end
          end
        end
        pipe = false
      end

    end
    cmd = "docker run #{mount_cmd} #{image_cmd} #{cmd}"
    CMD.cmd(cmd, :log => true, :pipe => pipe)
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
rbbt-util-5.19.16 lib/rbbt/util/docker.rb
rbbt-util-5.19.15 lib/rbbt/util/docker.rb
rbbt-util-5.19.14 lib/rbbt/util/docker.rb
rbbt-util-5.19.13 lib/rbbt/util/docker.rb
rbbt-util-5.19.12 lib/rbbt/util/docker.rb
rbbt-util-5.19.11 lib/rbbt/util/docker.rb
rbbt-util-5.19.10 lib/rbbt/util/docker.rb
rbbt-util-5.19.9 lib/rbbt/util/docker.rb
rbbt-util-5.19.8 lib/rbbt/util/docker.rb
rbbt-util-5.19.7 lib/rbbt/util/docker.rb
rbbt-util-5.19.6 lib/rbbt/util/docker.rb
rbbt-util-5.19.5 lib/rbbt/util/docker.rb
rbbt-util-5.19.4 lib/rbbt/util/docker.rb
rbbt-util-5.19.3 lib/rbbt/util/docker.rb
rbbt-util-5.19.2 lib/rbbt/util/docker.rb
rbbt-util-5.19.1 lib/rbbt/util/docker.rb
rbbt-util-5.19.0 lib/rbbt/util/docker.rb
rbbt-util-5.18.1 lib/rbbt/util/docker.rb
rbbt-util-5.18.0 lib/rbbt/util/docker.rb
rbbt-util-5.17.89 lib/rbbt/util/docker.rb