Module: Docker
- Extended by:
- Docker, Helpers
- Included in:
- Docker, Rails, Ruby
- Defined in:
- lib/docker.rb,
lib/docker/id.rb,
lib/docker/tag.rb,
lib/docker/path.rb,
lib/docker/rake.rb,
lib/docker/ruby.rb,
lib/docker/image.rb,
lib/docker/rails.rb,
lib/docker/helpers.rb,
lib/docker/inspect.rb,
lib/docker/equality.rb,
lib/docker/postgres.rb,
lib/docker/container.rb,
lib/docker/repository.rb,
lib/docker/interactive.rb,
lib/docker/rails/server.rb,
lib/docker/rails/console.rb
Defined Under Namespace
Modules: Equality, Helpers, Interactive, Rails, Rake, Ruby
Classes: Container, Id, Image, Inspect, NullInspect, Path, Postgres, Repository, Tag
Constant Summary
collapse
- USER_NAME =
'jphager2'
Instance Method Summary
collapse
Methods included from Helpers
rails_image, rails_server
Instance Method Details
#all_containers ⇒ Object
141
142
143
|
# File 'lib/docker.rb', line 141
def all_containers
`docker ps -a`.split("\n")[1..-1]
end
|
#build(app_path, image_tag = nil) ⇒ Object
46
47
48
49
50
|
# File 'lib/docker.rb', line 46
def build(app_path, image_tag = nil)
path = PATH(app_path)
image_tag ||= path.name
Image.build(path, image_tag)
end
|
#containers(mode = :all) ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/docker.rb', line 122
def containers(mode = :all)
containers = case mode
when :all
all_containers
when :stopped
all_containers.select { |container| container =~ /Exited/ }
when :paused
all_containers.select { |container| container =~ /(Paused)/ }
when :running
`docker ps`.split("\n")[1..-1]
.select { |container| container !~ /(Paused)/}
else
raise ArgumentError, "Bad Argument: #{mode}"
end
containers.map do |container|
Container.new(container[0..11]).to_klass
end
end
|
#find_container(options = {}) ⇒ Object
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/docker.rb', line 97
def find_container(options = {})
validate_search_parameters(options)
containers.find do |container|
found = true
options.each do |option,value|
found = false unless container.send(option) == value
end
found
end
end
|
#find_containers(options = {}) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/docker.rb', line 108
def find_containers(options = {})
klass = options.delete(:klass)
validate_search_parameters(options)
kontainers = containers
kontainers.map! { |container| klass.load_from(container) } if klass
kontainers.select { |container|
found = true
options.each do |option, value|
found = false unless container.send(option) === value
end
found
}.compact
end
|
#find_image(options = {}) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/docker.rb', line 85
def find_image(options = {})
klass = options.delete(:klass) || :image
validate_search_parameters(options)
images(klass).find do |image|
found = true
options.each do |option,value|
found = false unless image.send(option) == value
end
found
end
end
|
#ID(input) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/docker.rb', line 27
def ID(input)
case input
when String
Id.create(input)
when ->(obj){obj.respond_to?(:id)}
Id.create(input.id)
end
end
|
#images(response_type = :image) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/docker.rb', line 57
def images(response_type = :image)
images = `docker images`.split("\n")[1..-1]
images.map do |image|
id = image.match(/^[^\s]+\s+[^\s]+\s+([^\s]+)/)[1]
repo = image.match(/^[a-zA-Z0-9\/\-_\.<>]+/)[0]
tag = image.match(/^[^\s]+\s+([^\s]+)/)[1]
case response_type
when :repository
Repository.new(id, repo)
when :tag
Tag.new(id, repo, tag)
when :image
Image.new(id)
end
end
end
|
#inspekt(id) ⇒ Object
74
75
76
77
|
# File 'lib/docker.rb', line 74
def inspekt(id)
inspekt = Inspect.new(id.to_s)
inspekt.inspekt ? inspekt : NullInspect.new
end
|
#PATH(input) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/docker.rb', line 36
def PATH(input)
case input
when String
Path.new(input)
when Path
input
end
end
|
#run(image, options = "", command = "") ⇒ Object
53
54
55
|
# File 'lib/docker.rb', line 53
def run(image, options = "", command = "")
Container.run(image.to_s, options, command)
end
|
#validate_search_parameters(options) ⇒ Object
79
80
81
82
83
|
# File 'lib/docker.rb', line 79
def validate_search_parameters(options)
bad_args = options.keys.select {|key| key.to_s.end_with?('!')}
raise ArgumentError, 'bang method given ' +
"as option: #{bad_args.join(', ')}" unless bad_args.empty?
end
|