docker-spoon 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile.lock +7 -7
- data/README.md +24 -0
- data/docker/Dockerfile +45 -24
- data/docker/resources/tmux.conf +99 -0
- data/docker/resources/zshrc.default +1 -1
- data/docker/runit-ssh/log/run +2 -0
- data/docker/{resources → runit-ssh}/run +0 -0
- data/docker-spoon.gemspec +1 -1
- data/lib/spoon/version.rb +1 -1
- data/lib/spoon.rb +98 -43
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44d1699d5dfe6932ecb60d0c9ab0da39f7d8aa9a
|
4
|
+
data.tar.gz: a8552620c5ee5b7ad52d08231f42ef7ad74d337f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2849495539fe5b88f718b2125d23251006142355bda39980d5c0eaa3d4065072ca6f50bdbc6a9653fc59b9dd9485fc2c76b287d4048fbb2b9a1de9501b0dd8c3
|
7
|
+
data.tar.gz: 00fea86de864e662b76ca61791e4a24cf7a6f62c39316fdd0f8219c7071cd0ddddba277f0091e581117d21e6ac23e7683eb12adae643fba6cf3060f1aae763e2
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
docker-spoon (0.
|
5
|
-
docker-api (~> 1.
|
4
|
+
docker-spoon (0.8.0)
|
5
|
+
docker-api (~> 1.13)
|
6
6
|
methadone (~> 1.4.0)
|
7
7
|
rainbow (~> 2.0)
|
8
8
|
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
cucumber (>= 1.1.1)
|
16
16
|
rspec-expectations (>= 2.7.0)
|
17
17
|
builder (3.2.2)
|
18
|
-
childprocess (0.5.
|
18
|
+
childprocess (0.5.5)
|
19
19
|
ffi (~> 1.0, >= 1.0.11)
|
20
20
|
cucumber (1.3.17)
|
21
21
|
builder (>= 2.1.2)
|
@@ -24,12 +24,12 @@ GEM
|
|
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.
|
27
|
+
docker-api (1.13.6)
|
28
28
|
archive-tar-minitar
|
29
29
|
excon (>= 0.38.0)
|
30
30
|
json
|
31
|
-
excon (0.
|
32
|
-
ffi (1.9.
|
31
|
+
excon (0.40.0)
|
32
|
+
ffi (1.9.6)
|
33
33
|
gherkin (2.12.2)
|
34
34
|
multi_json (~> 1.3)
|
35
35
|
json (1.8.1)
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
rspec-expectations (3.1.2)
|
45
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
46
|
rspec-support (~> 3.1.0)
|
47
|
-
rspec-support (3.1.
|
47
|
+
rspec-support (3.1.2)
|
48
48
|
|
49
49
|
PLATFORMS
|
50
50
|
ruby
|
data/README.md
CHANGED
@@ -95,6 +95,11 @@ in.
|
|
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.
|
98
|
+
- `--portforwards`, This is a space separated list of ports to forward
|
99
|
+
over ssh. The format is either `sourceport:destport` or just `sourceport`
|
100
|
+
in which case the same port will be used for source & destination.
|
101
|
+
Multiple port forwards may be separated by spaces, for exampe
|
102
|
+
`--portforwards '8080 8081:9090'`
|
98
103
|
|
99
104
|
### List
|
100
105
|
|
@@ -120,10 +125,16 @@ The `--destroy NAME` option will destroy the specified spoon container.
|
|
120
125
|
|
121
126
|
```shell
|
122
127
|
$ spoon -d fortesting
|
128
|
+
Are you sure you want to destroy spoon-fortesting? (y/n) y
|
123
129
|
Destroying spoon-fortesting
|
124
130
|
Done!
|
125
131
|
```
|
126
132
|
|
133
|
+
To skip any confirmations:
|
134
|
+
|
135
|
+
* add `-f` or `--force` to the command-line
|
136
|
+
* add `options[:force] = true` to your `.spoonrc`.
|
137
|
+
|
127
138
|
### Network
|
128
139
|
|
129
140
|
The `--network NAME` option will show the forwarded ports for a spoon
|
@@ -196,6 +207,19 @@ the .ssh directory in the example above.
|
|
196
207
|
Example:
|
197
208
|
```
|
198
209
|
options[:add_authorized_keys] = "id_rsa.pub"
|
210
|
+
```
|
211
|
+
|
212
|
+
`run_on_create` - This is a list of commands to run on a spoon container
|
213
|
+
once it has been started. This allows you to quickly and automatically
|
214
|
+
modify a spoon environment upon creation to meet any needs you have
|
215
|
+
which aren't baked into the Docker image. This is a config-only
|
216
|
+
option, there is no command line for this. Commands are run one at a
|
217
|
+
time over ssh - enabling :add_authorized_keys makes this option more
|
218
|
+
tolerable.
|
219
|
+
|
220
|
+
Example:
|
221
|
+
```
|
222
|
+
options[:run_on_create] = [ "sudo apt-get -y install emacs" ]
|
199
223
|
```
|
200
224
|
|
201
225
|
#### Container expectations
|
data/docker/Dockerfile
CHANGED
@@ -3,28 +3,31 @@ FROM ubuntu:14.04
|
|
3
3
|
RUN locale-gen en_US.UTF-8
|
4
4
|
RUN apt-get update
|
5
5
|
RUN apt-get install -y python-software-properties
|
6
|
-
RUN apt-get install -y software-properties-common
|
7
|
-
RUN apt-get install -y python-setuptools
|
6
|
+
RUN apt-get install -y software-properties-common
|
7
|
+
RUN apt-get install -y python-setuptools
|
8
8
|
RUN add-apt-repository ppa:webupd8team/java
|
9
9
|
RUN apt-get update
|
10
|
-
RUN apt-get install -y zip
|
10
|
+
RUN apt-get install -y zip
|
11
11
|
RUN apt-get install -y openssl
|
12
|
-
RUN apt-get install -y git
|
13
|
-
RUN apt-get install -y emacs24
|
14
|
-
RUN apt-get install -y tmux
|
15
|
-
RUN apt-get install -y ack-grep
|
16
|
-
RUN apt-get install -y python
|
17
|
-
RUN apt-get install -y wget
|
18
|
-
RUN apt-get install -y xsel
|
19
|
-
RUN apt-get install -y python-pip
|
20
|
-
RUN apt-get install -y zsh
|
21
|
-
RUN apt-get install -y curl
|
22
|
-
RUN apt-get install -y build-essential
|
23
|
-
RUN apt-get install -y runit
|
24
|
-
RUN apt-get install -y openssh-server
|
25
|
-
RUN apt-get install -y ruby
|
12
|
+
RUN apt-get install -y git
|
13
|
+
RUN apt-get install -y emacs24
|
14
|
+
RUN apt-get install -y tmux
|
15
|
+
RUN apt-get install -y ack-grep
|
16
|
+
RUN apt-get install -y python
|
17
|
+
RUN apt-get install -y wget
|
18
|
+
RUN apt-get install -y xsel
|
19
|
+
RUN apt-get install -y python-pip
|
20
|
+
RUN apt-get install -y zsh
|
21
|
+
RUN apt-get install -y curl
|
22
|
+
RUN apt-get install -y build-essential
|
23
|
+
RUN apt-get install -y runit
|
24
|
+
RUN apt-get install -y openssh-server
|
25
|
+
RUN apt-get install -y ruby
|
26
26
|
RUN apt-get install -y tree
|
27
27
|
RUN apt-get install -y vim
|
28
|
+
RUN apt-get install -y libevent-dev
|
29
|
+
RUN apt-get install -y ncurses-dev
|
30
|
+
RUN apt-get install -y rake
|
28
31
|
|
29
32
|
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
|
30
33
|
RUN echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
|
@@ -34,20 +37,38 @@ RUN apt-get -y install oracle-java7-installer
|
|
34
37
|
RUN easy_install httpie
|
35
38
|
RUN pip install https://github.com/Lokaltog/powerline/tarball/develop
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
RUN
|
40
|
+
# Tmux
|
41
|
+
RUN wget http://downloads.sourceforge.net/tmux/tmux-1.9a.tar.gz
|
42
|
+
RUN tar -zxf tmux-1.9a.tar.gz
|
43
|
+
RUN cd tmux-1.9a && ./configure && make install
|
44
|
+
RUN rm -r /tmux-1.9a*
|
45
|
+
RUN pip install --upgrade --user git+git://github.com/Lokaltog/powerline
|
42
46
|
|
43
47
|
RUN useradd -s /bin/zsh -m -d /home/pairing -g root pairing
|
44
48
|
RUN echo "pairing:pairing" | chpasswd
|
45
49
|
RUN echo "pairing ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
46
50
|
|
47
|
-
|
51
|
+
USER pairing
|
52
|
+
ENV HOME /home/pairing
|
53
|
+
RUN git clone https://github.com/robbyrussell/oh-my-zsh.git /home/pairing/.oh-my-zsh
|
54
|
+
RUN chown -R pairing /home/pairing/.oh-my-zsh
|
48
55
|
|
56
|
+
RUN git clone https://github.com/adnichols/tmux-and-vim.git /home/pairing/.janus
|
57
|
+
RUN bash -l -c /home/pairing/.janus/setup/setup.sh
|
58
|
+
# Fixup powerline for this setup
|
59
|
+
RUN sed -i 's%/usr/local/lib/python2\.7/site-packages%/usr/local/lib/python2.7/dist-packages%' ~/.tmux.conf
|
60
|
+
ADD resources/zshrc.default /home/pairing/.zshrc
|
49
61
|
RUN mkdir /home/pairing/projects
|
50
62
|
|
63
|
+
USER root
|
64
|
+
|
65
|
+
# Runit setup
|
66
|
+
RUN mkdir -p /etc/service
|
67
|
+
ADD runit-ssh /etc/service/ssh
|
68
|
+
ADD runit /etc/runit
|
69
|
+
|
70
|
+
RUN mkdir -p /var/run/sshd
|
71
|
+
|
51
72
|
EXPOSE 22
|
52
73
|
|
53
|
-
|
74
|
+
CMD /usr/sbin/sshd -D -o UsePAM=no
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Last modified: 2009-11-12T05:59:41+0800
|
2
|
+
# Change prefix key to Ctrl+a
|
3
|
+
unbind C-b
|
4
|
+
set -g prefix `
|
5
|
+
bind-key ` send-prefix
|
6
|
+
bind-key -n F11 set -g prefix C-o
|
7
|
+
bind-key -n F12 set -g prefix `
|
8
|
+
|
9
|
+
# Last active window
|
10
|
+
unbind l
|
11
|
+
bind C-a last-window
|
12
|
+
bind C-p previous-window
|
13
|
+
bind C-n next-window
|
14
|
+
|
15
|
+
set -g mode-mouse on
|
16
|
+
set -g mode-keys vi
|
17
|
+
bind-key -t vi-copy v begin-selection
|
18
|
+
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
|
19
|
+
unbind -t vi-copy Enter
|
20
|
+
bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"
|
21
|
+
|
22
|
+
set -g mouse-select-window on
|
23
|
+
set -g mouse-select-pane on
|
24
|
+
set -g mouse-resize-pane on
|
25
|
+
set -g xterm-keys on
|
26
|
+
set-window-option -g xterm-keys on
|
27
|
+
set-option -g mouse-utf8 on
|
28
|
+
set-option -g default-terminal screen-256color
|
29
|
+
|
30
|
+
# More straight forward key bindings for splitting
|
31
|
+
bind-key | split-window -h
|
32
|
+
bind-key - split-window -v
|
33
|
+
|
34
|
+
# Smart pane switching with awareness of vim splits
|
35
|
+
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys C-h) || tmux select-pane -L"
|
36
|
+
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys C-j) || tmux select-pane -D"
|
37
|
+
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys C-k) || tmux select-pane -U"
|
38
|
+
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys C-l) || tmux select-pane -R"
|
39
|
+
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys 'C-\\') || tmux select-pane -l"
|
40
|
+
|
41
|
+
bind C-l send-keys 'C-l'
|
42
|
+
bind-key C-o rotate-window
|
43
|
+
|
44
|
+
set-window-option -g other-pane-height 25
|
45
|
+
set-window-option -g other-pane-width 80
|
46
|
+
|
47
|
+
bind-key C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
|
48
|
+
bind-key C-v run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"
|
49
|
+
|
50
|
+
set-option -g display-panes-time 1500
|
51
|
+
#set-option -g default-command "reattach-to-user-namespace -l zsh"
|
52
|
+
set-option -g default-command "/bin/bash -c 'which reattach-to-user-namespace >/dev/null && exec reattach-to-user-namespace $SHELL -l || exec $SHELL -l'"
|
53
|
+
|
54
|
+
set-option -g lock-server on
|
55
|
+
set-option -g lock-command 'vlock'
|
56
|
+
set-option -g lock-after-time 1800
|
57
|
+
bind-key C-x lock-server
|
58
|
+
|
59
|
+
# History
|
60
|
+
set -g history-limit 100000
|
61
|
+
|
62
|
+
# Terminal emulator window title
|
63
|
+
set -g set-titles on
|
64
|
+
set -g set-titles-string '#S:#I.#P #W'
|
65
|
+
|
66
|
+
# Status Bar 1.8 format
|
67
|
+
# set-option -g status-bg black
|
68
|
+
# set-option -g status-fg cyan
|
69
|
+
|
70
|
+
# Status Bar 1.9 format
|
71
|
+
set-option -g status-style "bg=black"
|
72
|
+
set-option -g status-style "fg=cyan"
|
73
|
+
|
74
|
+
# Notifying if other windows has activities
|
75
|
+
set -g monitor-activity off
|
76
|
+
set -g visual-activity on
|
77
|
+
|
78
|
+
# Highlighting the active window in status bar (1.8)
|
79
|
+
# setw -g window-status-current-bg blue
|
80
|
+
# setw -g window-status-current-fg white
|
81
|
+
|
82
|
+
# Highlighting the active window in status bar (1.9
|
83
|
+
setw -g window-status-current-style "bg=blue"
|
84
|
+
setw -g window-status-current-style "fg=white"
|
85
|
+
|
86
|
+
# Highlight active window on screen
|
87
|
+
set-option -g pane-active-border-fg colour32 # light blue
|
88
|
+
|
89
|
+
# Clock
|
90
|
+
setw -g clock-mode-colour green
|
91
|
+
setw -g clock-mode-style 24
|
92
|
+
setw -g aggressive-resize on
|
93
|
+
set -g base-index 1
|
94
|
+
bind-key S command-prompt -p ssh: "new-window -n %1 'ssh %1'"
|
95
|
+
set -g update-environment -r
|
96
|
+
set-environment -gu RBENV_VERSION
|
97
|
+
|
98
|
+
# Powerline
|
99
|
+
source /usr/local/lib/python2.7/site-packages/powerline/bindings/tmux/powerline.conf
|
@@ -5,7 +5,7 @@ ZSH=$HOME/.oh-my-zsh
|
|
5
5
|
# Look in ~/.oh-my-zsh/themes/
|
6
6
|
# Optionally, if you set this to "random", it'll load a random theme each
|
7
7
|
# time that oh-my-zsh is loaded.
|
8
|
-
ZSH_THEME="
|
8
|
+
ZSH_THEME="robbyrussell"
|
9
9
|
|
10
10
|
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
|
11
11
|
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
|
File without changes
|
data/docker-spoon.gemspec
CHANGED
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency('aruba')
|
25
25
|
spec.add_development_dependency('rake', '~> 0.9.2')
|
26
26
|
spec.add_dependency('methadone', '~> 1.4.0')
|
27
|
-
spec.add_dependency('docker-api', '~> 1.
|
27
|
+
spec.add_dependency('docker-api', '~> 1.13')
|
28
28
|
spec.add_dependency('rainbow', '~> 2.0')
|
29
29
|
end
|
data/lib/spoon/version.rb
CHANGED
data/lib/spoon.rb
CHANGED
@@ -12,11 +12,6 @@ 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
|
-
|
20
15
|
D options.inspect
|
21
16
|
if options[:list]
|
22
17
|
instance_list
|
@@ -45,29 +40,49 @@ module Spoon
|
|
45
40
|
on("-n", "--network NAME", "Display exposed ports using name passed to NAME")
|
46
41
|
|
47
42
|
# Configurables
|
48
|
-
options[:
|
43
|
+
options[:config] ||= "#{ENV['HOME']}/.spoonrc"
|
44
|
+
on("-c FILE", "--config", "Config file to use for spoon options")
|
45
|
+
|
46
|
+
# Read config file & set options
|
47
|
+
if File.exists?(options[:config])
|
48
|
+
eval(File.open(options[:config]).read)
|
49
|
+
end
|
50
|
+
|
51
|
+
options[:builddir] ||= '.'
|
49
52
|
on("--builddir DIR", "Directory containing Dockerfile")
|
50
53
|
on("--pre-build-commands", "List of commands to run locally before building image")
|
51
54
|
# These are config only options
|
52
|
-
options[:copy_on_create]
|
53
|
-
options[:
|
54
|
-
options[:
|
55
|
+
options[:copy_on_create] ||= []
|
56
|
+
options[:run_on_create] ||= []
|
57
|
+
options[:add_authorized_keys] ||= false
|
58
|
+
options[:url] ||= Docker.url
|
55
59
|
on("-u", "--url URL", "Docker url to connect to")
|
56
60
|
on("-L", "--list-images", "List available spoon images")
|
57
|
-
options[:image]
|
61
|
+
options[:image] ||= "spoon-pairing"
|
58
62
|
on("-i", "--image NAME", "Use image for spoon instance")
|
59
|
-
options[:prefix]
|
63
|
+
options[:prefix] ||= 'spoon-'
|
60
64
|
on("-p", "--prefix PREFIX", "Prefix for container names")
|
61
|
-
options[:command]
|
62
|
-
|
63
|
-
on("-c FILE", "--config", "Config file to use for spoon options")
|
65
|
+
options[:command] ||= ''
|
66
|
+
on("-f", "--force", "Skip any confirmations")
|
64
67
|
on("--debug", "Enable debug")
|
68
|
+
on("--debugssh", "Enable SSH debugging")
|
69
|
+
on("-P PORT", "--portforwards", "Forward PORT over ssh (must be > 1023)")
|
65
70
|
|
66
71
|
|
67
72
|
arg(:instance, :optional, "Spoon instance to connect to")
|
68
73
|
|
69
74
|
use_log_level_option
|
70
75
|
|
76
|
+
def self.confirm_delete?(name)
|
77
|
+
if options[:force]
|
78
|
+
return true
|
79
|
+
else
|
80
|
+
print "Are you sure you want to delete #{name}? (y/n) "
|
81
|
+
answer = $stdin.gets.chomp.downcase
|
82
|
+
return answer == "y"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
71
86
|
def self.apply_prefix(name)
|
72
87
|
"#{options[:prefix]}#{name}"
|
73
88
|
end
|
@@ -129,6 +144,7 @@ module Spoon
|
|
129
144
|
instance_create(name)
|
130
145
|
instance_copy_authorized_keys(name, options[:add_authorized_keys])
|
131
146
|
instance_copy_files(name)
|
147
|
+
instance_run_actions(name)
|
132
148
|
end
|
133
149
|
|
134
150
|
container = get_container(name)
|
@@ -143,8 +159,11 @@ module Spoon
|
|
143
159
|
def self.instance_list
|
144
160
|
docker_url
|
145
161
|
puts "List of available spoon containers:"
|
146
|
-
container_list =
|
147
|
-
|
162
|
+
container_list = get_spoon_containers
|
163
|
+
if container_list.empty?
|
164
|
+
puts "No spoon containers running at #{options[:url]}"
|
165
|
+
exit
|
166
|
+
end
|
148
167
|
max_width_container_name = remove_prefix(container_list.max_by {|c| c.info["Names"].first.to_s.length }.info["Names"].first.to_s)
|
149
168
|
max_name_width = max_width_container_name.length
|
150
169
|
container_list.each do |container|
|
@@ -200,21 +219,25 @@ module Spoon
|
|
200
219
|
container = get_container(name)
|
201
220
|
|
202
221
|
if container
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
222
|
+
if confirm_delete?(name)
|
223
|
+
puts "Destroying #{name}"
|
224
|
+
begin
|
225
|
+
container.kill
|
226
|
+
rescue
|
227
|
+
puts "Failed to kill container #{container.id}"
|
228
|
+
end
|
209
229
|
|
210
|
-
|
230
|
+
container.wait(10)
|
211
231
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
232
|
+
begin
|
233
|
+
container.delete(:force => true)
|
234
|
+
rescue
|
235
|
+
puts "Failed to remove container #{container.id}"
|
236
|
+
end
|
237
|
+
puts "Done!"
|
238
|
+
else
|
239
|
+
puts "Delete aborted.. #{name} lives to pair another day."
|
216
240
|
end
|
217
|
-
puts "Done!"
|
218
241
|
else
|
219
242
|
puts "No container named: #{name}"
|
220
243
|
end
|
@@ -224,37 +247,55 @@ module Spoon
|
|
224
247
|
get_container(name)
|
225
248
|
end
|
226
249
|
|
227
|
-
def self.
|
250
|
+
def self.get_port_forwards(forwards = "")
|
251
|
+
if options[:portforwards]
|
252
|
+
options[:portforwards].split.each do |port|
|
253
|
+
(lport,rport) = port.split(':')
|
254
|
+
forwards << "-L #{lport}:127.0.0.1:#{rport || lport} "
|
255
|
+
end
|
256
|
+
end
|
257
|
+
return forwards
|
258
|
+
end
|
259
|
+
|
260
|
+
def self.instance_ssh(name, command='', exec=true)
|
228
261
|
container = get_container(name)
|
262
|
+
forwards = get_port_forwards
|
263
|
+
D "Got forwards: #{forwards}"
|
229
264
|
host = URI.parse(options[:url]).host
|
230
265
|
if container
|
231
266
|
ssh_command = "\"#{command}\"" if not command.empty?
|
232
267
|
ssh_port = get_port('22', container)
|
233
268
|
puts "Waiting for #{name}:#{ssh_port}..." until host_available?(host, ssh_port)
|
234
|
-
|
269
|
+
ssh_options = "-t -o StrictHostKeyChecking=no -p #{ssh_port} #{forwards} "
|
270
|
+
ssh_options << "-v " if options[:debugssh]
|
271
|
+
ssh_cmd = "ssh #{ssh_options} pairing@#{host} #{ssh_command}"
|
272
|
+
D "SSH CMD: #{ssh_cmd}"
|
273
|
+
if exec
|
274
|
+
exec(ssh_cmd)
|
275
|
+
else
|
276
|
+
system(ssh_cmd)
|
277
|
+
end
|
235
278
|
else
|
236
279
|
puts "No container named: #{container.inspect}"
|
237
280
|
end
|
238
281
|
end
|
239
282
|
|
240
283
|
def self.instance_copy_authorized_keys(name, keyfile)
|
284
|
+
D "Setting up authorized_keys file"
|
285
|
+
# We sleep this once to cope w/ slow starting ssh daemon on create
|
286
|
+
sleep 1
|
241
287
|
if keyfile
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
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
|
288
|
+
full_keyfile = "#{ENV['HOME']}/.ssh/#{keyfile}"
|
289
|
+
key = File.read(full_keyfile).chop
|
290
|
+
D "Read keyfile `#{full_keyfile}` with contents:\n#{key}"
|
291
|
+
cmd = "mkdir -p .ssh ; chmod 700 .ssh ; echo '#{key}' >> .ssh/authorized_keys"
|
292
|
+
instance_ssh(name, cmd, false)
|
252
293
|
end
|
253
294
|
end
|
254
295
|
|
255
296
|
def self.instance_copy_files(name)
|
256
297
|
options[:copy_on_create].each do |file|
|
257
|
-
|
298
|
+
D "Copying file #{file}"
|
258
299
|
container = get_container(name)
|
259
300
|
host = URI.parse(options[:url]).host
|
260
301
|
if container
|
@@ -267,10 +308,26 @@ module Spoon
|
|
267
308
|
end
|
268
309
|
end
|
269
310
|
|
311
|
+
def self.instance_run_actions(name)
|
312
|
+
options[:run_on_create].each do |action|
|
313
|
+
puts "Running command: #{action}"
|
314
|
+
instance_ssh(name, action, false)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
270
318
|
def self.get_all_containers
|
271
319
|
Docker::Container.all(:all => true)
|
272
320
|
end
|
273
321
|
|
322
|
+
def self.get_spoon_containers
|
323
|
+
container_list = get_all_containers.select { |c| c.info["Names"].first.to_s.start_with? "/#{options[:prefix]}" }
|
324
|
+
unless container_list.empty?
|
325
|
+
return container_list.sort { |c1, c2| c1.info["Names"].first.to_s <=> c2.info["Names"].first.to_s }
|
326
|
+
else
|
327
|
+
return container_list
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
274
331
|
def self.get_running_containers
|
275
332
|
Docker::Container.all
|
276
333
|
end
|
@@ -332,5 +389,3 @@ module Spoon
|
|
332
389
|
|
333
390
|
go!
|
334
391
|
end
|
335
|
-
|
336
|
-
# option :debug, :type => :boolean, :default => true
|
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.
|
4
|
+
version: 0.8.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-
|
11
|
+
date: 2014-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - ~>
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '1.
|
103
|
+
version: '1.13'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '1.
|
110
|
+
version: '1.13'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rainbow
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,8 +140,10 @@ files:
|
|
140
140
|
- docker-spoon.gemspec
|
141
141
|
- docker/Dockerfile
|
142
142
|
- docker/resources/log/run
|
143
|
-
- docker/resources/
|
143
|
+
- docker/resources/tmux.conf
|
144
144
|
- docker/resources/zshrc.default
|
145
|
+
- docker/runit-ssh/log/run
|
146
|
+
- docker/runit-ssh/run
|
145
147
|
- docker/runit/1
|
146
148
|
- docker/runit/2
|
147
149
|
- docker/runit/3
|