traquitana 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Gemfile.lock +8 -8
- data/README.md +39 -23
- data/bin/traq +26 -26
- data/config/custom.yml +11 -24
- data/config/default.yml +6 -0
- data/config/proc.sh +52 -0
- data/config/traq.yml +1 -0
- data/gem-public_cert.pem +24 -20
- data/lib/bar.rb +1 -1
- data/lib/cleaner.rb +2 -2
- data/lib/config.rb +8 -8
- data/lib/deployer.rb +15 -8
- data/lib/packager.rb +18 -12
- data/lib/selector.rb +1 -1
- data/lib/ssh.rb +1 -1
- data/lib/traquitana.rb +1 -1
- data/lib/traquitana/version.rb +1 -1
- data/spec/bar_spec.rb +48 -41
- data/spec/cleaner_spec.rb +17 -16
- data/spec/config/Gemfile +3 -0
- data/spec/config/Rakefile +11 -0
- data/spec/config/config/traq.yml +1 -0
- data/spec/config_spec.rb +106 -101
- data/spec/deploy_spec.rb +14 -7
- data/spec/network_spec.rb +55 -52
- data/spec/packager_spec.rb +40 -40
- data/spec/selector_spec.rb +9 -9
- data/traq/config.yml +6 -0
- data/traquitana.gemspec +11 -11
- metadata +35 -35
- metadata.gz.sig +0 -0
- data/lib/migrator.rb +0 -25
- data/spec/migrator_spec.rb +0 -75
data/lib/config.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'singleton'
|
2
2
|
|
3
3
|
module Traquitana
|
4
4
|
class Config
|
@@ -7,7 +7,7 @@ module Traquitana
|
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@configs = {}
|
10
|
-
@filename =
|
10
|
+
@filename = 'config/traq.yml'
|
11
11
|
@target = nil
|
12
12
|
load
|
13
13
|
end
|
@@ -23,23 +23,22 @@ module Traquitana
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def method_missing(meth)
|
26
|
-
@configs[meth.to_s] ||
|
26
|
+
@configs[meth.to_s] || ''
|
27
27
|
end
|
28
28
|
|
29
29
|
def setup
|
30
|
-
STDOUT.puts
|
30
|
+
STDOUT.puts 'Running setup'
|
31
31
|
|
32
32
|
if File.exists?(self.filename)
|
33
33
|
STDERR.puts "The configuration file #{self.filename} already exists."
|
34
34
|
return false
|
35
35
|
end
|
36
36
|
|
37
|
-
dir = File.dirname(
|
37
|
+
dir = File.dirname(filename)
|
38
38
|
Dir.mkdir(dir) if !File.exist?(dir)
|
39
39
|
|
40
|
-
STDOUT.puts "Writing #{
|
41
|
-
File.open(
|
42
|
-
file << "# Default configuration"
|
40
|
+
STDOUT.puts "Writing #{filename}"
|
41
|
+
File.open(filename, "w") do |file|
|
43
42
|
file << File.read(self.default)
|
44
43
|
end
|
45
44
|
|
@@ -49,6 +48,7 @@ module Traquitana
|
|
49
48
|
end
|
50
49
|
|
51
50
|
private
|
51
|
+
|
52
52
|
def check_configs(file)
|
53
53
|
@configs = YAML.load(File.read(file || self.filename)) rescue nil
|
54
54
|
STDERR.puts "Configs not found (tried '#{file}' and '#{self.filename}')" if !@configs
|
data/lib/deployer.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
module Traquitana
|
2
2
|
class Deployer
|
3
|
-
def initialize(options=nil)
|
3
|
+
def initialize(options = nil)
|
4
4
|
@config = Traquitana::Config.instance
|
5
5
|
@verbose = !options.nil? && options[:verbose]
|
6
|
-
@config.filename = options
|
6
|
+
@config.filename = file(options)
|
7
7
|
@config.target = options[:target] if options[:target]
|
8
8
|
end
|
9
9
|
|
10
10
|
def run
|
11
11
|
STDOUT.puts "\e[1mRunning Traquitana version #{VERSION}\e[0m\n\n"
|
12
|
-
Traquitana::Migrator.new.run
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
unless File.exist?(@config.filename)
|
14
|
+
warn "\e[31mNo config file (#{@config.filename}) found."
|
15
|
+
warn "Did you run \e[1mtraq setup\e[0;31m ?"
|
16
|
+
warn "Run it and check the configuration before deploying.\e[0m"
|
18
17
|
exit 1
|
19
18
|
end
|
20
19
|
|
@@ -30,7 +29,7 @@ module Traquitana
|
|
30
29
|
all_list_file, all_list_zip = @packager.pack
|
31
30
|
|
32
31
|
if !File.exists?(all_list_file) || !File.exists?(all_list_zip)
|
33
|
-
|
32
|
+
warn "\e[31mCould not create the needed files.\e[0m"
|
34
33
|
exit 2
|
35
34
|
end
|
36
35
|
|
@@ -59,5 +58,13 @@ module Traquitana
|
|
59
58
|
File.unlink(all_list_zip)
|
60
59
|
STDOUT.puts "\e[32mAll done. Have fun.\e[0m\n"
|
61
60
|
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def file(options)
|
65
|
+
return options[:filename] if options[:filename]
|
66
|
+
|
67
|
+
@config.filename
|
68
|
+
end
|
62
69
|
end
|
63
70
|
end
|
data/lib/packager.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'zip'
|
3
3
|
|
4
4
|
module Traquitana
|
5
5
|
class Packager
|
6
6
|
attr_reader :id
|
7
7
|
attr_accessor :verbose
|
8
8
|
|
9
|
-
def initialize(dir =
|
9
|
+
def initialize(dir = '')
|
10
10
|
@dir = dir
|
11
|
-
@id = Time.now.strftime(
|
11
|
+
@id = Time.now.strftime('%Y%m%d%H%M%S%L')
|
12
12
|
@verbose = verbose
|
13
13
|
end
|
14
14
|
|
@@ -21,24 +21,30 @@ module Traquitana
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def pack
|
24
|
-
list_path
|
25
|
-
zip_path
|
26
|
-
list
|
27
|
-
regex
|
24
|
+
list_path = "#{Dir.tmpdir}/#{self.list_file}"
|
25
|
+
zip_path = "#{Dir.tmpdir}/#{self.zip_file}"
|
26
|
+
list = Traquitana::Selector.new(@dir).files
|
27
|
+
regex = @dir.to_s.size < 1 ? '' : Regexp.new("^#{@dir}")
|
28
28
|
|
29
29
|
# write list file
|
30
30
|
STDOUT.puts "Creating the list file: #{list_path}" if @verbose
|
31
|
-
|
31
|
+
|
32
|
+
File.open(list_path, 'w') do |file|
|
33
|
+
file << list.map do |f|
|
34
|
+
f.sub(regex, '')
|
35
|
+
end.join("\n")
|
36
|
+
end
|
32
37
|
|
33
38
|
# write zip file
|
34
39
|
STDOUT.puts "Creating the zip file : #{zip_path}" if @verbose
|
35
|
-
|
40
|
+
|
41
|
+
Zip::File.open(zip_path, 'w') do |zip_file|
|
36
42
|
for file in list
|
37
|
-
strip = file.sub(regex,
|
43
|
+
strip = file.sub(regex, '')
|
38
44
|
zip_file.add(strip, file)
|
39
45
|
end
|
40
46
|
end
|
41
|
-
[
|
47
|
+
[list_path, zip_path]
|
42
48
|
end
|
43
49
|
end
|
44
50
|
end
|
data/lib/selector.rb
CHANGED
data/lib/ssh.rb
CHANGED
data/lib/traquitana.rb
CHANGED
data/lib/traquitana/version.rb
CHANGED
data/spec/bar_spec.rb
CHANGED
@@ -1,45 +1,52 @@
|
|
1
|
-
require
|
1
|
+
require 'minitest/autorun'
|
2
2
|
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
|
3
3
|
|
4
4
|
describe Traquitana::Bar do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
5
|
+
before do
|
6
|
+
@bar = Traquitana::Bar.new
|
7
|
+
@bar.total = 100
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'limits' do
|
11
|
+
it 'should have a total' do
|
12
|
+
expect(@bar).must_respond_to :total
|
13
|
+
end
|
14
|
+
it 'should have a current value' do
|
15
|
+
expect(@bar).must_respond_to :current
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'updates' do
|
20
|
+
it 'should have a name' do
|
21
|
+
expect(@bar).must_respond_to :name
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a update method' do
|
25
|
+
expect(@bar).must_respond_to :update
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have a indicator method' do
|
29
|
+
expect(@bar).must_respond_to :indicator
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return the correct string for 0%' do
|
33
|
+
expect(@bar.indicator(0)).must_equal '____________________'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return the correct string for 25%' do
|
37
|
+
expect(@bar.indicator(25)).must_equal '#####_______________'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return the correct string for 50%' do
|
41
|
+
expect(@bar.indicator(50)).must_equal '##########__________'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return the correct string for 75%' do
|
45
|
+
expect(@bar.indicator(75)).must_equal '###############_____'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should return the correct string for 100%' do
|
49
|
+
expect(@bar.indicator(100)).must_equal '####################'
|
50
|
+
end
|
51
|
+
end
|
45
52
|
end
|
data/spec/cleaner_spec.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/focus'
|
2
3
|
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
|
3
4
|
|
4
5
|
describe Traquitana::Cleaner do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
before do
|
7
|
+
@cleaner = Traquitana::Cleaner.new
|
8
|
+
@config = Traquitana::Config.instance
|
9
|
+
@config.load
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
it 'should have a run method' do
|
13
|
+
expect(@cleaner).must_respond_to :run
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
it 'should run cleaner on remote host' do
|
17
|
+
network = MiniTest::Mock.new
|
18
|
+
network.expect(:execute, nil, [["find #{@config.directory}/traq -type f -iname '*.zip' -o -iname '*.list' | sort | head -n-2 | xargs rm $1"]])
|
19
|
+
@cleaner.network = network
|
20
|
+
@cleaner.run
|
21
|
+
network.verify
|
22
|
+
end
|
22
23
|
end
|
data/spec/config/Gemfile
CHANGED
data/spec/config/Rakefile
CHANGED
data/spec/config/config/traq.yml
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -1,109 +1,114 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/focus'
|
4
5
|
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
|
5
6
|
|
6
7
|
describe Traquitana::Config do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
8
|
+
before do
|
9
|
+
@config = Traquitana::Config.instance
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'paths' do
|
13
|
+
it 'should have a filename getter method' do
|
14
|
+
expect(@config).must_respond_to :filename
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have a filename called traq.yml if file name is not set' do
|
18
|
+
expect(File.basename(@config.filename)).must_equal('traq.yml')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have a filename setter method' do
|
22
|
+
expect(@config).must_respond_to :filename=
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should have a custom filename if filename is set' do
|
26
|
+
old = @config.filename
|
27
|
+
custom = 'config/custom.yml'
|
28
|
+
|
29
|
+
@config.filename = custom
|
30
|
+
expect(@config.filename).must_equal custom
|
31
|
+
@config.filename = old
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should have a default file method' do
|
35
|
+
expect(@config).must_respond_to :default
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should have a valid directory' do
|
39
|
+
expect(@config.directory).wont_be_nil
|
40
|
+
expect(@config.directory.size > 0).must_equal true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'configs' do
|
45
|
+
it 'should respond to configuration dynamic methods' do
|
46
|
+
expect(@config.banana).must_equal ''
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should respond with the correct value' do
|
50
|
+
@config.load
|
51
|
+
expect(@config.user).must_equal 'taq'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should have basic information on the default file' do
|
55
|
+
contents = YAML.load(File.read(@config.default))
|
56
|
+
expect(contents['directory']).wont_be_nil
|
57
|
+
expect(contents['server']).wont_be_nil
|
58
|
+
expect(contents['list']).wont_be_nil
|
59
|
+
expect(contents['host']).wont_be_nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'setup' do
|
64
|
+
it 'should have a method named setup' do
|
65
|
+
expect(@config).must_respond_to :setup
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should do nothing if the configuration file exists' do
|
69
|
+
expect(@config.setup).must_equal false
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should write the configuration file if it doesnt exists' do
|
73
|
+
contents = File.read(@config.filename)
|
74
|
+
File.unlink(@config.filename)
|
75
|
+
|
76
|
+
expect(File.exists?(@config.filename)).must_equal false
|
77
|
+
expect(@config.setup).must_equal true
|
78
|
+
expect(File.exists?(@config.filename)).must_equal true
|
79
|
+
|
80
|
+
File.open(@config.filename, 'w') do |file|
|
81
|
+
file << contents
|
79
82
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'targets' do
|
87
|
+
it 'should have a target readable attribute' do
|
88
|
+
expect(@config).must_respond_to :target
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should have a target writable attribute' do
|
92
|
+
expect(@config).must_respond_to :target=
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should load custom target config' do
|
96
|
+
begin
|
97
|
+
@config.filename = 'config/custom.yml'
|
98
|
+
@config.target = 'custom'
|
99
|
+
@config.load
|
100
|
+
expect(@config.directory).must_equal '/tmp/traq_test_custom'
|
101
|
+
ensure
|
102
|
+
reset_config
|
85
103
|
end
|
104
|
+
end
|
105
|
+
end
|
86
106
|
|
87
|
-
|
88
|
-
@config.must_respond_to :target=
|
89
|
-
end
|
107
|
+
private
|
90
108
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
@config.directory.must_equal "/tmp/traq_test_custom"
|
97
|
-
ensure
|
98
|
-
reset_config
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
def reset_config
|
105
|
-
@config.filename = "config/traq.yml"
|
106
|
-
@config.target = nil
|
107
|
-
@config.load
|
108
|
-
end
|
109
|
+
def reset_config
|
110
|
+
@config.filename = 'config/traq.yml'
|
111
|
+
@config.target = nil
|
112
|
+
@config.load
|
113
|
+
end
|
109
114
|
end
|