vx-common 0.3.2 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc6f3bba460f725a826601a0ec3a41d551d6e906
4
- data.tar.gz: 65f6998ccdd5bec2c6fbc1b280c6707c3bc292e4
3
+ metadata.gz: aeaa48cff84a589e79162bba246ac94d5e2b5571
4
+ data.tar.gz: 6c8010c307bd983da2aeb965f8114467a9a6143f
5
5
  SHA512:
6
- metadata.gz: d1ab8f1ab621d9a4713bf64e1ed97bf3aa699b7eb4e6f297fbb40ef6343838f2b51613b683f5ac59cd7b9f8dba0012bd75e17ef7608a4d28e14b32843e643a2c
7
- data.tar.gz: e10cb43a542e9fa48655bb1cace53670856b4cedb48c131e0ac9717afb0afc2bb0f4a4b74224de231d7f55576cd4577e905a2275e599d7fce3b68c22251ded69
6
+ metadata.gz: 19f77dddca2f2e2d8a50362920921d0cd54cc7b455e265b4ae47f367d4d5dca961053c46c5d66e2e3d71d2b2e6140c832684879a8d907027e8966e65957d7010
7
+ data.tar.gz: 9155353231dbd9c1128e56431fbb59afddc7d57bc7dca0fe2b4142e951b1cac3a9328d8ec57608789d1a292125e9d8428c49a25e8d23434e718c3ec28e9c0997
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  rvm:
2
2
  - 2.0.0
3
- - 2.1.0
3
+ - 2.1.2
4
4
 
5
5
  script: "bundle exec rake travis"
data/lib/vx/common.rb CHANGED
@@ -9,8 +9,6 @@ module Vx
9
9
  end
10
10
 
11
11
  autoload :OutputBuffer, File.expand_path("../common/output_buffer", __FILE__)
12
- autoload :EnvFile, File.expand_path("../common/env_file", __FILE__)
13
- autoload :ErrorNotifier, File.expand_path("../common/error_notifier", __FILE__)
14
12
  autoload :Git, File.expand_path("../common/git", __FILE__)
15
13
  end
16
14
 
data/lib/vx/common/git.rb CHANGED
@@ -21,7 +21,7 @@ module Vx
21
21
  def git_ssh_content(key_location)
22
22
  key = key_location ? "-i #{key_location}" : ""
23
23
  out = "#!/bin/sh\n"
24
- out << "/usr/bin/ssh"
24
+ out << "exec /usr/bin/ssh"
25
25
  out << " -A -o LogLevel=quiet"
26
26
  out << " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
27
27
  out << " #{key} $@\n"
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module Common
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vx-common-spawn
@@ -136,19 +136,13 @@ files:
136
136
  - LICENSE.txt
137
137
  - Rakefile
138
138
  - lib/vx/common.rb
139
- - lib/vx/common/amqp_setup.rb
140
- - lib/vx/common/env_file.rb
141
- - lib/vx/common/error_notifier.rb
142
139
  - lib/vx/common/git.rb
143
140
  - lib/vx/common/helper/middlewares.rb
144
- - lib/vx/common/helper/shell.rb
145
141
  - lib/vx/common/helper/upload_sh_command.rb
146
142
  - lib/vx/common/output_buffer.rb
147
- - lib/vx/common/tagged_logging.rb
148
143
  - lib/vx/common/version.rb
149
144
  - spec/lib/common/git_spec.rb
150
145
  - spec/lib/common/helper/middlewares_spec.rb
151
- - spec/lib/common/helper/shell_spec.rb
152
146
  - spec/lib/common/helper/upload_sh_command_spec.rb
153
147
  - spec/lib/common/output_buffer_spec.rb
154
148
  - spec/spec_helper.rb
@@ -173,14 +167,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
167
  version: '0'
174
168
  requirements: []
175
169
  rubyforge_project:
176
- rubygems_version: 2.0.14
170
+ rubygems_version: 2.2.2
177
171
  signing_key:
178
172
  specification_version: 4
179
173
  summary: Common code for ci
180
174
  test_files:
181
175
  - spec/lib/common/git_spec.rb
182
176
  - spec/lib/common/helper/middlewares_spec.rb
183
- - spec/lib/common/helper/shell_spec.rb
184
177
  - spec/lib/common/helper/upload_sh_command_spec.rb
185
178
  - spec/lib/common/output_buffer_spec.rb
186
179
  - spec/spec_helper.rb
@@ -1,41 +0,0 @@
1
- require 'vx/common/amqp'
2
- require 'vx/common/error_notifier'
3
-
4
- module Vx
5
- module Common
6
-
7
- module AMQP
8
- extend self
9
-
10
- def setup(logger, options = {})
11
- Vx::Common::AMQP.configure do |c|
12
-
13
- c.before_subscribe do |e|
14
- logger.warn "[#{e[:name]}] subsribing #{e[:exchange].name}"
15
- end
16
-
17
- c.after_subscribe do |e|
18
- logger.warn "[#{e[:name]}] shutdown"
19
- end
20
-
21
- c.before_recieve do |e|
22
- logger.warn "[#{e[:name]}] payload recieved #{e[:payload].inspect[0..60]}"
23
- end
24
-
25
- c.after_recieve do |e|
26
- logger.warn "[#{e[:name]}] commit message"
27
- end
28
-
29
- c.on_error do |e|
30
- Vx::Common::ErrorNotifier.notify(e)
31
- end
32
-
33
- c.content_type = 'application/x-protobuf'
34
- c.logger = nil
35
- c.url = options[:url]
36
-
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,24 +0,0 @@
1
- module Vx
2
- module Common
3
- module EnvFile
4
-
5
- def read_env_file(file = nil)
6
- file ||= '/etc/vexor/ci'
7
- file = File.expand_path(file)
8
-
9
- if File.readable?(file)
10
- buf = File.read(file)
11
-
12
- buf.split("\n").each do |line|
13
- next if line.strip.empty?
14
-
15
- env, value = line.split("=").map(&:strip)
16
- ::ENV[env] = value
17
- end
18
- end
19
-
20
- end
21
-
22
- end
23
- end
24
- end
@@ -1,32 +0,0 @@
1
- require 'airbrake'
2
-
3
- module Vx
4
- module Common
5
-
6
- class ErrorNotifier
7
-
8
- class << self
9
- def notify(error)
10
- if setup
11
- ::Airbrake.notify(error)
12
- end
13
- end
14
-
15
- def setup
16
- @configured ||= begin
17
- return false unless ENV['AIRBRAKE_API_KEY']
18
-
19
- ::Airbrake.configure do |config|
20
- config.api_key = ENV['AIRBRAKE_API_KEY']
21
- config.host = ENV['AIRBRAKE_HOST']
22
- config.port = ENV['AIRBRAKE_PORT'] || 80
23
- config.secure = config.port == 443
24
- end
25
- true
26
- end
27
- end
28
- end
29
- end
30
-
31
- end
32
- end
@@ -1,83 +0,0 @@
1
- require 'pathname'
2
- require 'fileutils'
3
- require 'tempfile'
4
- require 'shellwords'
5
-
6
- require 'vx/common/spawn'
7
-
8
- module Vx
9
- module Common
10
- module Helper
11
-
12
- module Shell
13
-
14
- private
15
-
16
- include Vx::Common::Spawn
17
-
18
- def path(name)
19
- Pathname.new(name)
20
- end
21
-
22
- def mkdir(name)
23
- FileUtils.mkdir_p name.to_s
24
- end
25
-
26
- def rm(name)
27
- FileUtils.rm_rf name.to_s
28
- end
29
-
30
- def recreate(name)
31
- rm name
32
- mkdir name
33
- end
34
-
35
- def write_file(name, content, perm = 0644)
36
- File.open(name, 'w', perm) do |io|
37
- io.write content
38
- end
39
- end
40
-
41
- def write_tmp_file(name, content, perm = 0600)
42
- tmp = ::Tempfile.new name
43
- tmp.write content
44
- tmp.rewind
45
- tmp.flush
46
- tmp.close
47
- FileUtils.chmod perm, tmp.path
48
- tmp
49
- end
50
-
51
- def read_file(name)
52
- if File.readable?(name)
53
- File.read name
54
- end
55
- end
56
-
57
- def expand_path(path)
58
- File.expand_path path.to_s
59
- end
60
-
61
- def bash(*args, &block)
62
- raise ArgumentError, 'block required' unless block_given?
63
-
64
- options = args.last.is_a?(Hash) ? args.pop : {}
65
- command = args.first
66
-
67
- cmd = "/usr/bin/env -i HOME=${HOME} bash"
68
-
69
- if file = options.delete(:file)
70
- cmd << " #{file}"
71
- else
72
- cmd << " -c " << Shellwords.escape(command)
73
- end
74
-
75
- runner = options.delete(:ssh) || self
76
- runner.send(:spawn, cmd, options, &block)
77
- end
78
-
79
- end
80
-
81
- end
82
- end
83
- end
@@ -1,81 +0,0 @@
1
- # from activesupport
2
-
3
- require 'logger'
4
-
5
- module Vx
6
- module Common
7
- module TaggedLogging
8
-
9
- class Formatter < ::Logger::Formatter
10
- Format = "[%s] %1s : %s\n"
11
-
12
- def call(severity, time, progname, msg)
13
- Format % [format_datetime(time),
14
- severity[0...1],
15
- msg2str("#{tags_text}#{msg}")]
16
- end
17
-
18
- def thread_id
19
- Thread.current.object_id
20
- end
21
-
22
- def tagged(*tags)
23
- new_tags = push_tags(*tags)
24
- yield self
25
- ensure
26
- pop_tags(new_tags.size)
27
- end
28
-
29
- def push_tags(*tags)
30
- tags.flatten.reject{|i| i.to_s.strip.empty? }.tap do |new_tags|
31
- current_tags.concat new_tags
32
- end
33
- end
34
-
35
- def pop_tags(size = 1)
36
- current_tags.pop size
37
- end
38
-
39
- def clear_tags!
40
- current_tags.clear
41
- end
42
-
43
- def current_tags
44
- Thread.current[:activesupport_tagged_logging_tags] ||= []
45
- end
46
-
47
- private
48
-
49
- def tags_text
50
- tags = current_tags
51
- if tags.any?
52
- tags.collect { |tag| "[#{tag}] " }.join
53
- end
54
- end
55
-
56
- end
57
-
58
- def self.new(logger)
59
- # Ensure we set a default formatter so we aren't extending nil!
60
- logger.formatter = Formatter.new
61
- logger.extend(self)
62
- end
63
-
64
- %w{ push_tags pop_tags clear_tags! }.each do |m|
65
- define_method m do
66
- formatter.send(m)
67
- end
68
- end
69
-
70
- def tagged(*tags)
71
- formatter.tagged(*tags) { yield self }
72
- end
73
-
74
- def flush
75
- clear_tags!
76
- super if defined?(super)
77
- end
78
-
79
- end
80
- end
81
- end
@@ -1,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Vx::Common::Helper::Shell do
4
-
5
- let(:klass) { Class.new.tap{|i| i.send :include, described_class } }
6
- let(:object) { klass.new }
7
-
8
- subject { object }
9
-
10
- context "path" do
11
- it "should create Pathname" do
12
- expect_method(:path, '/tmp').to eq Pathname.new('/tmp')
13
- end
14
- end
15
-
16
- context "mkdir" do
17
-
18
- after { FileUtils.rm_rf '/tmp/.a/' }
19
-
20
- it "should create directories" do
21
- expect_method(:mkdir, '/tmp/.a/b/c')
22
- expect(File.directory? '/tmp/.a/b/c')
23
- end
24
- end
25
-
26
- context "rm" do
27
- before { FileUtils.mkdir_p '/tmp/.a/b/c' }
28
- after { FileUtils.rm_rf '/tmp/.a' }
29
-
30
- it "should force remove" do
31
- expect_method :rm, '/tmp/.a'
32
- expect(File.exists? '/tmp/.a').to be_false
33
- end
34
- end
35
-
36
- context "recreate" do
37
- before { FileUtils.mkdir_p '/tmp/.a/b/c' }
38
- after { FileUtils.rm_rf '/tmp/.a' }
39
-
40
- it "should remove and create directory" do
41
- expect_method :recreate, '/tmp/.a/b'
42
- expect(File.exists? '/tmp/.a/b/c').to be_false
43
- end
44
- end
45
-
46
- context "write_file" do
47
- let(:fname) { '/tmp/.a' }
48
- after { FileUtils.rm_f fname }
49
-
50
- it "should write content to file" do
51
- expect_method :write_file, fname, 'content', 0611
52
- expect(File.readable? fname).to be_true
53
- expect(File.read fname).to eq 'content'
54
- end
55
- end
56
-
57
- context "write_tmp_file" do
58
- let(:tmp_file) { object.send :write_tmp_file, 'fname', 'content', 0611 }
59
-
60
- after { FileUtils.rm_f tmp_file.path }
61
-
62
- it "should create tmp file and write content" do
63
- expect(tmp_file).to be
64
- expect(File.readable? tmp_file.path).to be_true
65
- expect(File.read tmp_file.path).to eq 'content'
66
- end
67
- end
68
-
69
- context "read_file" do
70
- let(:fname) { '/tmp/.a' }
71
- before do
72
- File.open fname, 'w' do |io|
73
- io << "content"
74
- end
75
- end
76
- after { FileUtils.rm_f fname }
77
-
78
- it "should read file" do
79
- expect_method(:read_file, fname).to eq 'content'
80
- end
81
-
82
- context "when file does not exists" do
83
- it "should return nil" do
84
- expect_method(:read_file, 'not_exists').to be_nil
85
- end
86
- end
87
- end
88
-
89
- context "bash" do
90
- let(:output) { '' }
91
-
92
- context "when command is string" do
93
- it "should spawn bash command and return exit code" do
94
- expect_method(:bash, "echo $HOME", &method(:add_to_output)).to eq 0
95
- expect(output).to eq ENV['HOME'] + "\n"
96
- end
97
- end
98
-
99
- context "when command is a file" do
100
- let(:fname) { '/tmp/.a' }
101
-
102
- before do
103
- File.open fname, 'w' do |io|
104
- io << "echo $HOME"
105
- end
106
- end
107
-
108
- after { FileUtils.rm_f fname }
109
-
110
- it "should spawn bash, execute file and return exit code" do
111
- expect_method(:bash, file: fname, &method(:add_to_output)).to eq 0
112
- end
113
- end
114
-
115
- context "when :ssh options passed" do
116
- let(:ssh) { 'ssh' }
117
-
118
- before do
119
- mock(ssh).spawn("/usr/bin/env -i HOME=${HOME} bash -c command", {}) { 0 }
120
- end
121
-
122
- it "should execute command thougth :ssh" do
123
- expect_method(:bash, 'command', ssh: ssh, &method(:add_to_output)).to eq 0
124
- end
125
-
126
- end
127
-
128
- def add_to_output(out)
129
- output << out
130
- end
131
- end
132
-
133
- def expect_method(name, *args, &block)
134
- expect(object.send(name, *args, &block))
135
- end
136
-
137
- end