docker-porcelain 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 +9 -0
- data/.overcommit.yml +32 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/docker-porcelain.gemspec +26 -0
- data/lib/docker/porcelain.rb +8 -0
- data/lib/docker/porcelain/container.rb +63 -0
- data/lib/docker/porcelain/error.rb +16 -0
- data/lib/docker/porcelain/extensions.rb +11 -0
- data/lib/docker/porcelain/refinements.rb +12 -0
- data/lib/docker/porcelain/version.rb +5 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7efd63b3850efd8d08d78ecb5415b1b0d605909d
|
4
|
+
data.tar.gz: fb88214f6d293cb9a060a75552b20b3924082bd0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f25a8960da2cef4ad5643963aeb3a04ecf40e0c683fd07c9b06df4d8f809e8036b28b31bb6c14c69b7728cf7e6f95a36a0c9288881c74c7af3b7c1d187d91731
|
7
|
+
data.tar.gz: 27402efb8ed7e69890a1b62a6d9fda38acb9e89b75602009b67f5dbde1e8b3d8972b05b35ecefa6c10f8d45def964bfcd64810a6bda563a0cbfb861c86ad1723
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Use this file to configure the Overcommit hooks you wish to use. This will
|
2
|
+
# extend the default configuration defined in:
|
3
|
+
# https://github.com/brigade/overcommit/blob/master/config/default.yml
|
4
|
+
#
|
5
|
+
# At the topmost level of this YAML file is a key representing type of hook
|
6
|
+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
7
|
+
# customize each hook, such as whether to only run it on certain files (via
|
8
|
+
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
9
|
+
#
|
10
|
+
# For a complete list of hooks, see:
|
11
|
+
# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
|
12
|
+
#
|
13
|
+
# For a complete list of options that you can use to customize hooks, see:
|
14
|
+
# https://github.com/brigade/overcommit#configuration
|
15
|
+
#
|
16
|
+
# Uncomment the following lines to make the configuration take effect.
|
17
|
+
|
18
|
+
#PreCommit:
|
19
|
+
# RuboCop:
|
20
|
+
# enabled: true
|
21
|
+
# on_warn: fail # Treat all warnings as failures
|
22
|
+
#
|
23
|
+
# TrailingWhitespace:
|
24
|
+
# exclude:
|
25
|
+
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
|
26
|
+
#
|
27
|
+
#PostCheckout:
|
28
|
+
# ALL: # Special hook name that customizes all hooks of this type
|
29
|
+
# quiet: true # Change all post-checkout hooks to only display output on failure
|
30
|
+
#
|
31
|
+
# IndexTags:
|
32
|
+
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Rafał Rzepecki
|
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,86 @@
|
|
1
|
+
# Docker::Porcelain
|
2
|
+
|
3
|
+
Porcelain for the Docker API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'docker-porcelain'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install docker-porcelain
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
There's several styles of using docker-porcelain:
|
24
|
+
|
25
|
+
### Monkey-patching (AKA global extensions)
|
26
|
+
|
27
|
+
Recommended for application code unless it causes problems.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'docker/porcelain/extensions'
|
31
|
+
|
32
|
+
container = Docker::Container.create 'Image' => 'alpine'
|
33
|
+
container.write '/tmp/foo', 'This is the foo file!'
|
34
|
+
```
|
35
|
+
|
36
|
+
Note this will monkey patch docker-api classes, which might not be what you
|
37
|
+
want (especially in a library).
|
38
|
+
|
39
|
+
### Object extensions
|
40
|
+
|
41
|
+
You can extend individual objects (recommended for library code):
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'docker/porcelain'
|
45
|
+
|
46
|
+
container = Docker::Container.create 'Image' => 'alpine'
|
47
|
+
container.extend Docker::Porcelain::Container
|
48
|
+
container.write '/tmp/foo', 'This is the foo file!'
|
49
|
+
```
|
50
|
+
|
51
|
+
### Refinements
|
52
|
+
|
53
|
+
[Not recommended](http://6ftdan.com/allyourdev/2015/06/21/ruby-refinements-not-quite-ready-for-production/),
|
54
|
+
and it might not work as expected, but you can experiment:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'docker/porcelain/refinements'
|
58
|
+
|
59
|
+
using Docker::Porcelain
|
60
|
+
|
61
|
+
container = Docker::Container.create 'Image' => 'alpine'
|
62
|
+
container.write '/tmp/foo', 'This is the foo file!'
|
63
|
+
```
|
64
|
+
|
65
|
+
## Synopsis
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
container.write '/tmp/foo', 'This is the foo file!'
|
69
|
+
container.system 'true' or fail "there's no truth in the container!"
|
70
|
+
```
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
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).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/conjurinc/docker-porcelain.
|
81
|
+
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
86
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "docker/porcelain"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'docker/porcelain/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "docker-porcelain"
|
8
|
+
spec.version = Docker::Porcelain::VERSION
|
9
|
+
spec.authors = ["Rafał Rzepecki"]
|
10
|
+
spec.email = ["rafal@conjur.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{Porcelain for the Docker API}
|
13
|
+
spec.homepage = "https://github.com/conjurinc/docker-porcelain"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "docker-api", "~> 1.22"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'docker/porcelain/error'
|
2
|
+
|
3
|
+
module Docker
|
4
|
+
module Porcelain
|
5
|
+
module Container
|
6
|
+
# Writes to a file in the container
|
7
|
+
# @note Executes `tee` internally, which has to be available inside the container.
|
8
|
+
# @param path [String] full path of the file to write
|
9
|
+
# @param content [String] data to be written
|
10
|
+
# @return [Fixnum] number of bytes written
|
11
|
+
def write path, content
|
12
|
+
stdout, stderr, code = exec ['tee', path], stdin: StringIO.new(content)
|
13
|
+
case code
|
14
|
+
when 0
|
15
|
+
stdout.map(&:length).inject :+
|
16
|
+
when 127
|
17
|
+
raise MisconfiguredContainerError, "error when trying to call tee: " + (stdout + stderr).join
|
18
|
+
else
|
19
|
+
raise CommandError, (stdout + stderr).join
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @overload system(command...)
|
24
|
+
# Executes a command in a container
|
25
|
+
# @param [String, Array<String>] command to execute.
|
26
|
+
# A single string is passed to '/bin/sh -c' for execution.
|
27
|
+
# @return [true, false, nil] true if the command gives zero exit status,
|
28
|
+
# false for non zero exit status, nil if command execution fails.
|
29
|
+
# @note The exit code is available in {.last_exitstatus}.
|
30
|
+
def system *args
|
31
|
+
env = args.shift if args.first.is_a? Hash
|
32
|
+
opts = args.pop if args.last.is_a? Hash
|
33
|
+
|
34
|
+
cmdline = args
|
35
|
+
|
36
|
+
raise NotImplementedError, "setting env or opts is not implemented" \
|
37
|
+
if [env, opts].any?
|
38
|
+
|
39
|
+
raise NotImplementedError, "overringing argv0 is not implemented" \
|
40
|
+
if cmdline.first.is_a? Array
|
41
|
+
|
42
|
+
if cmdline.length == 1
|
43
|
+
cmdline = ['/bin/sh', '-c', cmdline.first]
|
44
|
+
end
|
45
|
+
|
46
|
+
_stdout, _stderr, status = self.exec cmdline
|
47
|
+
|
48
|
+
# 'simulate' exit status in $?
|
49
|
+
@last_exitstatus = status
|
50
|
+
|
51
|
+
case status
|
52
|
+
when 127
|
53
|
+
nil
|
54
|
+
else
|
55
|
+
status == 0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Exit status of the last command ran with {#system}
|
60
|
+
attr_reader :last_exitstatus
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Docker
|
2
|
+
module Porcelain
|
3
|
+
# Superclass of all errors from Docker::Porcelain.
|
4
|
+
class Error < RuntimeError
|
5
|
+
end
|
6
|
+
|
7
|
+
# Error caused most probably by an unexpected container configuration,
|
8
|
+
# eg. a missing command.
|
9
|
+
class MisconfiguredContainerError < Error
|
10
|
+
end
|
11
|
+
|
12
|
+
# Error running a command inside a container.
|
13
|
+
class CommandError < Error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docker-porcelain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rafał Rzepecki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: docker-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.22'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.22'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- rafal@conjur.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".overcommit.yml"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- docker-porcelain.gemspec
|
87
|
+
- lib/docker/porcelain.rb
|
88
|
+
- lib/docker/porcelain/container.rb
|
89
|
+
- lib/docker/porcelain/error.rb
|
90
|
+
- lib/docker/porcelain/extensions.rb
|
91
|
+
- lib/docker/porcelain/refinements.rb
|
92
|
+
- lib/docker/porcelain/version.rb
|
93
|
+
homepage: https://github.com/conjurinc/docker-porcelain
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.4.8
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Porcelain for the Docker API
|
117
|
+
test_files: []
|
118
|
+
has_rdoc:
|