-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
184 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ gemspec | |
|
||
group :development do | ||
gem 'pry' | ||
gem 'pry-byebug' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apple: | ||
image: busybox | ||
command: /bin/sh -c 'sleep 3600' | ||
orange: | ||
image: busybox | ||
command: /bin/sh -c 'sleep 3600' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Docker::Compose | ||
class Collection < Array | ||
# @example find containers that are up | ||
# who_is_up = coll.where { |c| c.up? } | ||
# @example count space taken by all containers | ||
# coll.map { |c| c.size }.inject(0) { |a, x| a + x } | ||
def where | ||
hits = Collection.new | ||
self.each { |c| hits << c if yield(c) } | ||
hits | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Docker::Compose | ||
class Container | ||
PS_STATUS = /^([A-Za-z]+) ?\(?([0-9]*)\)? ?(.*)$/i | ||
|
||
attr_reader :id, :image, :size, :status, :exitstatus | ||
attr_reader :names, :labels, :ports, :mounts | ||
|
||
# @param [String] id | ||
# @param [String] image | ||
# @param [String,Numeric] size | ||
# @param [String,#map] status e.g. ['Exited', '0', '3 minutes ago'] | ||
# @param [String,#map] names | ||
# @param [String,#map] labels | ||
# @param [String,#map] ports | ||
# @param [String,#map] mounts | ||
def initialize(id, image, size, status, names, labels, ports, mounts) | ||
if size.is_a?(String) | ||
scalar, units = size.split(' ') | ||
scalar = size[0].to_i # lazy: invalid --> 0 | ||
mult = case units.downcase | ||
when 'b' then 1 | ||
when 'kb' then 1_024 | ||
when 'mb' then 1_024^2 | ||
when 'gb' then 1_024^3 | ||
when 'tb' then 1_024^4 | ||
else | ||
raise Error.new('Service#new', units, 'Impossibly large unit') | ||
end | ||
size = scalar * mult | ||
end | ||
|
||
if status.is_a?(String) | ||
status = PS_STATUS.match(status) | ||
raise Error.new('Service#new', status, 'Unrecognized status') unless status | ||
end | ||
|
||
names = names.split(',') if names.is_a?(String) | ||
labels = labels.split(',') if labels.is_a?(String) | ||
ports = ports.split(',') if ports.is_a?(String) | ||
mounts = ports.split(',') if mounts.is_a?(String) | ||
|
||
@id = id | ||
@image = image | ||
@size = size | ||
@status = status[1].downcase.to_sym | ||
@exitstatus = !status[2].empty? && status[2].to_i # sloppy! | ||
@names = names | ||
@labels = labels | ||
@ports = ports | ||
@mounts = mounts | ||
end | ||
|
||
# @return [String] | ||
def name | ||
names.first | ||
end | ||
|
||
# @return [Boolean] | ||
def up? | ||
self.status == :up | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) | ||
require 'docker/compose' | ||
|
||
begin | ||
require 'pry' | ||
rescue LoadError | ||
# bah! | ||
end |