Class: DockerEngineRuby::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/docker_engine_ruby/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0
DEFAULT_TLS_VERIFY_PEER =

Whether to verify server TLS certificate chain.

true
ENVIRONMENTS =

rubocop:disable Style/MutableConstant

{production: "http://localhost:2375", production_tls: "https://localhost:2376"}

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS, Internal::Transport::BaseClient::REDIRECT_STATUSES

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, redirect_status?, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(tls_ca_cert_path: ENV["DOCKER_TLS_CA_CERT_PATH"], tls_client_cert_path: ENV["DOCKER_TLS_CLIENT_CERT_PATH"], tls_client_key_path: ENV["DOCKER_TLS_CLIENT_KEY_PATH"], environment: nil, base_url: ENV["DOCKER_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, tls_verify_peer: self.class::DEFAULT_TLS_VERIFY_PEER) ⇒ Client

Creates and returns a new client for interacting with the API.

certificate. Defaults to ‘ENV`

ENV`

ENV`

Each environment maps to a different base URL:

  • production corresponds to http://localhost:2375

  • production_tls corresponds to https://localhost:2376

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • tls_ca_cert_path (String, nil) (defaults to: ENV["DOCKER_TLS_CA_CERT_PATH"])

    Path to the trusted CA certificate file (PEM) used to verify the Docker daemon

  • tls_client_cert_path (String, nil) (defaults to: ENV["DOCKER_TLS_CLIENT_CERT_PATH"])

    Path to the client TLS certificate file (PEM). Defaults to

  • tls_client_key_path (String, nil) (defaults to: ENV["DOCKER_TLS_CLIENT_KEY_PATH"])

    Path to the client TLS private key file (PEM). Defaults to

  • environment (:production, :production_tls, nil) (defaults to: nil)

    Specifies the environment to use for the API.

  • base_url (String, nil) (defaults to: ENV["DOCKER_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)
  • tls_verify_peer (Boolean) (defaults to: self.class::DEFAULT_TLS_VERIFY_PEER)

    Whether to verify server TLS certificate chain.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/docker_engine_ruby/client.rb', line 114

def initialize(
  tls_ca_cert_path: ENV["DOCKER_TLS_CA_CERT_PATH"],
  tls_client_cert_path: ENV["DOCKER_TLS_CLIENT_CERT_PATH"],
  tls_client_key_path: ENV["DOCKER_TLS_CLIENT_KEY_PATH"],
  environment: nil,
  base_url: ENV["DOCKER_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY,
  tls_verify_peer: self.class::DEFAULT_TLS_VERIFY_PEER
)
  base_url ||= DockerEngineRuby::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do
    message = "environment must be one of " \
              "#{DockerEngineRuby::Client::ENVIRONMENTS.keys}, got #{environment}"
    raise ArgumentError.new(message)
  end

  @tls_ca_cert_path = tls_ca_cert_path&.to_s
  @tls_client_cert_path = tls_client_cert_path&.to_s
  @tls_client_key_path = tls_client_key_path&.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay,
    tls_verify_peer: tls_verify_peer,
    tls_ca_cert_path: @tls_ca_cert_path,
    tls_client_cert_path: @tls_client_cert_path,
    tls_client_key_path: @tls_client_key_path
  )

  @auth = DockerEngineRuby::Resources::Auth.new(client: self)
  @system_ = DockerEngineRuby::Resources::System.new(client: self)
  @containers = DockerEngineRuby::Resources::Containers.new(client: self)
  @exec_ = DockerEngineRuby::Resources::Exec.new(client: self)
  @images = DockerEngineRuby::Resources::Images.new(client: self)
  @networks = DockerEngineRuby::Resources::Networks.new(client: self)
  @volumes = DockerEngineRuby::Resources::Volumes.new(client: self)
  @services = DockerEngineRuby::Resources::Services.new(client: self)
  @configs = DockerEngineRuby::Resources::Configs.new(client: self)
  @secrets = DockerEngineRuby::Resources::Secrets.new(client: self)
  @nodes = DockerEngineRuby::Resources::Nodes.new(client: self)
  @swarm = DockerEngineRuby::Resources::Swarm.new(client: self)
  @tasks = DockerEngineRuby::Resources::Tasks.new(client: self)
  @plugins = DockerEngineRuby::Resources::Plugins.new(client: self)
  @distribution = DockerEngineRuby::Resources::Distribution.new(client: self)
end

Instance Attribute Details

#authDockerEngineRuby::Resources::Auth (readonly)



40
41
42
# File 'lib/docker_engine_ruby/client.rb', line 40

def auth
  @auth
end

#configsDockerEngineRuby::Resources::Configs (readonly)



64
65
66
# File 'lib/docker_engine_ruby/client.rb', line 64

def configs
  @configs
end

#containersDockerEngineRuby::Resources::Containers (readonly)



46
47
48
# File 'lib/docker_engine_ruby/client.rb', line 46

def containers
  @containers
end

#distributionDockerEngineRuby::Resources::Distribution (readonly)



82
83
84
# File 'lib/docker_engine_ruby/client.rb', line 82

def distribution
  @distribution
end

#exec_DockerEngineRuby::Resources::Exec (readonly)



49
50
51
# File 'lib/docker_engine_ruby/client.rb', line 49

def exec_
  @exec_
end

#imagesDockerEngineRuby::Resources::Images (readonly)



52
53
54
# File 'lib/docker_engine_ruby/client.rb', line 52

def images
  @images
end

#networksDockerEngineRuby::Resources::Networks (readonly)



55
56
57
# File 'lib/docker_engine_ruby/client.rb', line 55

def networks
  @networks
end

#nodesDockerEngineRuby::Resources::Nodes (readonly)



70
71
72
# File 'lib/docker_engine_ruby/client.rb', line 70

def nodes
  @nodes
end

#pluginsDockerEngineRuby::Resources::Plugins (readonly)



79
80
81
# File 'lib/docker_engine_ruby/client.rb', line 79

def plugins
  @plugins
end

#secretsDockerEngineRuby::Resources::Secrets (readonly)



67
68
69
# File 'lib/docker_engine_ruby/client.rb', line 67

def secrets
  @secrets
end

#servicesDockerEngineRuby::Resources::Services (readonly)



61
62
63
# File 'lib/docker_engine_ruby/client.rb', line 61

def services
  @services
end

#swarmDockerEngineRuby::Resources::Swarm (readonly)



73
74
75
# File 'lib/docker_engine_ruby/client.rb', line 73

def swarm
  @swarm
end

#system_DockerEngineRuby::Resources::System (readonly)



43
44
45
# File 'lib/docker_engine_ruby/client.rb', line 43

def system_
  @system_
end

#tasksDockerEngineRuby::Resources::Tasks (readonly)



76
77
78
# File 'lib/docker_engine_ruby/client.rb', line 76

def tasks
  @tasks
end

#tls_ca_cert_pathString? (readonly)

Path to the trusted CA certificate file (PEM) used to verify the Docker daemon certificate.

Returns:

  • (String, nil)


29
30
31
# File 'lib/docker_engine_ruby/client.rb', line 29

def tls_ca_cert_path
  @tls_ca_cert_path
end

#tls_client_cert_pathString? (readonly)

Path to the client TLS certificate file (PEM).

Returns:

  • (String, nil)


33
34
35
# File 'lib/docker_engine_ruby/client.rb', line 33

def tls_client_cert_path
  @tls_client_cert_path
end

#tls_client_key_pathString? (readonly)

Path to the client TLS private key file (PEM).

Returns:

  • (String, nil)


37
38
39
# File 'lib/docker_engine_ruby/client.rb', line 37

def tls_client_key_path
  @tls_client_key_path
end

#volumesDockerEngineRuby::Resources::Volumes (readonly)



58
59
60
# File 'lib/docker_engine_ruby/client.rb', line 58

def volumes
  @volumes
end