taq-traquitana 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.
- data/bin/traq +14 -0
- data/config/default.yml +19 -0
- data/config/passenger.sh +7 -0
- data/config/proc.sh +27 -0
- data/lib/config.rb +32 -0
- data/lib/deploy.rb +118 -0
- metadata +87 -0
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
|
data/config/default.yml
ADDED
@@ -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
|
data/config/passenger.sh
ADDED
data/config/proc.sh
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# move to the correct directory
|
2
|
+
cd $1/..
|
3
|
+
|
4
|
+
# make a copy of the old contents
|
5
|
+
echo Making a safe copy of the old contents ...
|
6
|
+
zip -q traq/$2.safe.zip `cat traq/$2.list`
|
7
|
+
echo Stored on traq/$2.safe.zip
|
8
|
+
|
9
|
+
# install the new files
|
10
|
+
echo
|
11
|
+
echo Unzipping the new content
|
12
|
+
echo -------------------------
|
13
|
+
unzip -o traq/$2.zip
|
14
|
+
|
15
|
+
# run migrations if needed
|
16
|
+
migrations=$(grep "^db/migrate" traq/$2.list)
|
17
|
+
|
18
|
+
if [ -n "$migrations" ]; then
|
19
|
+
echo
|
20
|
+
echo Running migrations
|
21
|
+
echo ------------------
|
22
|
+
echo $migrations
|
23
|
+
rake db:migrate
|
24
|
+
fi
|
25
|
+
|
26
|
+
# restart the server
|
27
|
+
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,118 @@
|
|
1
|
+
module Traquitana
|
2
|
+
class Deploy
|
3
|
+
TRAQ_VERSION="0.0.1"
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@config = Traquitana::Config.instance
|
7
|
+
end
|
8
|
+
|
9
|
+
def section_msg(msg)
|
10
|
+
puts "\n#{msg}"
|
11
|
+
puts "#{'-'*msg.size}\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
puts "Running setup"
|
16
|
+
if !File.exist?(@config.dir)
|
17
|
+
Dir.mkdir(@config.dir)
|
18
|
+
end
|
19
|
+
puts "Writing #{@config.config}"
|
20
|
+
File.open(@config.config,"w") do |file|
|
21
|
+
file << "# Default configuration"
|
22
|
+
file << File.read(@config.default)
|
23
|
+
end
|
24
|
+
puts "Setup completed!"
|
25
|
+
puts "You MUST check the configurations on #{@config.config} before deploying!"
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
if !File.exist?(@config.config)
|
31
|
+
STDERR.puts "No config file (#{@config.config}) found."
|
32
|
+
STDERR.puts "Did you run traq setup?"
|
33
|
+
STDERR.puts "Run it and check the configuration before deploying."
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
@config.load
|
37
|
+
|
38
|
+
puts "Running Traquitana version #{TRAQ_VERSION}\n"
|
39
|
+
puts "Connecting to #{@config.host} with #{@config.user}, sending files to #{@config.directory}"
|
40
|
+
section_msg("Checking changed files on the last #{@config.ignore} hour(s)")
|
41
|
+
all_list = []
|
42
|
+
|
43
|
+
for files in @config.list
|
44
|
+
send, ignore = files
|
45
|
+
puts "Will send #{send}"+(ignore ? " and ignore #{ignore}" : "")
|
46
|
+
send_list = Dir.glob(send)
|
47
|
+
next if send_list.size<1
|
48
|
+
if ignore
|
49
|
+
ignore_list = Dir.glob(ignore)
|
50
|
+
end
|
51
|
+
result = ignore_list ? send_list - ignore_list : send_list
|
52
|
+
result = result.select {|item| f = File.new(item); !File.directory?(item) && (Time.now-f.mtime)/3600 <= @config.ignore }
|
53
|
+
all_list.push(*result)
|
54
|
+
end
|
55
|
+
|
56
|
+
if all_list.size < 1
|
57
|
+
puts "\nNo files changed on the last #{@config.ignore} hour(s)."
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
# current id and files
|
62
|
+
id = Time.now.to_f.to_s.sub(/\./,"")
|
63
|
+
all_list_file = "#{id}.list"
|
64
|
+
all_list_zip = "#{id}.zip"
|
65
|
+
|
66
|
+
# first time running? send database.yml also
|
67
|
+
first_run_file = "traq/.first_run"
|
68
|
+
if Dir.glob(first_run_file).size<1
|
69
|
+
puts "Will send config/database.yml"
|
70
|
+
all_list << "config/database.yml"
|
71
|
+
FileUtils.touch(first_run_file)
|
72
|
+
end
|
73
|
+
|
74
|
+
File.open(all_list_file,"w") {|file| file << all_list.join("\n")}
|
75
|
+
section_msg("File list created")
|
76
|
+
|
77
|
+
section_msg("Creating ZIP file with #{all_list.size} files")
|
78
|
+
File.unlink(all_list_zip) if File.exist?(all_list_zip)
|
79
|
+
Zip::ZipFile.open(all_list_zip,true) do |zipfile|
|
80
|
+
all_list.each do |file|
|
81
|
+
puts "Adding #{file} ..."
|
82
|
+
zipfile.add(file,file)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
puts "ZIP file created."
|
86
|
+
|
87
|
+
section_msg("Sending list, ZIP file and control files to remote host")
|
88
|
+
migrate = all_list.find {|item| item =~ /db\/migrate/}
|
89
|
+
options = @config.password.size>1 ? {:password=>@config.password} : {}
|
90
|
+
|
91
|
+
# check if the traq directory exists
|
92
|
+
Net::SSH.start(@config.host,@config.user,options) do |ssh|
|
93
|
+
ssh.exec!("mkdir -p #{@config.directory}/traq")
|
94
|
+
end
|
95
|
+
|
96
|
+
Net::SCP.start(@config.host,@config.user,options) do |scp|
|
97
|
+
scp.upload!("#{File.dirname(File.expand_path(__FILE__))}/../config/proc.sh","#{@config.directory}/traq/proc.sh")
|
98
|
+
scp.upload!("#{File.dirname(File.expand_path(__FILE__))}/../config/#{@config.server}.sh","#{@config.directory}/traq/server.sh")
|
99
|
+
scp.upload!(all_list_file,"#{@config.directory}/traq/#{all_list_file}")
|
100
|
+
scp.upload!(all_list_zip ,"#{@config.directory}/traq/#{all_list_zip}")
|
101
|
+
end
|
102
|
+
section_msg("Running processes on the remote server")
|
103
|
+
|
104
|
+
Net::SSH.start(@config.host,@config.user,options) do |ssh|
|
105
|
+
result = ""
|
106
|
+
ssh.exec!("#{@config.directory}/traq/proc.sh #{@config.directory}/traq #{all_list_file.split(File.extname(all_list_file).first)}") do |channel, stream, data|
|
107
|
+
result << data
|
108
|
+
end
|
109
|
+
puts result
|
110
|
+
end
|
111
|
+
puts "\nDone. Have fun.\n"
|
112
|
+
|
113
|
+
# clean up
|
114
|
+
File.unlink(all_list_file)
|
115
|
+
File.unlink(all_list_zip)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: taq-traquitana
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eustaquio 'TaQ' Rangel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-12 00:00:00 -07: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: false
|
61
|
+
homepage: http://github.com/taq/traquitana
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.2.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 2
|
85
|
+
summary: Simple tool for deploy Rails apps
|
86
|
+
test_files: []
|
87
|
+
|