dockerapi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +132 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dockerapi.gemspec +29 -0
- data/lib/docker/api/connection.rb +42 -0
- data/lib/docker/api/container.rb +183 -0
- data/lib/docker/api/error.rb +6 -0
- data/lib/docker/api/image.rb +24 -0
- data/lib/docker/api/version.rb +9 -0
- data/lib/dockerapi.rb +12 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 39b737a07cdf35864b8be1402ca7d504c59fc854e2092762df7a9f448bb2bf24
|
4
|
+
data.tar.gz: d71d1894cab1f61a3713f0991d24c272f99373832bff140c962604a8d707621f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3622c339bae6e7a93738d110a5d6eaa38dda6288abeebda35c4b376cd354b33fa2b1595bf53fc2da04cf8a5e6f8e78a49f7cea10927afdb3fc719f119d94a8fd
|
7
|
+
data.tar.gz: d40f00a1e7c913a5b005cba33182e2295da22d1631eb0fec23101d45639998391ad89829a03a51b3c197da8f69196c954fb8e70234f90175f2b7bbc410159be1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dockerapi (0.1.0)
|
5
|
+
excon
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
excon (0.74.0)
|
12
|
+
rake (12.3.3)
|
13
|
+
rspec (3.9.0)
|
14
|
+
rspec-core (~> 3.9.0)
|
15
|
+
rspec-expectations (~> 3.9.0)
|
16
|
+
rspec-mocks (~> 3.9.0)
|
17
|
+
rspec-core (3.9.2)
|
18
|
+
rspec-support (~> 3.9.3)
|
19
|
+
rspec-expectations (3.9.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.9.0)
|
22
|
+
rspec-mocks (3.9.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.9.0)
|
25
|
+
rspec-support (3.9.3)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
dockerapi!
|
32
|
+
rake (~> 12.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# dockerapi
|
2
|
+
|
3
|
+
Interact directly with Docker API from Ruby code.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dockerapi'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dockerapi
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Let's test a Nginx container
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# Pull nginx image
|
27
|
+
Docker::API::Image.create( fromImage: "nginx:latest" )
|
28
|
+
|
29
|
+
# Create container
|
30
|
+
Docker::API::Container.create( {name: "nginx"}, {Image: "nginx:latest", HostConfig: {PortBindings: {"80/tcp": [ {HostIp: "0.0.0.0", HostPort: "80"} ]}}})
|
31
|
+
|
32
|
+
# Start container
|
33
|
+
Docker::API::Container.start("nginx")
|
34
|
+
|
35
|
+
# Open localhost or machine IP to check the container running
|
36
|
+
|
37
|
+
# Restart container
|
38
|
+
Docker::API::Container.restart("nginx")
|
39
|
+
|
40
|
+
# Pause/unpause container
|
41
|
+
Docker::API::Container.pause("nginx")
|
42
|
+
Docker::API::Container.unpause("nginx")
|
43
|
+
|
44
|
+
# List containers
|
45
|
+
Docker::API::Container::list
|
46
|
+
|
47
|
+
# List containers (including stopped ones)
|
48
|
+
Docker::API::Container::list(all: true)
|
49
|
+
|
50
|
+
# Inspect container
|
51
|
+
Docker::API::Container.inspect("nginx")
|
52
|
+
|
53
|
+
# View container's processes
|
54
|
+
Docker::API::Container.top("nginx")
|
55
|
+
|
56
|
+
# Let's enhance the output
|
57
|
+
JSON.parse(Docker::API::Container.top("nginx").body)
|
58
|
+
|
59
|
+
# View filesystem changes
|
60
|
+
Docker::API::Container.changes("nginx")
|
61
|
+
|
62
|
+
# View filesystem logs
|
63
|
+
Docker::API::Container.logs("nginx", stdout: true)
|
64
|
+
Docker::API::Container.logs("nginx", stdout: true, follow: true)
|
65
|
+
|
66
|
+
# View filesystem stats
|
67
|
+
Docker::API::Container.stats("nginx", stream: true)
|
68
|
+
|
69
|
+
# Export container
|
70
|
+
Docker::API::Container.export("nginx", "~/exported_container")
|
71
|
+
|
72
|
+
# Get files from container
|
73
|
+
Docker::API::Container.archive("nginx", "~/html.tar", path: "/usr/share/nginx/html/")
|
74
|
+
|
75
|
+
# Stop container
|
76
|
+
Docker::API::Container.stop("nginx")
|
77
|
+
|
78
|
+
# Remove container
|
79
|
+
Docker::API::Container.remove("nginx")
|
80
|
+
|
81
|
+
# Remove stopped containers (prune)
|
82
|
+
Docker::API::Container.prune
|
83
|
+
```
|
84
|
+
|
85
|
+
### Requests
|
86
|
+
|
87
|
+
Requests should work as described in Docker API documentation.
|
88
|
+
|
89
|
+
### Response
|
90
|
+
|
91
|
+
All requests return a Excon::Response object.
|
92
|
+
|
93
|
+
## Development
|
94
|
+
|
95
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
96
|
+
|
97
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
98
|
+
|
99
|
+
### Road to 1.0.0
|
100
|
+
|
101
|
+
NS: Not Started
|
102
|
+
|
103
|
+
WIP: Work In Progress
|
104
|
+
|
105
|
+
|
106
|
+
| Class | Tests | Implementation | Refactoring |
|
107
|
+
|---|---|---|---|
|
108
|
+
| Container | WIP | WIP | NS |
|
109
|
+
| Image | NS | NS | NS |
|
110
|
+
| Volume | NS | NS | NS |
|
111
|
+
| Network | NS | NS | NS |
|
112
|
+
| System | NS | NS | NS |
|
113
|
+
| Exec | NS | NS | NS |
|
114
|
+
| Swarm | NS | NS | NS |
|
115
|
+
| Node | NS | NS | NS |
|
116
|
+
| Service | NS | NS | NS |
|
117
|
+
| Task | NS | NS | NS |
|
118
|
+
| Secret | NS | NS | NS |
|
119
|
+
|
120
|
+
Misc:
|
121
|
+
* Improve response object
|
122
|
+
* Improve error objects
|
123
|
+
|
124
|
+
## Contributing
|
125
|
+
|
126
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nu12/dockerapi.
|
127
|
+
|
128
|
+
|
129
|
+
## License
|
130
|
+
|
131
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
132
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dockerapi"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/dockerapi.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/docker/api/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "dockerapi"
|
5
|
+
spec.version = Docker::API::GEM_VERSION
|
6
|
+
spec.authors = ["Alysson A. Costa"]
|
7
|
+
spec.email = ["alysson.avila.costa@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "Interact directly with Docker API from Ruby code."
|
10
|
+
spec.description = "Interact directly with Docker API from Ruby code."
|
11
|
+
spec.homepage = "https://github.com/nu12/dockerapi"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/nu12/dockerapi.git"
|
17
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency "excon"
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "excon"
|
2
|
+
require "singleton"
|
3
|
+
require "json"
|
4
|
+
module Docker
|
5
|
+
module API
|
6
|
+
class Connection
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_reader(:connection)
|
10
|
+
|
11
|
+
def get path
|
12
|
+
r = @connection.get(path: path)
|
13
|
+
#p r
|
14
|
+
r
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(path, body = nil)
|
18
|
+
if body
|
19
|
+
r = @connection.post(path: path, headers: { "Content-Type" => "application/json" }, body: body.to_json)
|
20
|
+
else
|
21
|
+
r = @connection.post(path: path)
|
22
|
+
end
|
23
|
+
#p r
|
24
|
+
r
|
25
|
+
end
|
26
|
+
|
27
|
+
def head(path)
|
28
|
+
@connection.head(path: path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete path
|
32
|
+
@connection.delete(path: path)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def initialize
|
37
|
+
@connection = Excon.new('unix:///', :socket => '/var/run/docker.sock')
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
module Docker
|
2
|
+
module API
|
3
|
+
CreateBody = [:Hostname,:Domainname,:User,:AttachStdin,:AttachStdout,:AttachStderr,:ExposedPorts,:Tty,:OpenStdin,:StdinOnce,:Env,:Cmd,:HealthCheck,:ArgsEscaped,:Image,:Volumes,:WorkingDir,:Entrypoint,:NetworkDisabled,:MacAddress,:OnBuild,:Labels,:StopSignal,:StopTimeout,:Shell,:HostConfig,:NetworkingConfig]
|
4
|
+
UpdateBody = [:CpuShares, :Memory, :CgroupParent, :BlkioWeight, :BlkioWeightDevice, :BlkioWeightReadBps, :BlkioWeightWriteBps, :BlkioWeightReadOps, :BlkioWeightWriteOps, :CpuPeriod, :CpuQuota, :CpuRealtimePeriod, :CpuRealtimeRuntime, :CpusetCpus, :CpusetMems, :Devices, :DeviceCgroupRules, :DeviceRequest, :Kernel, :Memory, :KernelMemoryTCP, :MemoryReservation, :MemorySwap, :MemorySwappiness, :NanoCPUs, :OomKillDisable, :Init, :PidsLimit, :ULimits, :CpuCount, :CpuPercent, :IOMaximumIOps, :IOMaximumBandwidth, :RestartPolicy]
|
5
|
+
|
6
|
+
class Container
|
7
|
+
|
8
|
+
@@base_path = "/containers"
|
9
|
+
|
10
|
+
def self.list params = {}
|
11
|
+
self.validate Docker::API::InvalidParameter, [:all, :limit, :size, :filters], params
|
12
|
+
Docker::API::Connection.instance.get(self.build_path(["json"], params))
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.inspect name, params = {}
|
16
|
+
self.validate Docker::API::InvalidParameter, [:size], params
|
17
|
+
Docker::API::Connection.instance.get(self.build_path([name, "json"], params))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.top name, params = {}
|
21
|
+
self.validate Docker::API::InvalidParameter, [:ps_args], params
|
22
|
+
Docker::API::Connection.instance.get(self.build_path([name, "top"], params))
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.changes name
|
26
|
+
Docker::API::Connection.instance.get(self.build_path([name, "changes"]))
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.start name, params = {}
|
30
|
+
self.validate Docker::API::InvalidParameter, [:detachKeys], params
|
31
|
+
Docker::API::Connection.instance.post(self.build_path([name, "start"], params))
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.stop name, params = {}
|
35
|
+
self.validate Docker::API::InvalidParameter, [:t], params
|
36
|
+
Docker::API::Connection.instance.post(self.build_path([name, "stop"], params))
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.restart name, params = {}
|
40
|
+
self.validate Docker::API::InvalidParameter, [:t], params
|
41
|
+
Docker::API::Connection.instance.post(self.build_path([name, "restart"], params))
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.kill name, params = {}
|
45
|
+
self.validate Docker::API::InvalidParameter, [:signal], params
|
46
|
+
Docker::API::Connection.instance.post(self.build_path([name, "kill"], params))
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.wait name, params = {}
|
50
|
+
self.validate Docker::API::InvalidParameter, [:condition], params
|
51
|
+
Docker::API::Connection.instance.post(self.build_path([name, "wait"], params))
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.update name, body = {}
|
55
|
+
self.validate Docker::API::InvalidRequestBody, Docker::API::UpdateBody, body
|
56
|
+
Docker::API::Connection.instance.post(self.build_path([name, "update"]), body)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.rename name, params = {}
|
60
|
+
self.validate Docker::API::InvalidParameter, [:name], params
|
61
|
+
Docker::API::Connection.instance.post(self.build_path([name, "rename"], params))
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.resize name, params = {}
|
65
|
+
self.validate Docker::API::InvalidParameter, [:w, :h], params
|
66
|
+
Docker::API::Connection.instance.post(self.build_path([name, "resize"], params))
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.prune params = {}
|
70
|
+
self.validate Docker::API::InvalidParameter, [:filters], params
|
71
|
+
Docker::API::Connection.instance.post(self.build_path(["prune"], params))
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.pause name
|
75
|
+
Docker::API::Connection.instance.post(self.build_path([name, "pause"]))
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.unpause name
|
79
|
+
Docker::API::Connection.instance.post(self.build_path([name, "unpause"]))
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.remove name, params = {}
|
83
|
+
self.validate Docker::API::InvalidParameter, [:v, :force, :link], params
|
84
|
+
Docker::API::Connection.instance.delete(self.build_path([name]))
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.logs name, params = {}
|
88
|
+
self.validate Docker::API::InvalidParameter, [:follow, :stdout, :stderr, :since, :until, :timestamps, :tail], params
|
89
|
+
|
90
|
+
path = self.build_path([name, "logs"], params)
|
91
|
+
|
92
|
+
if params[:follow] == true || params[:follow] == 1
|
93
|
+
Docker::API::Connection.instance.connection.get(path: path , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
94
|
+
else
|
95
|
+
Docker::API::Connection.instance.get(path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.attach name, params = {}
|
100
|
+
self.validate Docker::API::InvalidParameter, [:detachKeys, :logs, :stream, :stdin, :stdout, :stderr], params
|
101
|
+
Docker::API::Connection.instance.connection.request(method: :post, path: self.build_path([name, "attach"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.create params = {}, body = {}
|
105
|
+
self.validate Docker::API::InvalidParameter, [:name], params
|
106
|
+
self.validate Docker::API::InvalidRequestBody, Docker::API::CreateBody, body
|
107
|
+
Docker::API::Connection.instance.post(self.build_path(["create"], params), body)
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.stats name, params = {}
|
111
|
+
self.validate Docker::API::InvalidParameter, [:stream], params
|
112
|
+
path = self.build_path([name, "stats"], params)
|
113
|
+
|
114
|
+
if params[:stream] == true || params[:stream] == 1
|
115
|
+
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
116
|
+
puts chunk
|
117
|
+
end
|
118
|
+
Docker::API::Connection.instance.connection.get(path: path , response_block: streamer)
|
119
|
+
else
|
120
|
+
Docker::API::Connection.instance.get(path)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.export name, path = "exported_container"
|
125
|
+
response = Docker::API::Container.inspect(name)
|
126
|
+
if response.status == 200
|
127
|
+
file = File.open(File.expand_path(path), "wb")
|
128
|
+
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
129
|
+
file.write(chunk)
|
130
|
+
end
|
131
|
+
response = Docker::API::Connection.instance.connection.get(path: self.build_path([name, "export"]) , response_block: streamer)
|
132
|
+
file.close
|
133
|
+
end
|
134
|
+
response
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.archive name, file, params = {}
|
138
|
+
self.validate Docker::API::InvalidParameter, [:path, :noOverwriteDirNonDir, :copyUIDGID], params
|
139
|
+
|
140
|
+
begin # File exists on disk, send it to container
|
141
|
+
file = File.open( File.expand_path( file ) , "r")
|
142
|
+
response = Docker::API::Connection.instance.connection.put(path: self.build_path([name, "archive"], params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
143
|
+
file.close
|
144
|
+
rescue Errno::ENOENT # File doesnt exist, get it from container
|
145
|
+
response = Docker::API::Connection.instance.head(self.build_path([name, "archive"], params))
|
146
|
+
if response.status == 200 # file exists in container
|
147
|
+
file = File.open( File.expand_path( file ) , "wb")
|
148
|
+
response = Docker::API::Connection.instance.connection.get(path: self.build_path([name, "archive"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
|
149
|
+
file.close
|
150
|
+
end
|
151
|
+
end
|
152
|
+
response
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def self.validate error, permitted_keys, params
|
158
|
+
not_permitted = params.keys - permitted_keys
|
159
|
+
raise error if not_permitted.size > 0
|
160
|
+
end
|
161
|
+
|
162
|
+
## Converts Ruby Hash into query parameters
|
163
|
+
## In general, the format is key=value
|
164
|
+
## If value is another Hash, it should keep a json syntax {key:value}
|
165
|
+
def self.hash_to_params h
|
166
|
+
p = []
|
167
|
+
h.each do |k,v|
|
168
|
+
if v.is_a?(Hash)
|
169
|
+
p << "#{k}=#{v.to_json}"
|
170
|
+
else
|
171
|
+
p << "#{k}=#{v}"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
p.join("&").gsub(" ","")
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.build_path path, params = {}
|
178
|
+
p = ([@@base_path] << path).join("/")
|
179
|
+
params.size > 0 ? [p, self.hash_to_params(params)].join("?") : p
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Docker
|
2
|
+
module API
|
3
|
+
class Image
|
4
|
+
|
5
|
+
@@base_path = "/images"
|
6
|
+
|
7
|
+
def self.create query_params = {}
|
8
|
+
Docker::API::Connection.instance.post(self.build_path(["create"], query_params))
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.remove name, query_params = {}
|
12
|
+
Docker::API::Connection.instance.delete(self.build_path([name], query_params))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.build_path path, params = {}
|
18
|
+
p = ([@@base_path] << path).join("/")
|
19
|
+
params.size > 0 ? [p, params.map {|k,v| "#{k}=#{v}"}.join("&")].join("?") : p
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/dockerapi.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dockerapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alysson A. Costa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Interact directly with Docker API from Ruby code.
|
28
|
+
email:
|
29
|
+
- alysson.avila.costa@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/console
|
43
|
+
- bin/setup
|
44
|
+
- dockerapi.gemspec
|
45
|
+
- lib/docker/api/connection.rb
|
46
|
+
- lib/docker/api/container.rb
|
47
|
+
- lib/docker/api/error.rb
|
48
|
+
- lib/docker/api/image.rb
|
49
|
+
- lib/docker/api/version.rb
|
50
|
+
- lib/dockerapi.rb
|
51
|
+
homepage: https://github.com/nu12/dockerapi
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata:
|
55
|
+
homepage_uri: https://github.com/nu12/dockerapi
|
56
|
+
source_code_uri: https://github.com/nu12/dockerapi.git
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.3.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.1.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Interact directly with Docker API from Ruby code.
|
76
|
+
test_files: []
|