dockerbash 0.1.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.
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at crawler8086@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dockerbash.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jordi Garcia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # Dockerbash
2
+
3
+ A very basic command line rubygem that makes easier to execute a bash into running Docker containers.
4
+
5
+ Sometimes when you are running docker containers, you need to inspect the status of services, files, configurations, this gem provides the ability to log into running containers using a GNU Bourne-Shell and debug the container from another shell.
6
+
7
+ ## Requirements
8
+
9
+ This command line tool has been developed and tested on Gnu/Linux environments, it won't run on Darwin (OS X) systems.
10
+
11
+ In order to run dockerbash, you must install the package that contains the header files for compiling extension modules for Ruby.
12
+
13
+ Based on DEB
14
+ ```
15
+ $ sudo apt-get install build-essential ruby-dev
16
+ ```
17
+ Based on RPM
18
+ ```
19
+ $ sudo yum install -y gcc gcc-c++ ruby-devel libxml2 libxml2-devel libxslt libxslt-devel
20
+ ```
21
+
22
+ ## Installation
23
+ Install the gem yourself:
24
+ ```
25
+ $ gem install dockerbash
26
+ ```
27
+
28
+ ## Usage
29
+ How to run it:
30
+ ```
31
+ $ dockerbash
32
+ ```
33
+
34
+ Example menu:
35
+
36
+ ```
37
+ _ _ _ _
38
+ __| | ___ ___| | _____ _ __| |__ __ _ ___| |___
39
+ / _` |/ _ \ / __| |/ / _ \ __| _ \ / _` / __| _ |
40
+ | (_| | (_) | (__| < __/ | | |_) | (_| \__ \ | | |
41
+ \____|\___/ \___|_|\_\___|_| |____/ \____|___/_| |_|
42
+
43
+ v.0.1.0 - by m8051
44
+
45
+ 0. Container:docker_nginx_1 Ip:172.17.0.3 Ports: 80/tcp -> 8080
46
+ 1. Container:docker_php7-fpm_1 Ip:172.17.0.2 Ports: 9000/tcp -> 9001
47
+ Container? 0
48
+ root@2d7083aa1744:/#
49
+ ```
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dockerbash. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
64
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dockerbash"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'dockerbash'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'dockerbash'
8
+ end
9
+
10
+ # Clean exit with CTRL+C
11
+ trap("INT") { exit }
12
+
13
+ dockerbash = Dockerbash::Client.new()
14
+ dockerbash.select_docker_container()
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dockerbash/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dockerbash"
8
+ spec.version = Dockerbash::VERSION
9
+ spec.authors = ["Jordi"]
10
+ spec.email = ["crawler8086@gmail.com"]
11
+
12
+ spec.summary = %q{A script to make it easier to execute a bash into running Docker containers}
13
+ spec.description = %q{Sometimes when you are running docker containers, you need to inspect the status of services, files, configurations, this gem provides the ability to log into running containers using a GNU Bourne-Shell and debug the container from another shell}
14
+ spec.homepage = "https://github.com/m8051/dockerbash"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = ["dockerbash"]
18
+ spec.require_paths = ["lib"]
19
+ spec.rubygems_version = "1.8.23"
20
+
21
+ spec.add_runtime_dependency 'highline', '~> 1.7'
22
+ spec.add_runtime_dependency 'colorize', '~> 0.7'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+
28
+ end
@@ -0,0 +1,90 @@
1
+ require "dockerbash/version"
2
+ require "highline/import"
3
+ require "fileutils"
4
+ require "colorize"
5
+ require "open3"
6
+ require "mkmf"
7
+
8
+ # Preventing mkmf to:
9
+ # => litter with log files.
10
+ # => non-verbose stdout
11
+ module Logging
12
+ @logfile = File::NULL
13
+ @quiet = true
14
+ end
15
+
16
+ module Dockerbash
17
+
18
+ class Client
19
+
20
+ def initialize()
21
+ banner
22
+ @docker_path = find_docker()
23
+ end
24
+
25
+ def select_docker_container()
26
+ counter = 0
27
+ docker_ids = []
28
+ ids = get_docker_containers_ids()
29
+ ids.each do |i|
30
+ cn_stdout, cn_stderr, cn_status = Open3.capture3("#{@docker_path} inspect --format={{.Name}} #{i}")
31
+ container_name = cn_stdout.gsub(/\n/,'')
32
+ container_name.delete!("/")
33
+
34
+ ci_stdout, ci_stderr, ci_status = Open3.capture3("#{@docker_path} inspect --format={{.NetworkSettings.IPAddress}} #{i}")
35
+ container_ip = ci_stdout.gsub(/\n/,'')
36
+ container_ip.delete("/")
37
+
38
+ cb_stdout, cb_stderr, cb_status = Open3.capture3("#{@docker_path} inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' #{i}")
39
+ container_bindings = cb_stdout.gsub(/\n/,'')
40
+
41
+ container_ids = i
42
+ puts "#{counter}. Container:#{container_name}\tIp:#{container_ip}\tPorts:#{container_bindings}"
43
+ docker_ids << container_ids
44
+ counter += 1
45
+ end
46
+
47
+ selected_id = ask("Container? ", Integer) { |q| q.in = 0..docker_ids.count }
48
+ command = "#{@docker_path} exec -t -i #{docker_ids[selected_id]} /bin/bash"
49
+ exec(command)
50
+ end
51
+
52
+ private
53
+
54
+ def banner
55
+ puts ' _ _ _ _ '.green.bold
56
+ puts ' __| | ___ ___| | _____ _ __| |__ __ _ ___| |___ '.green.bold
57
+ puts ' / _` |/ _ \ / __| |/ / _ \ __| _ \ / _` / __| _ | '.white.bold
58
+ puts ' | (_| | (_) | (__| < __/ | | |_) | (_| \__ \ | | | '.white.bold
59
+ puts ' \____|\___/ \___|_|\_\___|_| |____/ \____|___/_| |_| '.yellow.bold
60
+ puts ' '.yellow.bold
61
+ puts ' v.0.1.0 - by m8051 '.red.bold
62
+ puts ''
63
+ end
64
+
65
+ def find_docker()
66
+ docker_path = find_executable('docker', path = nil)
67
+ if docker_path.nil? || docker_path.empty?
68
+ msg = " -- Docker not found, is the docker package installed?".red
69
+ abort(msg)
70
+ else
71
+ return docker_path
72
+ end
73
+ end
74
+
75
+ def get_docker_containers_ids()
76
+ docker_containers_ids = []
77
+ stdout, stdeerr, status = Open3.capture3("#{@docker_path} ps -aq -f status=running")
78
+ if stdout.nil? || stdout.empty?
79
+ msg = " -- Is the Docker daemon running and the containers up?".red
80
+ abort(msg)
81
+ else
82
+ concat_stdout = stdout.gsub(/\n/,' ')
83
+ docker_containers_ids = concat_stdout.split(" ")
84
+ return docker_containers_ids
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,3 @@
1
+ module Dockerbash
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dockerbash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jordi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-04-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: highline
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.7'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.7'
30
+ - !ruby/object:Gem::Dependency
31
+ name: colorize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.7'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.7'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '10.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '3.0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '3.0'
94
+ description: Sometimes when you are running docker containers, you need to inspect
95
+ the status of services, files, configurations, this gem provides the ability to
96
+ log into running containers using a GNU Bourne-Shell and debug the container from
97
+ another shell
98
+ email:
99
+ - crawler8086@gmail.com
100
+ executables:
101
+ - dockerbash
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - CODE_OF_CONDUCT.md
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/dockerbash
112
+ - bin/setup
113
+ - dockerbash.gemspec
114
+ - lib/dockerbash.rb
115
+ - lib/dockerbash/version.rb
116
+ homepage: https://github.com/m8051/dockerbash
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.23
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: A script to make it easier to execute a bash into running Docker containers
141
+ test_files: []