dockerapi 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f647538a729eaa623b009a4e97713761bc80579073ebfb8b9ab7bfa26b6b6d98
4
- data.tar.gz: ce3b40c357d635a47ab8c921b59254ef734c2ec1173da60e58ba1b6f7d325ecf
3
+ metadata.gz: 90acd383975c4846ca2d6bfb91aa15d9898ce0101557ca50481f20729871ef73
4
+ data.tar.gz: 03d01594692f5c2093bf3e91b4f67635d2bd8e1bf0360217747ea4aa8d2c6840
5
5
  SHA512:
6
- metadata.gz: f845ea3e89761d9ab726f098d4ef4ca1586c92320616359b182d6f9dc24e7769b53c88a6d17d8257514303226b16fd08a841ced1645be68c19b4d4b31a8a9b4f
7
- data.tar.gz: 409819921a1135b593377d8c561d0d5f81013f519e98a547976b1563b4038bff91f5948a5cd00b9f7513026821811b9baa476306915b7b644768232238daf0f4
6
+ metadata.gz: 56a36a3c8b73fc0a8ae02cc68bd93b6b858be21d8c9c6d033b5f1d34d581f646dbb9e77df2e0a9d216c2a835eec3bd8e1abb62ade82aa6ec818ef081b5181d5d
7
+ data.tar.gz: 101c74b35333664dc5573d5443f2c7d75d5c8de9a43a2f70a7a54e5bb5673091eebe31dfc9ed5845c1052f47907dc6d7873f3bbe84a5015e10f5411458993cb9
@@ -1,3 +1,13 @@
1
+ # 0.6.0
2
+
3
+ Add connection parameters specifications with connect_to in Docker::API::Connection.
4
+
5
+ Add Docker::API::Exec methods:
6
+ * create
7
+ * start
8
+ * resize
9
+ * inspect
10
+
1
11
  # 0.5.0
2
12
 
3
13
  Add Docker::API::System methods:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dockerapi (0.5.0)
4
+ dockerapi (0.6.0)
5
5
  excon (~> 0.74.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -37,7 +37,6 @@ Docker::API::Image.create( fromSrc: "https://url.to/file.tar", repo: "repo:tag"
37
37
 
38
38
  # List images
39
39
  Docker::API::Image.list
40
- Docker::API::Image.list( all:true )
41
40
 
42
41
  # Inspect image
43
42
  Docker::API::Image.inspect("image")
@@ -59,7 +58,7 @@ Docker::API::Image.push("repo:tag") # to dockerhub
59
58
  Docker::API::Image.push("localhost:5000/repo:tag") # to local registry
60
59
  Docker::API::Image.push("private/repo", {tag: "tag"}, {username: "janedoe", password: "password"} # to private repository
61
60
 
62
- # Remove container
61
+ # Remove image
63
62
  Docker::API::Image.remove("image")
64
63
  Docker::API::Image.remove("image", force: true)
65
64
 
@@ -215,6 +214,21 @@ Docker::API::System.events(until: Time.now.to_i)
215
214
  Docker::API::System.df
216
215
  ```
217
216
 
217
+ ### Exec
218
+
219
+ ```ruby
220
+ # Create exec instance, get generated exec ID
221
+ response = Docker::API::Exec.create(container, AttachStdout:true, Cmd: ["ls", "-l"])
222
+ id = response.json["Id"]
223
+
224
+ # Execute the command, stream from Stdout is stored in response data
225
+ response = Docker::API::Exec.start(id)
226
+ print response.data[:stream]
227
+
228
+ # Inspect exec instance
229
+ Docker::API::Exec.inspect(id)
230
+ ```
231
+
218
232
  ### Requests
219
233
 
220
234
  Requests should work as described in [Docker API documentation](https://docs.docker.com/engine/api/v1.40). Check it out to customize your requests.
@@ -275,7 +289,7 @@ WIP: Work In Progress
275
289
  | Volume | Ok | Ok | NS |
276
290
  | Network | Ok | Ok | NS |
277
291
  | System | Ok | Ok | NS |
278
- | Exec | NS | NS | NS |
292
+ | Exec | Ok | Ok | NS |
279
293
  | Swarm | NS | NS | NS |
280
294
  | Node | NS | NS | NS |
281
295
  | Service | NS | NS | NS |
data/bin/setup CHANGED
@@ -1,8 +1,22 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
4
+ #set -vx
7
5
 
8
6
  # Do any other automated setup that you need to do here
7
+ if [ $USER == 'root' ]
8
+ then
9
+ echo "Enabling TCP port 2375 for external connection to Docker"
10
+ echo '{"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]}' > /etc/docker/daemon.json
11
+ mkdir -p /etc/systemd/system/docker.service.d
12
+ echo '[Service]' > /etc/systemd/system/docker.service.d/override.conf
13
+ echo 'ExecStart=' >> /etc/systemd/system/docker.service.d/override.conf
14
+ echo 'ExecStart=/usr/bin/dockerd' >> /etc/systemd/system/docker.service.d/override.conf
15
+ systemctl daemon-reload
16
+ systemctl restart docker.service
17
+ echo "Done!"
18
+ else
19
+ echo "Running bundle install"
20
+ bundle install
21
+ echo "Run this script as root for further configurations"
22
+ fi
@@ -15,6 +15,10 @@ module Docker
15
15
  def request params
16
16
  Docker::API::Response.new(@connection.request(params).data)
17
17
  end
18
+
19
+ def connect_to params
20
+ @connection = Excon.new(params)
21
+ end
18
22
 
19
23
  private
20
24
  def initialize
@@ -0,0 +1,39 @@
1
+ module Docker
2
+ module API
3
+ class Exec < Docker::API::Base
4
+
5
+ def self.base_path
6
+ "/exec"
7
+ end
8
+
9
+ def self.create name, body = {}
10
+ validate Docker::API::InvalidRequestBody, [:AttachStdin, :AttachStdout, :AttachStderr, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir], body
11
+ connection.request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json )
12
+ end
13
+
14
+ def self.start name, body = {}
15
+ validate Docker::API::InvalidRequestBody, [:Detach, :Tty], body
16
+
17
+ stream = ""
18
+ response = connection.request(method: :post,
19
+ path: "/exec/#{name}/start",
20
+ headers: {"Content-Type": "application/json"},
21
+ body: body.to_json,
22
+ response_block: lambda { |chunk, remaining_bytes, total_bytes| stream += chunk.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') }
23
+ )
24
+ response.data.merge!({stream: stream})
25
+ response
26
+ end
27
+
28
+ def self.resize name, params = {}
29
+ validate Docker::API::InvalidParameter, [:w, :h], params
30
+ connection.post(build_path([name, "resize"], params))
31
+ end
32
+
33
+ def self.inspect name
34
+ connection.get(build_path([name, "json"]))
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.5.0"
3
+ GEM_VERSION = "0.6.0"
4
4
 
5
5
  API_VERSION = "1.40"
6
6
 
@@ -10,6 +10,7 @@ require "docker/api/container"
10
10
  require "docker/api/image"
11
11
  require "docker/api/volume"
12
12
  require "docker/api/network"
13
+ require "docker/api/exec"
13
14
  require "docker/api/system"
14
15
 
15
16
  module Docker
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alysson A. Costa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-29 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -47,6 +47,7 @@ files:
47
47
  - lib/docker/api/connection.rb
48
48
  - lib/docker/api/container.rb
49
49
  - lib/docker/api/error.rb
50
+ - lib/docker/api/exec.rb
50
51
  - lib/docker/api/image.rb
51
52
  - lib/docker/api/network.rb
52
53
  - lib/docker/api/response.rb