docker-porcelain 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.overcommit.yml +4 -32
- data/.rubocop.yml +10 -0
- data/README.md +7 -1
- data/lib/docker/porcelain/container.rb +48 -11
- data/lib/docker/porcelain/extensions.rb +2 -1
- data/lib/docker/porcelain/image.rb +43 -2
- data/lib/docker/porcelain/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9abf4d5591b1dc167a974d44a7b585ee079775a3
|
4
|
+
data.tar.gz: a8e2a32ad64087d40f19be336350c26652662ccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50f831bddf3502bf4e9684245d24e6c9437122aff4cc318b18d514dd3765fc04fbf05a32a39f937355f56ee2950b648ee89046005719770f09a7bf8cd8777ba7
|
7
|
+
data.tar.gz: e32d4a549030bee551c600aaf0118dcd6cc005158fe20d9333628758b26a4674c7f84b6c87dffc23180815f1de1e2b19623c2d8ac48ebcc5fb2f0c82a2515c60
|
data/.overcommit.yml
CHANGED
@@ -1,32 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
1
|
+
PreCommit:
|
2
|
+
RuboCop:
|
3
|
+
enabled: true
|
4
|
+
problem_on_unmodified_line: warn
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -67,9 +67,15 @@ container.write '/tmp/foo', 'This is the foo file!'
|
|
67
67
|
```ruby
|
68
68
|
container.write '/tmp/foo', 'This is the foo file!'
|
69
69
|
container.system 'true' or fail "there's no truth in the container!"
|
70
|
+
uptime = container.` 'uptime'
|
71
|
+
container.delete! # force destroy
|
72
|
+
|
70
73
|
img = Docker::Image['image:tag'] # => #<Docker::Image:...>
|
71
74
|
img.tags # => ['image:tag', 'other:tag']
|
72
|
-
|
75
|
+
img.parent # => #<Docker::Image:...>
|
76
|
+
img.tag 'repo', 'tag'
|
77
|
+
|
78
|
+
Docker::Image.repository 'image' # => [#<Docker::Image:...>, ...]
|
73
79
|
```
|
74
80
|
|
75
81
|
## Development
|
@@ -1,10 +1,15 @@
|
|
1
1
|
require 'docker/porcelain/error'
|
2
2
|
|
3
|
+
# rubocop:disable Style/OpMethod
|
4
|
+
# rubocop:disable Style/RedundantSelf
|
5
|
+
# rubocop:disable Style/Alias
|
6
|
+
|
3
7
|
module Docker
|
4
8
|
module Porcelain
|
5
9
|
module Container
|
6
|
-
#
|
7
|
-
# @note Executes
|
10
|
+
# Write to a file in the container
|
11
|
+
# @note Executes +tee+ internally, which has to be available inside the
|
12
|
+
# container.
|
8
13
|
# @param path [String] full path of the file to write
|
9
14
|
# @param content [String] data to be written
|
10
15
|
# @return [Fixnum] number of bytes written
|
@@ -20,13 +25,39 @@ module Docker
|
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
28
|
+
# Execute a command in the container, returning the output
|
29
|
+
# @param [String] command the command line to execute,
|
30
|
+
# passed to +/bin/sh -c+
|
31
|
+
# @return [String] the standard output
|
32
|
+
# @raise (Docker::Porcelain::CommandError) if there's a problem executing
|
33
|
+
# the command (ie. the shell returns 127)
|
34
|
+
# @note The exit code is available in {#last_exitstatus}.
|
35
|
+
# @see #system
|
36
|
+
def ` command
|
37
|
+
# unweird syntax highlighters: `
|
38
|
+
stdout, stderr, status = self.exec ['/bin/sh', '-c', command]
|
39
|
+
case @last_exitstatus = status
|
40
|
+
when 127
|
41
|
+
fail CommandError, stderr.join
|
42
|
+
else
|
43
|
+
stdout.join
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
alias backtick ` # `
|
48
|
+
|
49
|
+
# Execute a command in the container, discarding the output
|
23
50
|
# @overload system(command...)
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
51
|
+
# @param [String] command the command line to execute;
|
52
|
+
# passed to +/bin/sh -c+
|
53
|
+
# @param [String...] command... the command to execute and its arguments
|
54
|
+
# @return [true] if the command exits with zero exit status.
|
55
|
+
# @return [false] if the command exits with a nonzero status.
|
56
|
+
# @return [nil] if the command execution fails.
|
57
|
+
# @note The exit code is available in {#last_exitstatus}.
|
58
|
+
# @see #`
|
59
|
+
# @raise [NotImplementedError] if the argument list contains options
|
60
|
+
# or environments (as allowed by {Kernel#system}).
|
30
61
|
def system *args
|
31
62
|
env = args.shift if args.first.is_a? Hash
|
32
63
|
opts = args.pop if args.last.is_a? Hash
|
@@ -36,7 +67,7 @@ module Docker
|
|
36
67
|
raise NotImplementedError, "setting env or opts is not implemented" \
|
37
68
|
if [env, opts].any?
|
38
69
|
|
39
|
-
|
70
|
+
fail NotImplementedError, 'overriding argv0 is not implemented' \
|
40
71
|
if cmdline.first.is_a? Array
|
41
72
|
|
42
73
|
if cmdline.length == 1
|
@@ -45,7 +76,6 @@ module Docker
|
|
45
76
|
|
46
77
|
_stdout, _stderr, status = self.exec cmdline
|
47
78
|
|
48
|
-
# 'simulate' exit status in $?
|
49
79
|
@last_exitstatus = status
|
50
80
|
|
51
81
|
case status
|
@@ -56,7 +86,14 @@ module Docker
|
|
56
86
|
end
|
57
87
|
end
|
58
88
|
|
59
|
-
#
|
89
|
+
# Force delete a container (even if it is running)
|
90
|
+
# @return [void]
|
91
|
+
def delete!
|
92
|
+
delete force: true
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [Fixnum] exit status of the last command ran with {#system}
|
96
|
+
# or {#`}
|
60
97
|
attr_reader :last_exitstatus
|
61
98
|
end
|
62
99
|
end
|
@@ -21,14 +21,55 @@ module Docker
|
|
21
21
|
|
22
22
|
# @return [Array<String>] repository tags of the image
|
23
23
|
def tags
|
24
|
+
# Image can have incomplete info, refresh then
|
25
|
+
refresh! unless info['RepoTags']
|
26
|
+
|
24
27
|
# docker returns '<none>:<none>' for an untagged repo
|
25
28
|
info['RepoTags'] - ['<none>:<none>']
|
26
29
|
end
|
27
30
|
|
31
|
+
# @return [Docker::Image] the parent image
|
32
|
+
# @return [nil] if the image is +FROM scratch+
|
33
|
+
def parent
|
34
|
+
return nil if (parent = info['Parent']).empty?
|
35
|
+
Docker::Porcelain::Image[parent]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Tag the image
|
39
|
+
# @overload tag(repo, tag, opts)
|
40
|
+
# @param [String] repo the repository to tag in
|
41
|
+
# @param [String] tag the new tag
|
42
|
+
# @option opts [Boolean] force whether to replace the tag if it
|
43
|
+
# already exists
|
44
|
+
# @overload tag(repo_tag, opts)
|
45
|
+
# @param [String] repo_tag the repository to tag in with optional tag;
|
46
|
+
# in 'repo:tag' or 'repo' format
|
47
|
+
# @option opts [Boolean] force whether to replace the tag if it
|
48
|
+
# already exists
|
49
|
+
# @overload tag(opts)
|
50
|
+
# @option opts [String] repo the repository to tag in
|
51
|
+
# @option opts [String] tag the new tag
|
52
|
+
# @option opts [Boolean] force whether to replace the tag if it
|
53
|
+
# already exists
|
54
|
+
# @return [void]
|
55
|
+
def tag *args
|
56
|
+
strargs, rest = args.partition { |arg| arg.respond_to? :to_str }
|
57
|
+
|
58
|
+
# rest should be [opts] or empty
|
59
|
+
rest.length < 2 or
|
60
|
+
fail ArgumentError, 'expected args: [repo [tag]] [options]'
|
61
|
+
opts = rest.first || {}
|
62
|
+
|
63
|
+
super opts.merge Image.repo_tag_to_hash *strargs
|
64
|
+
end
|
65
|
+
|
28
66
|
extend ClassMethods
|
29
67
|
|
30
|
-
|
31
|
-
|
68
|
+
private
|
69
|
+
|
70
|
+
def self.repo_tag_to_hash repo = nil, tag = nil
|
71
|
+
repo, tag = repo.split ':' unless tag
|
72
|
+
{ 'repo' => repo, 'tag' => tag }
|
32
73
|
end
|
33
74
|
end
|
34
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-porcelain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafał Rzepecki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- ".gitignore"
|
77
77
|
- ".overcommit.yml"
|
78
78
|
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
79
80
|
- ".travis.yml"
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|