File: dockercli.rb

package info (click to toggle)
ruby-specinfra 2.89.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 2,412 kB
  • sloc: ruby: 10,338; sh: 4; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 865 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Specinfra
  module Backend
    # Docker command line transport
    class Dockercli < Exec
      def build_command(cmd)
        docker_cmd = %w[docker exec]
        docker_cmd << '--interactive' if get_config(:interactive_shell)
        docker_cmd << '--tty' if get_config(:request_pty)
        docker_cmd << instance
        (docker_cmd << super(cmd)).join(' ')
      end

      def send_file(from, to)
        to = Pathname.new(to).dirname.to_s if File.directory?(from)
        cmd = %W[docker cp #{from} #{instance}:#{to}]
        spawn_command(cmd.join(' '))
      end

      def send_directory(from, to)
        send_file(from, to)
      end

      private

      def instance
        raise 'Please specify docker_container' unless (container = get_config(:docker_container))

        container
      end
    end
  end
end