tid 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb734390a35364f1e6ca0ca85c8f3877dcc09cc4
4
+ data.tar.gz: 4a5aaee11bab1e364c558db56eb2e2cbc3c54ac4
5
+ SHA512:
6
+ metadata.gz: ce623229ef7feab8984379543cd6d2e3a7bfd440658bd4d92b2bd16388388669382ce62f58c197723f1e369c0fc00dda0d99e97115eaa6d402a34e5083d00e22
7
+ data.tar.gz: 340ca41f9b70a0e5ef3df7b3bea469338520f1aafc753556c7bd0adcc3a241517cc391677048c067384e2797045ed19a8e1adc56da2963293f3132db6947a983
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tid.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
7
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 linyows
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,106 @@
1
+ TID
2
+ ===
3
+
4
+ Easy to test in the docker container.
5
+
6
+ [![ruby gem](https://img.shields.io/gem/v/tid.svg?style=flat-square)][gem]
7
+ [![wercker status](https://img.shields.io/wercker/ci/f6e5ba503e4a1f062c6b012ff77d87d0.svg?style=flat-square)][wercker]
8
+
9
+ [gem]: https://rubygems.org/gems/tid
10
+ [wercker]: https://app.wercker.com/project/bykey/f6e5ba503e4a1f062c6b012ff77d87d0
11
+
12
+ Requirements
13
+ ------------
14
+
15
+ linux:
16
+
17
+ ```sh
18
+ $ curl -s http://get.docker.io/ubuntu/ | sudo sh
19
+ ```
20
+
21
+ mac:
22
+
23
+ ```sh
24
+ $ brew update
25
+ $ brew install docker boot2docker
26
+ ```
27
+
28
+ Installation
29
+ ------------
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ ```ruby
34
+ gem 'tid'
35
+ ```
36
+
37
+ And then execute:
38
+
39
+ ```sh
40
+ $ bundle
41
+ ```
42
+
43
+ Or install it yourself as:
44
+
45
+ ```sh
46
+ $ gem install tid
47
+ ```
48
+
49
+ Usage
50
+ -----
51
+
52
+ ```sh
53
+ $ tid init
54
+ create spec/tid/Dockerfile
55
+ create spec/tid/id_rsa
56
+ create spec/tid/id_rsa.pub
57
+ ```
58
+
59
+ example this.
60
+
61
+ ### RSpec
62
+
63
+ spec_helper.rb:
64
+
65
+ ```ruby
66
+ require 'tid'
67
+
68
+ RSpec.configure do |config|
69
+ ...
70
+ config.include(Tid)
71
+ config.before(:all) { Tid.prepare }
72
+ config.after(:all) { Tid.clear }
73
+ end
74
+ ```
75
+
76
+ foo_spec.rb:
77
+
78
+ ```ruby
79
+ describe 'ssh to docker container' do
80
+ it 'successful' do
81
+ out, _, ex = cmd "ssh root@#{ENV['TID_HOSTNAME']} -p #{ENV['TID_PORT']} \
82
+ -i #{ENV['TID_BASE_PATH']}/id_rsa 'echo yo'"
83
+ expect(ex.exitstatus).to eq 0
84
+ expect(out).to eq "yo\n"
85
+ end
86
+ end
87
+ ```
88
+
89
+ Contributing
90
+ ------------
91
+
92
+ 1. Fork it ( https://github.com/linyows/tid/fork )
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create a new Pull Request
97
+
98
+ Author
99
+ ------
100
+
101
+ [linyows](https://github.com/linyows)
102
+
103
+ License
104
+ -------
105
+
106
+ The MIT License (MIT)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,50 @@
1
+ module Tid
2
+ module Boot2docker
3
+ class << self
4
+ def env_keys
5
+ %w(
6
+ DOCKER_HOST
7
+ DOCKER_CERT_PATH
8
+ DOCKER_TLS_VERIFY
9
+ )
10
+ end
11
+
12
+ def env
13
+ @env ||= env!
14
+ end
15
+
16
+ def env!
17
+ out = `boot2docker shellinit 2>/dev/null`
18
+ env_keys.each.with_object({}) do |key, memo|
19
+ out.match(/#{key}=(.*)/)
20
+ memo[key] = $1.chomp
21
+ end
22
+ end
23
+
24
+ def prepare
25
+ up unless running?
26
+ end
27
+
28
+ def status
29
+ Console.cmd 'boot2docker status'
30
+ end
31
+
32
+ def have?
33
+ !`which boot2docker`.empty?
34
+ end
35
+
36
+ def running?
37
+ status == 'running'
38
+ end
39
+
40
+ def ip
41
+ out, _, _ = Console.cmd 'boot2docker ip'
42
+ out.to_s.chomp
43
+ end
44
+
45
+ def up
46
+ Console.cmd 'boot2docker up'
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ require 'open3'
2
+ require 'rainbow/ext/string'
3
+
4
+ module Tid
5
+ module Console
6
+ class << self
7
+ def default_env
8
+ Boot2docker.have? ? Boot2docker.env : {}
9
+ end
10
+
11
+ def cmd(str, env = {})
12
+ env = default_env.merge(env)
13
+ out, err, status = Open3.capture3(env, str)
14
+ show_debuggings(str, env, out, err, status) if debug?
15
+ return out, err, status
16
+ end
17
+
18
+ def debug?
19
+ !!ENV['DEBUG']
20
+ end
21
+
22
+ def show_debuggings(str, env, out, err, status)
23
+ puts " $ #{str} (exit: #{status.exitstatus})".color(:blue)
24
+ puts "#{out}".gsub(/^(.*)/, ' \1').color(:green) unless out.empty?
25
+ puts "#{err}".gsub(/^(.*)/, ' \1').color(:red) unless err.empty?
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/tid/docker.rb ADDED
@@ -0,0 +1,45 @@
1
+ module Tid
2
+ module Docker
3
+ class << self
4
+ def build
5
+ Console.cmd "docker build -t #{image_name} #{Tid.base_path}"
6
+ end
7
+
8
+ def run
9
+ Console.cmd "docker run -d -P --name #{container_name} #{image_name}"
10
+ end
11
+
12
+ def stop
13
+ Console.cmd "docker stop #{container_name}"
14
+ end
15
+
16
+ def rm
17
+ Console.cmd "docker rm #{container_name}"
18
+ end
19
+
20
+ def rmi
21
+ Console.cmd "docker rmi #{image_name}"
22
+ end
23
+
24
+ def hostname
25
+ Boot2docker.have? ? Boot2docker.ip : 'localhost'
26
+ end
27
+
28
+ def image_name
29
+ ENV['TID_IMAGE_NAME'] || 'tid'
30
+ end
31
+
32
+ def container_ssh_port
33
+ _, _, ex = Console.cmd "docker ps | grep #{container_name}"
34
+ if ex.exitstatus.zero?
35
+ out, _, _ = Console.cmd("docker port #{container_name} 22")
36
+ out.to_s.chomp.gsub('0.0.0.0:', '')
37
+ end
38
+ end
39
+
40
+ def container_name
41
+ ENV['TID_CONTAINER_NAME'] || 'tid'
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Tid
2
+ VERSION = '0.0.1'
3
+ end
data/lib/tid.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'tid/version'
2
+ require 'tid/boot2docker'
3
+ require 'tid/docker'
4
+ require 'tid/console'
5
+
6
+ module Tid
7
+ def cmd(str, env = {})
8
+ Console.cmd(str, env)
9
+ end
10
+
11
+ class << self
12
+ def prepare
13
+ Boot2docker.prepare if Boot2docker.have?
14
+ Docker.build
15
+ Docker.run
16
+ self.set_env
17
+ end
18
+
19
+ def clear
20
+ Docker.stop
21
+ Docker.rm
22
+ Docker.rmi
23
+ end
24
+
25
+ def bundle(options = [])
26
+ default_options = [
27
+ '--gemfile',
28
+ "#{base_path}/Gemfile",
29
+ '--quiet'
30
+ ]
31
+
32
+ Bundler.with_clean_env do
33
+ Console.cmd "bundle install #{default_options.concat(options).join(' ')}"
34
+ end
35
+ end
36
+
37
+ def base_path
38
+ ENV['TID_BASE_PATH'] ||= './spec/tid'
39
+ end
40
+
41
+ def set_env
42
+ ENV['TID_HOSTNAME'] ||= "#{Docker.hostname}"
43
+ ENV['TID_PORT'] ||= "#{Docker.container_ssh_port}"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ require 'tid'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+
12
+ config.include(Tid)
13
+ config.before(:all) { Tid.prepare }
14
+ config.after(:all) { Tid.clear }
15
+ end
@@ -0,0 +1,8 @@
1
+ FROM rastasheep/ubuntu-sshd:14.04
2
+ MAINTAINER linyows <linyows@gmail.com>
3
+
4
+ ENV HOME /root
5
+ RUN mkdir /root/.ssh
6
+ ADD id_rsa.pub /root/.ssh/authorized_keys
7
+ RUN chmod 700 /root/.ssh
8
+ RUN chmod 600 /root/.ssh/authorized_keys
data/spec/tid/id_rsa ADDED
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEpAIBAAKCAQEA54RVv3+XjUFcOJC5QD1wobIwkAAvicEz/Ihoq0lVhh3NTSv7
3
+ yyJl3XKq2KqnzYCln6TFXUiQES6IaeDf3usH55wKOnkgtuxmqn0Lq6aVV6Ly8gfT
4
+ 4qOuKTAMfdQud2VT5vBRWIsxkxPog9Q60EWf99unCGB16wuMrGAPRwYwPQDVbBcW
5
+ lDR7VkksXsU1vww3ux599GbL6lT74HvzW862onwwmCqesefHr74Aii/5iRVTUBYY
6
+ be/pN1dm/F7tgT6nEkpdbzzRy6cy0zN/fzCR6FCds17p1q7ujbJz7hzzz3EJwFIu
7
+ bjtnnjAqOQDsRETkleM6RzwghJZHV/PsOq5HawIDAQABAoIBAQCeO5w/nfz+1kUp
8
+ hACZH2Tzns4CHZ5gEGRvnOus5hpF5+iBbiZR19i3Wb/bBghaNCr+yab68rVEiQFD
9
+ HCbmPMzSR5vWCyOI4lno/D4Vu20m0IArW549sJFAJU7kUTjQ8bg+htGSKtBfLaQl
10
+ NdBcuLl0tfObjhIJ64Lh7WWDrX8asUJbXFRzTd9CdamMSlvwTD2d2kXsjY4gYC3T
11
+ OOP/zrzKP/WJ/vXtCNqINzyzSOFVMnU2ZICbImCZfXY7WexCT/jyxU5HpBMjgd5K
12
+ PJMv6GM53AFuA4cmyy6LfmTdVoLzN+6NWboGacCrNv1wLUx0rHbe9vA4YcD+Hqkb
13
+ dxn6xAJBAoGBAPcEN+TVXYCrFubBbhCJN9fesnuIwtjd1zPKYqERDAUSGVNNV3fp
14
+ luoqGhLZtJ3hU31yurRMplL6dlkRFGL7v5DIX5gtYF0CA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A9HBjA9ANVsFxaUNHtWSSxexTW/DDe7Hn30ZsvqVPvge/NbzraifDCYKp6x58evvgCKL/mJFVNQFhht7+k3V2b8Xu2BPqcSSl1vPNHLpzLTM39/MJHoUJ2zXunWru6NsnPuHPPPcQnAUi5uO2eeMCo5AOxEROSV4zpHPCCElkdX8+w6rkdr tomohisaoda@PMAC127S.local
data/spec/tid_spec.rb ADDED
@@ -0,0 +1,22 @@
1
+ RSpec.describe 'Tid' do
2
+ describe 'ssh to docker container' do
3
+ let(:ssh_to_docker_container) do
4
+ [
5
+ "ssh root@#{ENV['TID_HOSTNAME']}",
6
+ "-p #{ENV['TID_PORT']}",
7
+ "-i #{ENV['TID_BASE_PATH']}/id_rsa",
8
+ "'echo yo'"
9
+ ].join(' ')
10
+ end
11
+
12
+ it 'successful' do
13
+ _, _, ex = cmd ssh_to_docker_container
14
+ expect(ex.exitstatus).to eq 0
15
+ end
16
+
17
+ it 'puts yo' do
18
+ out, _, _ = cmd ssh_to_docker_container
19
+ expect(out).to eq "yo\n"
20
+ end
21
+ end
22
+ end
data/tid.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tid'
8
+ spec.version = Tid::VERSION
9
+ spec.authors = ['linyows']
10
+ spec.email = ['linyows@gmail.com']
11
+ spec.summary = %q{Test in Docker.}
12
+ spec.description = %q{Easy to test in the docker container.}
13
+ spec.homepage = 'https://github.com/linyows/tid'
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_dependency 'rainbow', '~> 2.0.0'
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
data/wercker.yml ADDED
@@ -0,0 +1,15 @@
1
+ box: wercker-labs/docker
2
+ build:
3
+ steps:
4
+ - install-packages:
5
+ packages: build-essential ruby2.0 ruby2.0-dev bundler
6
+ - script:
7
+ name: install latest docker
8
+ code: |
9
+ docker version
10
+ curl -s http://get.docker.io/ubuntu/ | sudo sh
11
+ docker version
12
+ - bundle-install
13
+ - script:
14
+ name: rspec
15
+ code: bundle exec rspec
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - linyows
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Easy to test in the docker container.
56
+ email:
57
+ - linyows@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/tid.rb
69
+ - lib/tid/boot2docker.rb
70
+ - lib/tid/console.rb
71
+ - lib/tid/docker.rb
72
+ - lib/tid/version.rb
73
+ - spec/spec_helper.rb
74
+ - spec/tid/Dockerfile
75
+ - spec/tid/id_rsa
76
+ - spec/tid/id_rsa.pub
77
+ - spec/tid_spec.rb
78
+ - tid.gemspec
79
+ - wercker.yml
80
+ homepage: https://github.com/linyows/tid
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.2.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Test in Docker.
104
+ test_files:
105
+ - spec/spec_helper.rb
106
+ - spec/tid/Dockerfile
107
+ - spec/tid/id_rsa
108
+ - spec/tid/id_rsa.pub
109
+ - spec/tid_spec.rb