vagrant-docker-exec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +3 -0
- data/lib/vagrant-docker-exec.rb +17 -0
- data/lib/vagrant-docker-exec/command/exec.rb +85 -0
- data/lib/vagrant-docker-exec/command/shell.rb +42 -0
- data/lib/vagrant-docker-exec/plugin.rb +31 -0
- data/lib/vagrant-docker-exec/version.rb +5 -0
- data/locales/en.yml +9 -0
- data/vagrant-docker-exec.gemspec +23 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5198d96cebf4c78b519b45f40a017d51cb4dea26
|
4
|
+
data.tar.gz: 9c42a1eb45c0352c5e234871ad11dfc24268eb3b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b28359a1de1c549285c0c686ae95c6ec68bde4447c601affad0ac5c2a6dbd144d9f5b340a23bf42799bd3522b421b3b613b00acb17a4435dc17aeb319d7cd81c
|
7
|
+
data.tar.gz: 6199d68ef06414df4e53f90df2779a153aab5a5a6fa3a8a1f38decf6501f0fe5542ca86bd6cda0ef5043053dcf565644c538f043b0f08811e0ac76f18198509d
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 William Kolean
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# vagrant-docker-exec
|
2
|
+
|
3
|
+
This plugin allows you to run `docker exec` on a running container.
|
4
|
+
|
5
|
+
## Known Issues
|
6
|
+
|
7
|
+
Docker exec requires Docker 1.3.0 or higher. boot2docker provided by Vagrant is version 1.2 and does not support exec, so a proxy VM is required to use
|
8
|
+
this plugin until boot2docker is updated.
|
9
|
+
|
10
|
+
This plugin has been tested on Mac OS X.
|
11
|
+
|
12
|
+
## Getting Started
|
13
|
+
|
14
|
+
To install the plugin, run the following command:
|
15
|
+
```bash
|
16
|
+
vagrant plugin install vagrant-docker-exec
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```bash
|
22
|
+
vagrant docker-exec [options] [container] -- [command] [args]
|
23
|
+
```
|
24
|
+
--[no-]detach Run in the background
|
25
|
+
|
26
|
+
-t, --[no-]tty Open an interactive shell
|
27
|
+
|
28
|
+
To create a new file in a container named `nginx`
|
29
|
+
|
30
|
+
```bash
|
31
|
+
vagrant docker-exec nginx -- touch /var/www/html/test.html
|
32
|
+
```
|
33
|
+
|
34
|
+
To open an interactive shell in a conatiner named `nginx`
|
35
|
+
|
36
|
+
```bash
|
37
|
+
vagrant docker-exec -t nginx -- bash
|
38
|
+
```
|
39
|
+
|
40
|
+
To simplify opening a shell, you can use the shortcut `vagrant docker-shell [container]`
|
41
|
+
|
42
|
+
## Author
|
43
|
+
William Kolean william.kolean@gmail.com
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "vagrant-docker-exec/plugin"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module DockerExec
|
7
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-docker-exec", __FILE__))
|
8
|
+
#autoload :Errors, lib_path.join("errors")
|
9
|
+
|
10
|
+
# This returns the path to the source of this plugin.
|
11
|
+
#
|
12
|
+
# @return [Pathname]
|
13
|
+
def self.source_root
|
14
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerExec
|
3
|
+
class Command < Vagrant.plugin("2", "command")
|
4
|
+
def self.synopsis
|
5
|
+
"run a new command in a running docker container"
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
options = {}
|
10
|
+
options[:detach] = false
|
11
|
+
options[:pty] = false
|
12
|
+
|
13
|
+
opts = OptionParser.new do |o|
|
14
|
+
o.banner = "Usage: vagrant docker-exec [command...]"
|
15
|
+
o.separator ""
|
16
|
+
o.separator "Options:"
|
17
|
+
o.separator ""
|
18
|
+
|
19
|
+
o.on("--[no-]detach", "Run in the background") do |d|
|
20
|
+
options[:detach] = d
|
21
|
+
end
|
22
|
+
|
23
|
+
o.on("-t", "--[no-]tty", "Allocate a pty") do |t|
|
24
|
+
options[:pty] = t
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Parse out the extra args to send to SSH, which is everything
|
29
|
+
# after the "--"
|
30
|
+
command = nil
|
31
|
+
split_index = @argv.index("--")
|
32
|
+
if split_index
|
33
|
+
command = @argv.drop(split_index + 1)
|
34
|
+
@argv = @argv.take(split_index)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Parse the options
|
38
|
+
argv = parse_options(opts)
|
39
|
+
return if !argv
|
40
|
+
|
41
|
+
# Show the error if we don't have "--" _after_ parse_options
|
42
|
+
# so that "-h" and "--help" work properly.
|
43
|
+
if !split_index
|
44
|
+
@env.ui.error(I18n.t("vagrant_docker_exec.exec_command_required"))
|
45
|
+
return 1
|
46
|
+
end
|
47
|
+
|
48
|
+
target_opts = { provider: :docker }
|
49
|
+
target_opts[:single_target] = options[:pty]
|
50
|
+
|
51
|
+
with_target_vms(argv, target_opts) do |machine|
|
52
|
+
if machine.state.id != :running
|
53
|
+
@env.ui.info("#{machine.name} is not running.")
|
54
|
+
next
|
55
|
+
end
|
56
|
+
|
57
|
+
# Run it!
|
58
|
+
exec_command(machine, options, command)
|
59
|
+
end
|
60
|
+
|
61
|
+
return 0
|
62
|
+
end
|
63
|
+
|
64
|
+
def exec_command(machine, options, command)
|
65
|
+
|
66
|
+
exec_cmd = %W(docker exec)
|
67
|
+
exec_cmd << "-i" << "-t" if options[:pty]
|
68
|
+
exec_cmd << options[:name]
|
69
|
+
exec_cmd += options[:extra_args] if options[:extra_args]
|
70
|
+
exec_cmd.concat(command)
|
71
|
+
|
72
|
+
# Run this interactively if asked.
|
73
|
+
exec_options = options
|
74
|
+
exec_options[:stdin] = true if options[:pty]
|
75
|
+
|
76
|
+
output = ""
|
77
|
+
machine.provider.driver.execute(*cmd, exec_options) do |type, data|
|
78
|
+
output += data
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DockerExec
|
3
|
+
class Command < Vagrant.plugin("2", "command")
|
4
|
+
def self.synopsis
|
5
|
+
"open a shell in a running docker container"
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
options[:detach] = false
|
12
|
+
options[:pty] = true
|
13
|
+
options[:stdin] = true
|
14
|
+
|
15
|
+
opts = OptionParser.new do |o|
|
16
|
+
o.banner = "Usage: vagrant docker-shell [container]"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parse the options
|
20
|
+
argv = parse_options(opts)
|
21
|
+
return if !argv
|
22
|
+
|
23
|
+
target_opts = { provider: :docker }
|
24
|
+
target_opts[:single_target] = options[:pty]
|
25
|
+
|
26
|
+
with_target_vms(argv, target_opts) do |machine|
|
27
|
+
command = ["docker", "exec", "-it"]
|
28
|
+
command << machine.name.to_s
|
29
|
+
command << "bash"
|
30
|
+
|
31
|
+
output = ""
|
32
|
+
machine.provider.driver.execute(*command, options) do |type, data|
|
33
|
+
output += data
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
return 0
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "This plugin must run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module DockerExec
|
9
|
+
class Plugin < Vagrant.plugin("2")
|
10
|
+
name "docker-exec"
|
11
|
+
description "The vagrant-docker-exec plugin lets you run commands in a docker container"
|
12
|
+
|
13
|
+
command "docker-exec" do
|
14
|
+
require_relative "command/exec"
|
15
|
+
Command
|
16
|
+
end
|
17
|
+
|
18
|
+
command "docker-shell" do
|
19
|
+
require_relative "command/shell"
|
20
|
+
Command
|
21
|
+
end
|
22
|
+
|
23
|
+
# This initializes the internationalization strings.
|
24
|
+
def self.setup_i18n
|
25
|
+
I18n.load_path << File.expand_path("locales/en.yml", DockerExec.source_root)
|
26
|
+
I18n.reload!
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_docker_exec :
|
3
|
+
exec_command_required |-
|
4
|
+
`vagrant docker-exec` requires a command to execute. This command
|
5
|
+
must be specified after a `--` in the command line. This is used
|
6
|
+
to separate machine name and options from the actual command to
|
7
|
+
execute. An example is show below:
|
8
|
+
|
9
|
+
vagrant docker-exec web -- rails new .
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-docker-exec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-docker-exec"
|
8
|
+
spec.version = VagrantPlugins::DockerExec::VERSION
|
9
|
+
spec.authors = ["William Kolean"]
|
10
|
+
spec.email = ["william.kolean@gmail.com"]
|
11
|
+
spec.summary = %q{docker-exec runs a new command in a running container.}
|
12
|
+
spec.description = %q{Vagrant plugin adding the command docker-exec [options] container -- [command] which invokes `docker exec` to run a command in a running container.}
|
13
|
+
spec.homepage = "https://github.com/wkolean/vagrant-docker-exec"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-docker-exec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Kolean
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Vagrant plugin adding the command docker-exec [options] container --
|
42
|
+
[command] which invokes `docker exec` to run a command in a running container.
|
43
|
+
email:
|
44
|
+
- william.kolean@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- CHANGELOG.md
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/vagrant-docker-exec.rb
|
56
|
+
- lib/vagrant-docker-exec/command/exec.rb
|
57
|
+
- lib/vagrant-docker-exec/command/shell.rb
|
58
|
+
- lib/vagrant-docker-exec/plugin.rb
|
59
|
+
- lib/vagrant-docker-exec/version.rb
|
60
|
+
- locales/en.yml
|
61
|
+
- vagrant-docker-exec.gemspec
|
62
|
+
homepage: https://github.com/wkolean/vagrant-docker-exec
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.14
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: docker-exec runs a new command in a running container.
|
86
|
+
test_files: []
|