traquitana 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/traq ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "yaml"
5
+ require "zip/zip"
6
+ require "net/scp"
7
+ require "net/ssh"
8
+ require "fileutils"
9
+ require File.dirname(__FILE__)+"/../lib/config.rb"
10
+ require File.dirname(__FILE__)+"/../lib/deploy.rb"
11
+
12
+ traq = Traquitana::Deploy.new
13
+ traq.setup if ARGV[0] =~ /setup/
14
+ traq.run
@@ -0,0 +1,19 @@
1
+ # Default configuration---
2
+ :directory: /tmp/traq_test
3
+ :ignore: 24
4
+ :user: taq
5
+ :list:
6
+ - - app/**/*
7
+ - - config/initializers/**/*
8
+ - - config/environments/production.rb
9
+ - - db/migrate/**/*
10
+ - - public/javascripts/**/*
11
+ - - public/stylesheets/**/*
12
+ - - config/locales/**/*
13
+ - - config/routes.rb
14
+ - - lib/**/*
15
+ - - public/images/**/*
16
+ - public/images/uploads/**/*
17
+ :password: fill your password here
18
+ :host: localhost
19
+ :server: passenger
@@ -0,0 +1,7 @@
1
+ echo
2
+ echo Restarting Passenger
3
+ echo --------------------
4
+ # sometimes passenger needs a "forced" tip to restart - removing the file first
5
+ rm -f tmp/restart.txt
6
+ touch tmp/restart.txt
7
+ echo Ok.
data/config/proc.sh ADDED
@@ -0,0 +1,36 @@
1
+ # force the production enviroment
2
+ export RAILS_ENV=production
3
+
4
+ # move to the correct directory
5
+ cd $1/..
6
+
7
+ # make a copy of the old contents
8
+ echo Making a safe copy of the old contents ...
9
+ zip -q traq/$2.safe.zip `cat traq/$2.list`
10
+ echo Stored on traq/$2.safe.zip
11
+
12
+ # install the new files
13
+ echo
14
+ echo Unzipping the new content
15
+ echo -------------------------
16
+ unzip -o traq/$2.zip
17
+
18
+ # run migrations if needed
19
+ migrations=$(grep "^db/migrate" traq/$2.list)
20
+
21
+ if [ -n "$migrations" ]; then
22
+ echo
23
+ echo Running migrations
24
+ echo ------------------
25
+ rake db:migrate
26
+ fi
27
+
28
+ # change file permissions on public dir
29
+ echo
30
+ echo Changing file permissions on public to 0755
31
+ echo -------------------------------------------
32
+ chmod -R 0755 public/*
33
+ echo Changed.
34
+
35
+ # restart the server
36
+ traq/server.sh
data/lib/config.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "singleton"
2
+
3
+ module Traquitana
4
+ class Config
5
+ include Singleton
6
+
7
+ def initialize
8
+ @configs = {}
9
+ end
10
+
11
+ def dir
12
+ "traq"
13
+ end
14
+
15
+ def config
16
+ "#{dir}/config.yml"
17
+ end
18
+
19
+ def default
20
+ "#{File.dirname(File.expand_path(__FILE__))}/../config/default.yml"
21
+ end
22
+
23
+ def load
24
+ @configs = YAML.load(File.read(config))
25
+ end
26
+
27
+ def method_missing(meth)
28
+ c = @configs[meth.to_sym]
29
+ c ? c : ""
30
+ end
31
+ end
32
+ end
data/lib/deploy.rb ADDED
@@ -0,0 +1,147 @@
1
+ module Traquitana
2
+ class Deploy
3
+ TRAQ_VERSION="0.0.5"
4
+
5
+ def initialize
6
+ @config = Traquitana::Config.instance
7
+ @progress = -1
8
+ end
9
+
10
+ def section_msg(msg)
11
+ puts "\n#{msg}"
12
+ puts "#{'-'*msg.size}\n"
13
+ end
14
+
15
+ def setup
16
+ puts "Running setup"
17
+ if !File.exist?(@config.dir)
18
+ Dir.mkdir(@config.dir)
19
+ end
20
+ puts "Writing #{@config.config}"
21
+ File.open(@config.config,"w") do |file|
22
+ file << "# Default configuration"
23
+ file << File.read(@config.default)
24
+ end
25
+ puts "Setup completed!"
26
+ puts "You MUST check the configurations on #{@config.config} before deploying!"
27
+ exit 1
28
+ end
29
+
30
+ def show_bar(name,sent,total)
31
+ bt, bp = 20, 5
32
+ return if sent<=0
33
+
34
+ prop = sent > 0 ? ((100/(total/sent.to_f))/bp).to_i : 0
35
+ return if prop<=0
36
+
37
+ if prop != @progress
38
+ bar = Array.new(bt,"-")
39
+ bar[0...prop] = Array.new(prop,"*")
40
+ name = File.basename(name).ljust(20)
41
+ STDOUT.print "Sending #{name} #{(prop*bp).to_s.rjust(3)}% : #{bar.join}\r"
42
+ STDOUT.flush
43
+ @progress = prop
44
+ end
45
+ if sent==total
46
+ puts "\n#{name.strip} sent.\n"
47
+ @progress = -1
48
+ end
49
+ end
50
+
51
+ def upload(scp,from,to)
52
+ puts " "
53
+ scp.upload!(from,to) do |ch,name,sent,total|
54
+ show_bar(name,sent,total)
55
+ end
56
+ end
57
+
58
+ def run
59
+ if !File.exist?(@config.config)
60
+ STDERR.puts "No config file (#{@config.config}) found."
61
+ STDERR.puts "Did you run traq setup?"
62
+ STDERR.puts "Run it and check the configuration before deploying."
63
+ exit 1
64
+ end
65
+ @config.load
66
+
67
+ puts "Running Traquitana version #{TRAQ_VERSION}\n"
68
+ puts "Connecting to #{@config.host} with #{@config.user}, sending files to #{@config.directory}"
69
+ section_msg("Checking changed files on the last #{@config.ignore} hour(s)")
70
+ all_list = []
71
+
72
+ for files in @config.list
73
+ send, ignore = files
74
+ puts "Will send #{send}"+(ignore ? " and ignore #{ignore}" : "")
75
+ send_list = Dir.glob(send)
76
+ next if send_list.size<1
77
+ if ignore
78
+ ignore_list = Dir.glob(ignore)
79
+ end
80
+ result = ignore_list ? send_list - ignore_list : send_list
81
+ result = result.select {|item| f = File.new(item); !File.directory?(item) && (Time.now-f.mtime)/3600 <= @config.ignore }
82
+ all_list.push(*result)
83
+ end
84
+
85
+ if all_list.size < 1
86
+ puts "\nNo files changed on the last #{@config.ignore} hour(s)."
87
+ exit 1
88
+ end
89
+
90
+ # current id and files
91
+ id = Time.now.to_f.to_s.sub(/\./,"")
92
+ all_list_file = "#{id}.list"
93
+ all_list_zip = "#{id}.zip"
94
+
95
+ # first time running? send database.yml also
96
+ first_run_file = "traq/.first_run"
97
+ if Dir.glob(first_run_file).size<1
98
+ puts "Will send config/database.yml"
99
+ all_list << "config/database.yml"
100
+ FileUtils.touch(first_run_file)
101
+ end
102
+
103
+ File.open(all_list_file,"w") {|file| file << all_list.join("\n")}
104
+ section_msg("File list created")
105
+
106
+ section_msg("Creating ZIP file with #{all_list.size} files")
107
+ File.unlink(all_list_zip) if File.exist?(all_list_zip)
108
+ Zip::ZipFile.open(all_list_zip,true) do |zipfile|
109
+ all_list.each do |file|
110
+ puts "Adding #{file} ..."
111
+ zipfile.add(file,file)
112
+ end
113
+ end
114
+ puts "ZIP file created."
115
+
116
+ section_msg("Sending list, ZIP file and control files to remote host")
117
+ migrate = all_list.find {|item| item =~ /db\/migrate/}
118
+ options = @config.password.size>1 ? {:password=>@config.password} : {}
119
+
120
+ # check if the traq directory exists
121
+ Net::SSH.start(@config.host,@config.user,options) do |ssh|
122
+ ssh.exec!("mkdir -p #{@config.directory}/traq")
123
+ end
124
+
125
+ Net::SCP.start(@config.host,@config.user,options) do |scp|
126
+ upload(scp,"#{File.dirname(File.expand_path(__FILE__))}/../config/proc.sh","#{@config.directory}/traq/proc.sh")
127
+ upload(scp,"#{File.dirname(File.expand_path(__FILE__))}/../config/#{@config.server}.sh","#{@config.directory}/traq/server.sh")
128
+ upload(scp,all_list_file,"#{@config.directory}/traq/#{all_list_file}")
129
+ upload(scp,all_list_zip ,"#{@config.directory}/traq/#{all_list_zip}")
130
+ end
131
+ section_msg("Running processes on the remote server")
132
+
133
+ Net::SSH.start(@config.host,@config.user,options) do |ssh|
134
+ result = ""
135
+ ssh.exec!("#{@config.directory}/traq/proc.sh #{@config.directory}/traq #{all_list_file.split(File.extname(all_list_file).first)}") do |channel, stream, data|
136
+ result << data
137
+ end
138
+ puts result
139
+ end
140
+ puts "\nDone. Have fun.\n"
141
+
142
+ # clean up
143
+ File.unlink(all_list_file)
144
+ File.unlink(all_list_zip)
145
+ end
146
+ end
147
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: traquitana
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Eustaquio 'TaQ' Rangel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-20 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubyzip
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: net-ssh
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: net-scp
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Simple tool for deploy Rails apps
46
+ email: eustaquiorangel@gmail.com
47
+ executables:
48
+ - traq
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - bin/traq
55
+ - lib/config.rb
56
+ - lib/deploy.rb
57
+ - config/default.yml
58
+ - config/passenger.sh
59
+ - config/proc.sh
60
+ has_rdoc: true
61
+ homepage: http://github.com/taq/traquitana
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Simple tool for deploy Rails apps
88
+ test_files: []
89
+