docker-spoon 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48e180dd50e661fe9d869975261de629fe5f9070
4
- data.tar.gz: 1f174fedabb1d9aeb312fbc904015a70bd06efc9
3
+ metadata.gz: 8560cffb7fd59a8f21670b4e79b29d437b983ec2
4
+ data.tar.gz: afd021a9f0b9f3f636afa3300df0fd7f22c0ff20
5
5
  SHA512:
6
- metadata.gz: c7def17b9423ea439700b0ae123578d78531af13676b27d367bc21ca1b9f75084e8a0c8843736eabb9f36c6e5bcb44981f6fbc1f2be63197651434d485dfa2ca
7
- data.tar.gz: b72bc31f97a01047c739148ed21253f7bd7c36409194ee9241561f45332a2de0b4b0592ddfaa422522b2aeefb4148020c2d1cb177bda80156f5ef85e680f5727
6
+ metadata.gz: 429d54094e6d70341b226ec3a89696fc3ef6bae4860143612946b3fc27315025e465f06c9d5c4c0db1a0e0b8b7eb256e9d514d4eba088b5e3b3a11df87585355
7
+ data.tar.gz: 8143c4d158264afa614b17b820cd0363e9483f43ea6a366b0ecadaa9da996063af07b5c68bdb6c4adbabc7e6940dfb164b2f90269e2c4d21aea0b1e3954a449d
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  results.html
3
3
  pkg
4
4
  html
5
- *.gem
5
+ *.gem
6
+ .spoonrc #used for testing
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docker-spoon (0.5.0)
4
+ docker-spoon (0.6.0)
5
5
  docker-api (~> 1.11)
6
6
  methadone (~> 1.4.0)
7
7
  rainbow (~> 2.0)
@@ -10,26 +10,26 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  archive-tar-minitar (0.5.2)
13
- aruba (0.6.0)
13
+ aruba (0.6.1)
14
14
  childprocess (>= 0.3.6)
15
15
  cucumber (>= 1.1.1)
16
16
  rspec-expectations (>= 2.7.0)
17
17
  builder (3.2.2)
18
18
  childprocess (0.5.3)
19
19
  ffi (~> 1.0, >= 1.0.11)
20
- cucumber (1.3.15)
20
+ cucumber (1.3.17)
21
21
  builder (>= 2.1.2)
22
22
  diff-lcs (>= 1.1.3)
23
23
  gherkin (~> 2.12)
24
24
  multi_json (>= 1.7.5, < 2.0)
25
25
  multi_test (>= 0.1.1)
26
26
  diff-lcs (1.2.5)
27
- docker-api (1.13.1)
27
+ docker-api (1.13.3)
28
28
  archive-tar-minitar
29
29
  excon (>= 0.38.0)
30
30
  json
31
- excon (0.38.0)
32
- ffi (1.9.3)
31
+ excon (0.39.6)
32
+ ffi (1.9.5)
33
33
  gherkin (2.12.2)
34
34
  multi_json (~> 1.3)
35
35
  json (1.8.1)
@@ -39,12 +39,12 @@ GEM
39
39
  multi_test (0.1.1)
40
40
  rainbow (2.0.0)
41
41
  rake (0.9.6)
42
- rdoc (4.1.1)
42
+ rdoc (4.1.2)
43
43
  json (~> 1.4)
44
- rspec-expectations (3.0.3)
44
+ rspec-expectations (3.1.2)
45
45
  diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.0.0)
47
- rspec-support (3.0.3)
46
+ rspec-support (~> 3.1.0)
47
+ rspec-support (3.1.1)
48
48
 
49
49
  PLATFORMS
50
50
  ruby
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # docker-spoon
2
2
 
3
3
  ## Overview
4
- Spoon creates on demand pairing environments using Docker.
4
+ Spoon creates on demand pairing environments using Docker.
5
5
 
6
6
  We pair a lot using tmux & emacs / vim and wanted a way to create
7
7
  pairing environments which met a few criteria:
@@ -11,7 +11,7 @@ pairing environments which met a few criteria:
11
11
  environments and asking who's using what
12
12
  - Are console based to enable low latency remote pairing
13
13
 
14
- Spoon is intended to make this process as easy as possible.
14
+ Spoon is intended to make this process as easy as possible.
15
15
 
16
16
  #### Why Spoon?
17
17
  [Learn more about spooning](https://www.youtube.com/watch?v=dYBjVTMUQY0)
@@ -42,10 +42,10 @@ All of the `options[]` parameters should map directly to the long form
42
42
  of options on the command line. They may be defined as either the
43
43
  `:symbol` form or as a string. The limitation is that ruby doesn't
44
44
  permit a dash in symbols, so when an option has a dash in it, it must be
45
- specified as a string.
45
+ specified as a string.
46
46
 
47
47
  You may also specify a different config file with the `--config`
48
- argument.
48
+ argument.
49
49
 
50
50
  ## Usage
51
51
 
@@ -65,7 +65,7 @@ the spoon container that you specify. If that container doesn't exist,
65
65
  spoon will create it for you. Once spoon either creates a container or
66
66
  determines that one already exists it will start an ssh connection to
67
67
  the host. This will shell out to ssh and should honor your ssh
68
- configuration locally.
68
+ configuration locally.
69
69
 
70
70
  Example (container doesn't exist):
71
71
  ```shell
@@ -91,7 +91,7 @@ in.
91
91
  - `--url`, The url of the Docker API endpoint. This is in the format
92
92
  supported by the docker -H option. This will also read from the
93
93
  environment variable `DOCKER_HOST` if this argument is not specified
94
- and that env var exists.
94
+ and that env var exists.
95
95
  - `--image`, The image name to use when starting a spoon container.
96
96
  - `--prefix`, The prefix to use for creating, listing & destroying
97
97
  containers.
@@ -101,7 +101,7 @@ in.
101
101
  The `--list` argument will list any containers on the destination Docker
102
102
  host which have the same prefix as specified by `--prefix` (default
103
103
  'spoon-'). Images are listed without the prefix specified so that you
104
- can see only the containers you are interested in.
104
+ can see only the containers you are interested in.
105
105
 
106
106
  ```shell
107
107
  $ spoon -l
@@ -116,7 +116,7 @@ containers, spoon will re-start them as necessary.
116
116
 
117
117
  ### Destroy
118
118
 
119
- The `--destroy NAME` option will destroy the specified spoon container.
119
+ The `--destroy NAME` option will destroy the specified spoon container.
120
120
 
121
121
  ```shell
122
122
  $ spoon -d fortesting
@@ -143,12 +143,12 @@ The `--build` option will build a docker image from the build directory
143
143
  specified by `--builddir` (default '.'). This has the same expectations
144
144
  as the [docker
145
145
  build](https://docs.docker.com/reference/commandline/cli/#build)
146
- command.
146
+ command.
147
147
 
148
148
  #### Options
149
149
 
150
150
  - `--builddir`, This is the directory where the build process will look
151
- for a Dockerfile and any content added to the container using `ADD`.
151
+ for a Dockerfile and any content added to the container using `ADD`.
152
152
 
153
153
  - `--pre-build-commands`, This is a list of commands to run before
154
154
  actually kicking off the build process (see below).
@@ -161,7 +161,7 @@ copying stuff into the container which you don't want to have committed
161
161
  to the repository. An example of this is that in our environment we need
162
162
  chef credentials inside of our container & we use this mechanism to copy
163
163
  those credentials into the builddir at build time without adding them to
164
- our repository containing the Dockerfile.
164
+ our repository containing the Dockerfile.
165
165
 
166
166
  Here's an example of how we copy our chef configuration into place:
167
167
  ```ruby
@@ -170,6 +170,34 @@ options["pre-build-commands"] = [
170
170
  ]
171
171
  ```
172
172
 
173
+ - `copy_on_create`, - This is a config-only value, there is no command
174
+ line argument for it. The idea is that you can specify a list of files
175
+ to copy into place on the destination container upon creation. This is
176
+ useful if you want to copy in place configs that you keep on your
177
+ workstation but don't want them as part of the image.
178
+
179
+ Example:
180
+ ```
181
+ options[:copy_on_create] = [
182
+ ".gitconfig",
183
+ ".ssh",
184
+ ".ssh/config"
185
+ ]
186
+ ```
187
+ NOTE: this does not create any required parent directories on the
188
+ destination system unless they are copied into place, for example like
189
+ the .ssh directory in the example above.
190
+
191
+ - `add_authorized_keys` - This is a config-only value. This allows you
192
+ to specify an ssh public key that should reside in your own `~/.ssh`
193
+ directory to be placed in authorized_keys on the destination system
194
+ upon container creation.
195
+
196
+ Example:
197
+ ```
198
+ options[:add_authorized_keys] = "id_rsa.pub"
199
+ ```
200
+
173
201
  #### Container expectations
174
202
 
175
203
  When building an image for use with docker-spoon you must build an
@@ -12,6 +12,11 @@ module Spoon
12
12
 
13
13
  main do |instance|
14
14
 
15
+ # Read config file & set options
16
+ if File.exists?(options[:config])
17
+ eval(File.open(options[:config]).read)
18
+ end
19
+
15
20
  D options.inspect
16
21
  if options[:list]
17
22
  instance_list
@@ -43,6 +48,9 @@ module Spoon
43
48
  options[:builddir] = '.'
44
49
  on("--builddir DIR", "Directory containing Dockerfile")
45
50
  on("--pre-build-commands", "List of commands to run locally before building image")
51
+ # These are config only options
52
+ options[:copy_on_create] = []
53
+ options[:add_authorized_keys] = false
46
54
  options[:url] = Docker.url
47
55
  on("-u", "--url URL", "Docker url to connect to")
48
56
  on("-L", "--list-images", "List available spoon images")
@@ -52,13 +60,9 @@ module Spoon
52
60
  on("-p", "--prefix PREFIX", "Prefix for container names")
53
61
  options[:command] = ''
54
62
  options[:config] = "#{ENV['HOME']}/.spoonrc"
55
- on("-c", "--config FILE", "Config file to use for spoon options")
63
+ on("-c FILE", "--config", "Config file to use for spoon options")
56
64
  on("--debug", "Enable debug")
57
65
 
58
- # Read config file & set options
59
- if File.exists?(options[:config])
60
- eval(File.open(options[:config]).read)
61
- end
62
66
 
63
67
  arg(:instance, :optional, "Spoon instance to connect to")
64
68
 
@@ -123,6 +127,8 @@ module Spoon
123
127
  if not instance_exists? name
124
128
  puts "The `#{name}` container doesn't exist, creating..."
125
129
  instance_create(name)
130
+ instance_copy_authorized_keys(name, options[:add_authorized_keys])
131
+ instance_copy_files(name)
126
132
  end
127
133
 
128
134
  container = get_container(name)
@@ -138,7 +144,7 @@ module Spoon
138
144
  docker_url
139
145
  puts "List of available spoon containers:"
140
146
  container_list = get_all_containers.select { |c| c.info["Names"].first.to_s.start_with? "/#{options[:prefix]}" }
141
- .sort { |c1, c2| c1.info["Names"].first.to_s <=> c2.info["Names"].first.to_s }
147
+ .sort { |c1, c2| c1.info["Names"].first.to_s <=> c2.info["Names"].first.to_s }
142
148
  max_width_container_name = remove_prefix(container_list.max_by {|c| c.info["Names"].first.to_s.length }.info["Names"].first.to_s)
143
149
  max_name_width = max_width_container_name.length
144
150
  container_list.each do |container|
@@ -231,6 +237,36 @@ module Spoon
231
237
  end
232
238
  end
233
239
 
240
+ def self.instance_copy_authorized_keys(name, keyfile)
241
+ if keyfile
242
+ container = get_container(name)
243
+ host = URI.parse(options[:url]).host
244
+ key = File.read("#{ENV['HOME']}/.ssh/#{keyfile}")
245
+ if container
246
+ ssh_port = get_port('22', container)
247
+ puts "Waiting for #{name}:#{ssh_port}..." until host_available?(host, ssh_port)
248
+ system("ssh -t -o StrictHostKeyChecking=no -p #{ssh_port} pairing@#{host} \"mkdir -p .ssh && chmod 700 .ssh && echo '#{key}' >> ~/.ssh/authorized_keys\"")
249
+ else
250
+ puts "No container named: #{container.inspect}"
251
+ end
252
+ end
253
+ end
254
+
255
+ def self.instance_copy_files(name)
256
+ options[:copy_on_create].each do |file|
257
+ puts "Copying file #{file}"
258
+ container = get_container(name)
259
+ host = URI.parse(options[:url]).host
260
+ if container
261
+ ssh_port = get_port('22', container)
262
+ puts "Waiting for #{name}:#{ssh_port}..." until host_available?(host, ssh_port)
263
+ system("scp -o StrictHostKeyChecking=no -P #{ssh_port} #{ENV['HOME']}/#{file} pairing@#{host}:#{file}")
264
+ else
265
+ puts "No container named: #{container.inspect}"
266
+ end
267
+ end
268
+ end
269
+
234
270
  def self.get_all_containers
235
271
  Docker::Container.all(:all => true)
236
272
  end
@@ -297,7 +333,4 @@ module Spoon
297
333
  go!
298
334
  end
299
335
 
300
- # option :debug, :type => :boolean, :default => true
301
-
302
-
303
- # private
336
+ # option :debug, :type => :boolean, :default => true
@@ -1,3 +1,3 @@
1
1
  module Spoon
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-spoon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Nichols
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler