docker-spoon 0.1.0 → 0.2.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.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  results.html
3
3
  pkg
4
4
  html
5
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docker-spoon (0.1.0)
4
+ docker-spoon (0.1.1)
5
5
  docker-api (~> 1.11)
6
6
  methadone (~> 1.4.0)
7
7
 
@@ -9,7 +9,7 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  archive-tar-minitar (0.5.2)
12
- aruba (0.5.4)
12
+ aruba (0.6.0)
13
13
  childprocess (>= 0.3.6)
14
14
  cucumber (>= 1.1.1)
15
15
  rspec-expectations (>= 2.7.0)
@@ -23,11 +23,11 @@ GEM
23
23
  multi_json (>= 1.7.5, < 2.0)
24
24
  multi_test (>= 0.1.1)
25
25
  diff-lcs (1.2.5)
26
- docker-api (1.11.2)
26
+ docker-api (1.13.1)
27
27
  archive-tar-minitar
28
- excon (>= 0.37.0)
28
+ excon (>= 0.38.0)
29
29
  json
30
- excon (0.37.0)
30
+ excon (0.38.0)
31
31
  ffi (1.9.3)
32
32
  gherkin (2.12.2)
33
33
  multi_json (~> 1.3)
@@ -39,10 +39,10 @@ GEM
39
39
  rake (0.9.6)
40
40
  rdoc (4.1.1)
41
41
  json (~> 1.4)
42
- rspec-expectations (3.0.2)
42
+ rspec-expectations (3.0.3)
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
44
  rspec-support (~> 3.0.0)
45
- rspec-support (3.0.2)
45
+ rspec-support (3.0.3)
46
46
 
47
47
  PLATFORMS
48
48
  ruby
data/README.md CHANGED
@@ -16,8 +16,6 @@ Spoon is intended to make this process as easy as possible.
16
16
  #### Why Spoon?
17
17
  [Learn more about spooning](https://www.youtube.com/watch?v=dYBjVTMUQY0)
18
18
 
19
- In the mean time - [learn more about spooning](https://www.youtube.com/watch?v=dYBjVTMUQY0)
20
-
21
19
  ## Installation
22
20
 
23
21
  ```
@@ -151,9 +149,9 @@ options["pre-build-commands"] = [
151
149
 
152
150
  #### Container expectations
153
151
 
154
- When building a container for use with docker-spoon you must build a
155
- container which runs an ssh daemon. An example of a Dockerfile which
156
- creates a container which runs ssh is included in the `docker/`
152
+ When building an image for use with docker-spoon you must build an
153
+ image which runs an ssh daemon. An example of a Dockerfile which
154
+ creates an image which runs ssh is included in the `docker/`
157
155
  directory inside this repository
158
156
 
159
157
  ## Contributing
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["anichols@trumped.org"]
11
11
  spec.summary = %q{Create on-demand pairing environments in Docker}
12
12
  spec.description = %q{Create on-demand pairing environments in Docker}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/adnichols/docker-spoon"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -10,4 +10,15 @@ Feature: My bootstrapped app kinda works
10
10
  And the banner should document that this app takes options
11
11
  And the following options should be documented:
12
12
  |--version|
13
- And the banner should document that this app takes no arguments
13
+ |--list|
14
+ |--destroy|
15
+ |--build|
16
+ |--builddir|
17
+ |--pre-build-commands|
18
+ |--url|
19
+ |--list-images|
20
+ |--image|
21
+ |--network|
22
+ |--prefix|
23
+ |--config|
24
+ |--debug|
data/lib/spoon.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require "spoon/version"
2
2
  require 'docker'
3
3
  require 'json'
4
- require 'pp'
5
4
  require 'uri'
6
5
 
7
6
  module Spoon
@@ -21,6 +20,8 @@ module Spoon
21
20
  image_build
22
21
  elsif options[:destroy]
23
22
  instance_destroy(apply_prefix(options[:destroy]))
23
+ elsif options[:network]
24
+ instance_network(apply_prefix(options[:network]))
24
25
  elsif instance
25
26
  instance_connect(apply_prefix(instance), options[:command])
26
27
  else
@@ -35,6 +36,7 @@ module Spoon
35
36
  on("-l", "--list", "List available spoon instances")
36
37
  on("-d", "--destroy NAME", "Destroy spoon instance with NAME")
37
38
  on("-b", "--build", "Build image from Dockerfile using name passed to --image")
39
+ on("-n", "--network NAME", "Display exposed ports using name passed to NAME")
38
40
 
39
41
  # Configurables
40
42
  options[:builddir] = '.'
@@ -76,7 +78,7 @@ module Spoon
76
78
  # Run pre-build commands
77
79
  options["pre-build-commands"].each do |command|
78
80
  sh command
79
- end
81
+ end unless options["pre-build-commands"].nil?
80
82
  D "pre-build commands complete, building Docker image"
81
83
 
82
84
  docker_url
@@ -123,6 +125,11 @@ module Spoon
123
125
  instance_create(name)
124
126
  end
125
127
 
128
+ container = get_container(name)
129
+ unless is_running?(container)
130
+ instance_start(container)
131
+ end
132
+
126
133
  puts "Connecting to `#{name}`"
127
134
  instance_ssh(name, command)
128
135
  end
@@ -130,12 +137,47 @@ module Spoon
130
137
  def self.instance_list
131
138
  docker_url
132
139
  puts "List of available spoon containers:"
133
- container_list = Docker::Container.all
140
+ container_list = get_all_containers
134
141
  container_list.each do |container|
135
142
  name = container.info["Names"].first.to_s
136
143
  if name.start_with? "/#{options[:prefix]}"
137
- puts remove_prefix(name)
144
+ running = is_running?(container) ? "Running" : "Stopped"
145
+ puts "#{remove_prefix(name)} [ #{running} ]".rjust(40)
146
+ end
147
+ end
148
+ end
149
+
150
+ def self.strip_slash(name)
151
+ if name.start_with? "/"
152
+ name[1..-1]
153
+ else
154
+ name
155
+ end
156
+ end
157
+
158
+ def self.is_running?(container)
159
+ container = Docker::Container.get(container.info["id"])
160
+ status = container.info["State"]["Running"] || nil
161
+ unless status.nil?
162
+ return status
163
+ else
164
+ return false
165
+ end
166
+ end
167
+
168
+ def self.instance_network(name)
169
+ docker_url
170
+
171
+ container = get_container(name)
172
+
173
+ if is_running?(container)
174
+ ports = container.json['NetworkSettings']['Ports']
175
+ ports.each do |p_name, p_port|
176
+ tcp_name = p_name.split('/')[0]
177
+ puts "#{tcp_name} -> #{p_port.first['HostPort']}"
138
178
  end
179
+ else
180
+ puts "Container is not running, cannot show ports"
139
181
  end
140
182
  end
141
183
 
@@ -181,12 +223,25 @@ module Spoon
181
223
  end
182
224
  end
183
225
 
226
+ def self.get_all_containers
227
+ Docker::Container.all(:all => true)
228
+ end
229
+
230
+ def self.get_running_containers
231
+ Docker::Container.all
232
+ end
233
+
234
+ def self.instance_start(container)
235
+ container.start!
236
+ end
237
+
184
238
  def self.get_container(name)
185
239
  docker_url
186
- container_list = Docker::Container.all
240
+ container_list = get_all_containers
187
241
 
242
+ l_name = strip_slash(name)
188
243
  container_list.each do |container|
189
- if container.info["Names"].first.to_s == "/#{name}"
244
+ if container.info["Names"].first.to_s == "/#{l_name}"
190
245
  return container
191
246
  end
192
247
  end
data/lib/spoon/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spoon
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-spoon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-28 00:00:00.000000000 Z
12
+ date: 2014-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -138,6 +138,7 @@ files:
138
138
  - README.md
139
139
  - Rakefile
140
140
  - bin/spoon
141
+ - docker-spoon.gemspec
141
142
  - docker/Dockerfile
142
143
  - docker/resources/log/run
143
144
  - docker/resources/run
@@ -150,9 +151,8 @@ files:
150
151
  - features/support/env.rb
151
152
  - lib/spoon.rb
152
153
  - lib/spoon/version.rb
153
- - spoon.gemspec
154
154
  - test/tc_something.rb
155
- homepage: ''
155
+ homepage: https://github.com/adnichols/docker-spoon
156
156
  licenses:
157
157
  - MIT
158
158
  post_install_message: