traquitana 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +71 -0
- data/Rakefile +8 -0
- data/bin/traq +28 -5
- data/config/default.yml +7 -8
- data/config/extra.sh +1 -0
- data/config/nginx.sh +6 -0
- data/config/passenger.sh +6 -7
- data/config/proc.sh +37 -16
- data/config/traq.yml +25 -0
- data/lib/bar.rb +39 -0
- data/lib/cleaner.rb +17 -0
- data/lib/config.rb +44 -28
- data/lib/deployer.rb +59 -0
- data/lib/migrator.rb +25 -0
- data/lib/packager.rb +44 -0
- data/lib/selector.rb +24 -0
- data/lib/ssh.rb +43 -0
- data/lib/traquitana.rb +3 -0
- data/lib/traquitana/version.rb +3 -0
- data/spec/bar_spec.rb +45 -0
- data/spec/cleaner_spec.rb +22 -0
- data/spec/config/Gemfile +0 -0
- data/spec/config/Rakefile +0 -0
- data/spec/config/app/controllers/people_controller.rb +0 -0
- data/spec/config/app/models/people.rb +0 -0
- data/spec/config/app/views/people/index.html.erb +0 -0
- data/spec/config/app/views/people/show.html.erb +0 -0
- data/spec/config/config.ru +0 -0
- data/spec/config/config/application.rb +0 -0
- data/spec/config/config/environment.rb +0 -0
- data/spec/config/config/environments/production.rb +0 -0
- data/spec/config/config/initializers/inflections.rb +0 -0
- data/spec/config/config/initializers/mime_types.rb +0 -0
- data/spec/config/config/locales/en.yml +0 -0
- data/spec/config/config/locales/pt-BR.yml +0 -0
- data/spec/config/config/routes.rb +0 -0
- data/spec/config/config/traq.yml +25 -0
- data/spec/config/db/migrate/one.rb +0 -0
- data/spec/config/db/migrate/two.rb +0 -0
- data/spec/config/lib/test.rb +0 -0
- data/spec/config/network_test.txt +1 -0
- data/spec/config/public/images/one.jpg +0 -0
- data/spec/config/public/images/themes/dark/dark.jpg +0 -0
- data/spec/config/public/images/themes/theme.jpg +0 -0
- data/spec/config/public/images/three.jpg +0 -0
- data/spec/config/public/images/two.jpg +0 -0
- data/spec/config/public/images/uploads/avatars/avatar.jpg +0 -0
- data/spec/config/public/images/uploads/people/person.jpg +0 -0
- data/spec/config/public/images/uploads/upload.jpg +0 -0
- data/spec/config/public/javascripts/application.js +0 -0
- data/spec/config/public/stylesheets/application.css +0 -0
- data/spec/config_spec.rb +64 -0
- data/spec/deploy_spec.rb +11 -0
- data/spec/migrator_spec.rb +75 -0
- data/spec/network_spec.rb +56 -0
- data/spec/packager_spec.rb +44 -0
- data/spec/selector_spec.rb +14 -0
- data/traq/config.yml +25 -0
- data/traquitana.gemspec +21 -0
- metadata +109 -14
- data/lib/deploy.rb +0 -151
data/lib/migrator.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Traquitana
|
4
|
+
class Migrator
|
5
|
+
def run
|
6
|
+
old_file = "./traq/config.yml"
|
7
|
+
new_file = "./config/traq.yml"
|
8
|
+
|
9
|
+
return false if !File.exists?(old_file) || File.exists?(new_file)
|
10
|
+
|
11
|
+
STDOUT.puts "Migrating old config file ..."
|
12
|
+
contents = YAML.load(File.read(old_file))
|
13
|
+
contents = contents.inject({}) {|hash,val| hash[val.first.to_s] = val.last; hash}.reject {|k,v| k=="ignore"}.to_yaml
|
14
|
+
File.open(new_file,"w") {|f| f<<contents}
|
15
|
+
|
16
|
+
File.unlink(old_file)
|
17
|
+
first_run = "#{File.dirname(old_file)}/.first_run"
|
18
|
+
File.unlink(first_run) if File.exists?(first_run)
|
19
|
+
|
20
|
+
dir = "#{File.dirname(old_file)}"
|
21
|
+
Dir.unlink(dir) if Dir.exists?(dir)
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/packager.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "tmpdir"
|
2
|
+
require "zip/zip"
|
3
|
+
|
4
|
+
module Traquitana
|
5
|
+
class Packager
|
6
|
+
attr_reader :id
|
7
|
+
attr_accessor :verbose
|
8
|
+
|
9
|
+
def initialize(dir="")
|
10
|
+
@dir = dir
|
11
|
+
@id = Time.now.strftime("%Y%m%d%H%M%S%L")
|
12
|
+
@verbose = verbose
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_file
|
16
|
+
"#{@id}.list"
|
17
|
+
end
|
18
|
+
|
19
|
+
def zip_file
|
20
|
+
"#{@id}.zip"
|
21
|
+
end
|
22
|
+
|
23
|
+
def pack
|
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
|
+
|
29
|
+
# write list file
|
30
|
+
STDOUT.puts "Creating the list file: #{list_path}" if @verbose
|
31
|
+
File.open(list_path,"w") {|file| file << list.map {|f| f.sub(regex,"")}.join("\n") }
|
32
|
+
|
33
|
+
# write zip file
|
34
|
+
STDOUT.puts "Creating the zip file : #{zip_path}" if @verbose
|
35
|
+
Zip::ZipFile.open(zip_path ,"w") do |zip_file|
|
36
|
+
for file in list
|
37
|
+
strip = file.sub(regex,"")
|
38
|
+
zip_file.add(strip,file)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
[list_path,zip_path]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/selector.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Traquitana
|
2
|
+
class Selector
|
3
|
+
def initialize(dir="")
|
4
|
+
@dir = dir
|
5
|
+
end
|
6
|
+
|
7
|
+
def files
|
8
|
+
config = Traquitana::Config.instance
|
9
|
+
selected = []
|
10
|
+
for file in config.list
|
11
|
+
send, *ignore = *file
|
12
|
+
mask = "#{@dir}#{send}"
|
13
|
+
send_list = Dir.glob(mask).select { |f| File.file?(f) }
|
14
|
+
for ignore_mask in ignore
|
15
|
+
mask = "#{@dir}#{ignore_mask}"
|
16
|
+
ignore_list = Dir.glob(mask).select { |f| File.file?(f) }
|
17
|
+
send_list = send_list - ignore_list if ignore_list.size>0
|
18
|
+
end
|
19
|
+
selected.push(*send_list)
|
20
|
+
end
|
21
|
+
selected
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ssh.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "net/scp"
|
2
|
+
require "net/ssh"
|
3
|
+
|
4
|
+
module Traquitana
|
5
|
+
class SSH
|
6
|
+
attr_reader :host, :user, :options
|
7
|
+
|
8
|
+
def initialize(host,user,options=nil)
|
9
|
+
@host = host
|
10
|
+
@user = user
|
11
|
+
@options = options || {}
|
12
|
+
STDOUT.puts "Connecting to #{@host} using user #{@user}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute(cmds,verbose=false)
|
16
|
+
rst = []
|
17
|
+
Net::SSH.start(@host,@user,@options) do |ssh|
|
18
|
+
for cmd in cmds
|
19
|
+
STDOUT.puts "Executing #{cmd} on remote host ..." if verbose
|
20
|
+
rst << ssh.exec!(cmd)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
rst
|
24
|
+
end
|
25
|
+
|
26
|
+
def send_files(col,updater=nil)
|
27
|
+
Net::SCP.start(@host,@user,@options) do |scp|
|
28
|
+
for files in col
|
29
|
+
from, to = *files
|
30
|
+
next if from.nil? || to.nil?
|
31
|
+
scp.upload!(from,to) do |ch,name,sent,total|
|
32
|
+
if !updater.nil?
|
33
|
+
updater.name = to
|
34
|
+
updater.total = total
|
35
|
+
updater.update(sent)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
updater.reset if !updater.nil?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/traquitana.rb
ADDED
data/spec/bar_spec.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
|
3
|
+
|
4
|
+
describe Traquitana::Bar do
|
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
|
+
@bar.must_respond_to :total
|
13
|
+
end
|
14
|
+
it "should have a current value" do
|
15
|
+
@bar.must_respond_to :current
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "updates" do
|
20
|
+
it "should have a name" do
|
21
|
+
@bar.must_respond_to :name
|
22
|
+
end
|
23
|
+
it "should have a update method" do
|
24
|
+
@bar.must_respond_to :update
|
25
|
+
end
|
26
|
+
it "should have a indicator method" do
|
27
|
+
@bar.must_respond_to :indicator
|
28
|
+
end
|
29
|
+
it "should return the correct string for 0%" do
|
30
|
+
@bar.indicator(0).must_equal "____________________"
|
31
|
+
end
|
32
|
+
it "should return the correct string for 25%" do
|
33
|
+
@bar.indicator(25).must_equal "#####_______________"
|
34
|
+
end
|
35
|
+
it "should return the correct string for 50%" do
|
36
|
+
@bar.indicator(50).must_equal "##########__________"
|
37
|
+
end
|
38
|
+
it "should return the correct string for 75%" do
|
39
|
+
@bar.indicator(75).must_equal "###############_____"
|
40
|
+
end
|
41
|
+
it "should return the correct string for 100%" do
|
42
|
+
@bar.indicator(100).must_equal "####################"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
|
3
|
+
|
4
|
+
describe Traquitana::Cleaner do
|
5
|
+
before do
|
6
|
+
@cleaner = Traquitana::Cleaner.new
|
7
|
+
@config = Traquitana::Config.instance
|
8
|
+
@config.load
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a run method" do
|
12
|
+
@cleaner.must_respond_to :run
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should run cleaner on remote host" do
|
16
|
+
network = MiniTest::Mock.new
|
17
|
+
network.expect(:execute,nil,[["find #{@config.directory}/traq -type f -iname '*.zip' -o -iname '*.list' | sort | head -n-2 | xargs rm $1"]])
|
18
|
+
@cleaner.network = network
|
19
|
+
@cleaner.run
|
20
|
+
network.verify
|
21
|
+
end
|
22
|
+
end
|
data/spec/config/Gemfile
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Sample configuration---
|
2
|
+
directory: /tmp/traq_test
|
3
|
+
user: taq
|
4
|
+
list:
|
5
|
+
- Rakefile
|
6
|
+
- config.ru
|
7
|
+
- Gemfile
|
8
|
+
- - config/application.rb
|
9
|
+
- - config/environment.rb
|
10
|
+
- - config/initializers/**/*
|
11
|
+
- - config/environments/production.rb
|
12
|
+
- - config/locales/**/*
|
13
|
+
- - config/routes.rb
|
14
|
+
- - app/**/*
|
15
|
+
- - db/migrate/**/*
|
16
|
+
- - public/javascripts/**/*
|
17
|
+
- - public/stylesheets/**/*
|
18
|
+
- - lib/**/*
|
19
|
+
- - public/images/**/*
|
20
|
+
- public/images/uploads/**/*
|
21
|
+
- public/images/themes/**/*
|
22
|
+
password: fill your password here
|
23
|
+
host: localhost
|
24
|
+
server: passenger
|
25
|
+
shell: bash -l -c
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
network test
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "fileutils"
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
|
5
|
+
|
6
|
+
describe Traquitana::Config do
|
7
|
+
before do
|
8
|
+
@config = Traquitana::Config.instance
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "paths" do
|
12
|
+
it "should have a filename method" do
|
13
|
+
@config.must_respond_to(:filename)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a filename called traq.yml" do
|
17
|
+
File.basename(@config.filename).must_equal("traq.yml")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a default file method" do
|
21
|
+
@config.must_respond_to(:default)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "configs" do
|
26
|
+
it "should respond to configuration dynamic methods" do
|
27
|
+
@config.banana.must_equal ""
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should respond with the correct value" do
|
31
|
+
@config.load
|
32
|
+
@config.user.must_equal "taq"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have basic information on the default file" do
|
36
|
+
contents = YAML.load(File.read(@config.default))
|
37
|
+
contents["directory"].wont_be_nil
|
38
|
+
contents["server"].wont_be_nil
|
39
|
+
contents["list"].wont_be_nil
|
40
|
+
contents["host"].wont_be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "setup" do
|
45
|
+
it "should have a method named setup" do
|
46
|
+
@config.must_respond_to(:setup)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should do nothing if the configuration file exists" do
|
50
|
+
@config.setup.must_equal false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should write the configuration file if it doesn't exists" do
|
54
|
+
contents = File.read(@config.filename)
|
55
|
+
File.unlink(@config.filename)
|
56
|
+
|
57
|
+
assert !File.exists?(@config.filename)
|
58
|
+
@config.setup.must_equal true
|
59
|
+
assert File.exists?(@config.filename)
|
60
|
+
|
61
|
+
File.open(@config.filename,"w") {|file| file << contents}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/deploy_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "fileutils"
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
|
5
|
+
|
6
|
+
describe Traquitana::Deployer do
|
7
|
+
before do
|
8
|
+
@config = Traquitana::Config.instance
|
9
|
+
@deploy = Traquitana::Deployer.new
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../lib/traquitana.rb"
|
3
|
+
|
4
|
+
describe Traquitana::Migrator do
|
5
|
+
before do
|
6
|
+
@migrator = Traquitana::Migrator.new
|
7
|
+
|
8
|
+
@old_file = "#{File.expand_path(File.dirname(__FILE__))}/../traq/config.yml"
|
9
|
+
@old_cont = File.read(@old_file)
|
10
|
+
|
11
|
+
@new_file = "#{File.expand_path(File.dirname(__FILE__))}/../config/traq.yml"
|
12
|
+
@new_cont = File.read(@new_file)
|
13
|
+
|
14
|
+
File.unlink(@new_file)
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
FileUtils.mkdir(File.dirname(@old_file)) if !Dir.exists?(File.dirname(@old_file))
|
19
|
+
FileUtils.mkdir(File.dirname(@new_file)) if !Dir.exists?(File.dirname(@new_file))
|
20
|
+
|
21
|
+
File.open(@new_file,"w") {|f| f<<@new_cont}
|
22
|
+
File.open(@old_file,"w") {|f| f<<@old_cont}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a run method" do
|
26
|
+
@migrator.must_respond_to(:run)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return false when there isn't an old config file" do
|
30
|
+
contents = File.read(@old_file)
|
31
|
+
File.unlink(@old_file)
|
32
|
+
assert !@migrator.run
|
33
|
+
File.open(@old_file,"w") {|f| f<<contents}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return false if there is a new config file" do
|
37
|
+
File.open(@new_file,"w") {|f| f<<@new_cont}
|
38
|
+
assert !@migrator.run
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return true when there is an old config file" do
|
42
|
+
assert @migrator.run
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have the new file after run" do
|
46
|
+
File.unlink(@new_file) if File.exists?(@new_file)
|
47
|
+
@migrator.run
|
48
|
+
assert File.exists?(@new_file)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not have the old file after run" do
|
52
|
+
@migrator.run
|
53
|
+
assert !File.exists?(@old_file)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not have the old dir after run" do
|
57
|
+
@migrator.run
|
58
|
+
assert !Dir.exists?(File.dirname(@old_file))
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not have the ignore clause on the new file" do
|
62
|
+
@migrator.run
|
63
|
+
assert !YAML.load(File.read(@new_file)).include?("ignore")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have all the keys of the old file on the new one" do
|
67
|
+
old_content = YAML.load(File.read(@old_file)).reject {|k,v| k==:ignore}
|
68
|
+
@migrator.run
|
69
|
+
new_content = YAML.load(File.read(@new_file))
|
70
|
+
old_content.each do |key,val|
|
71
|
+
assert new_content.include?(key.to_s)
|
72
|
+
assert new_content[key.to_s].to_s==old_content[key].to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|