Class: Train::Transports::Podman::Connection

Inherits:
BaseConnection
  • Object
show all
Defined in:
lib/train/transports/podman.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/train/transports/podman.rb', line 56

def initialize(options)
  super(options)

  @id = options[:host]

  if RUBY_PLATFORM =~ /windows|mswin|msys|mingw|cygwin/
    raise "Unsupported host platform."
  end

  # Currently Podman url can be set using option and setting the environment variable.
  uid = Process.uid
  podman_url = options[:podman_url] || ENV["CONTAINER_HOST"]
  podman_url ||= "unix:///run/podman/podman.sock" if uid == 0
  podman_url ||= "unix:///run/user/#{uid}/podman/podman.sock"

  Docker.url = podman_url

  # Using docker-api ruby library to fetch the Podman container data.
  @container = ::Docker::Container.get(@id) ||
    raise("Can't find Podman container #{@id}")
  @cmd_wrapper = nil
  @cmd_wrapper = CommandWrapper.load(self, @options)
  @probably_windows = nil
rescue Excon::Error::Socket
  raise Train::TransportError, "Unable to connect to Podman using #{podman_url}"
rescue Docker::Error::NotFoundError => e
  raise Train::TransportError, "Container Not Found: #{e.message}"
rescue Docker::Error::ServerError => e
  raise Train::TransportError, "#{e.message}"
end

Instance Method Details

#closeObject



87
88
89
# File 'lib/train/transports/podman.rb', line 87

def close
  # nothing to do at the moment
end

#unique_identifierObject



99
100
101
# File 'lib/train/transports/podman.rb', line 99

def unique_identifier
  @container.nil? ? @id : @container.id # default uuid set to the podman host.
end

#uriObject



91
92
93
94
95
96
97
# File 'lib/train/transports/podman.rb', line 91

def uri
  if @container.nil?
    "podman://#{@id}"
  else
    "podman://#{@container.id}"
  end
end