traquitana 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/config/default.yml +3 -0
- data/config/nginx.sh +0 -1
- data/config/passenger.sh +0 -1
- data/config/proc.sh +235 -61
- data/lib/deployer.rb +61 -61
- data/lib/ssh.rb +30 -10
- data/lib/traquitana/version.rb +1 -1
- data/spec/config/Gemfile +3 -0
- data/traquitana.gemspec +4 -3
- metadata +19 -3
data/config/default.yml
CHANGED
@@ -11,8 +11,11 @@ list:
|
|
11
11
|
- - config/environments/production.rb
|
12
12
|
- - config/locales/**/*
|
13
13
|
- - config/routes.rb
|
14
|
+
- - config/boot.rb
|
15
|
+
- - config/database.yml
|
14
16
|
- - app/**/*
|
15
17
|
- - db/migrate/**/*
|
18
|
+
- - db/seeds.rb
|
16
19
|
- - public/javascripts/**/*
|
17
20
|
- - public/stylesheets/**/*
|
18
21
|
- - lib/**/*
|
data/config/nginx.sh
CHANGED
data/config/passenger.sh
CHANGED
data/config/proc.sh
CHANGED
@@ -1,90 +1,264 @@
|
|
1
|
+
#
|
2
|
+
# Show a message
|
3
|
+
# msg(message, verbose, newline)
|
4
|
+
#
|
1
5
|
function msg() {
|
2
6
|
local str="$1"
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
|
8
|
+
echo "$str" >> $logfile
|
9
|
+
echo -e "$str"
|
10
|
+
}
|
11
|
+
|
12
|
+
#
|
13
|
+
# Show usage
|
14
|
+
#
|
15
|
+
function usage() {
|
16
|
+
echo "Usage:"
|
17
|
+
echo ""
|
18
|
+
echo "proc.sh <traq directory> <id> <verbose>"
|
19
|
+
echo ""
|
20
|
+
echo "-h Show this message"
|
21
|
+
echo "-o Show gem dir owner"
|
22
|
+
echo "-r Show gem dir owner, asking RVM"
|
23
|
+
echo "-g Show gem dir owner, asking Rubygems"
|
24
|
+
echo "-i Show gems provider (Rubygems, RVM, etc)"
|
25
|
+
echo "-d Show gems dir"
|
26
|
+
}
|
27
|
+
|
28
|
+
#
|
29
|
+
# Gem dir
|
30
|
+
#
|
31
|
+
function gem_dir() {
|
32
|
+
local provider=$(gem_provider)
|
33
|
+
if [ -z "${provider}" ]; then
|
34
|
+
echo ""
|
10
35
|
else
|
11
|
-
echo
|
36
|
+
echo $(${provider}_gemdir)
|
12
37
|
fi
|
13
38
|
}
|
14
39
|
|
15
|
-
#
|
16
|
-
|
40
|
+
#
|
41
|
+
# RVM gem dir
|
42
|
+
#
|
43
|
+
function rvm_gemdir() {
|
44
|
+
echo $(rvm gemdir)
|
45
|
+
}
|
17
46
|
|
18
|
-
#
|
19
|
-
|
47
|
+
#
|
48
|
+
# Rubygems gem dir
|
49
|
+
#
|
50
|
+
function rubygems_gemdir() {
|
51
|
+
echo $(gem environment | grep INSTALLATION | cut -f2- -d:)
|
52
|
+
}
|
53
|
+
|
54
|
+
#
|
55
|
+
# Return the RVM gems dir owner
|
56
|
+
#
|
57
|
+
function rvm_owner() {
|
58
|
+
echo $(stat --printf=%U $(rvm_gemdir))
|
59
|
+
}
|
20
60
|
|
21
|
-
#
|
22
|
-
|
61
|
+
#
|
62
|
+
# Return the gems dir owner
|
63
|
+
#
|
64
|
+
function rubygems_owner() {
|
65
|
+
echo $(stat --printf=%U $(rubygems_gemdir))
|
66
|
+
}
|
23
67
|
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
68
|
+
#
|
69
|
+
# Gems provider
|
70
|
+
#
|
71
|
+
function gem_provider() {
|
72
|
+
if [ -n "$(which rvm)" ]; then
|
73
|
+
echo "rvm"
|
74
|
+
elif [ -n "$(which gem)" ]; then
|
75
|
+
echo "rubygems"
|
76
|
+
else
|
77
|
+
echo ""
|
78
|
+
fi
|
79
|
+
}
|
28
80
|
|
29
|
-
#
|
30
|
-
|
81
|
+
#
|
82
|
+
# Find the current gem owner
|
83
|
+
# If not using RVM, returns the owner of the gem directory
|
84
|
+
#
|
85
|
+
function gemdir_owner() {
|
86
|
+
local provider=$(gem_provider)
|
87
|
+
if [ -z "${provider}" ]; then
|
88
|
+
echo $(whoami)
|
89
|
+
else
|
90
|
+
echo $(${provider}_owner)
|
91
|
+
fi
|
92
|
+
}
|
31
93
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
94
|
+
#
|
95
|
+
# Move to the app directory
|
96
|
+
#
|
97
|
+
function cd_app_dir() {
|
98
|
+
msg "Moving to ${dir} directory ..."
|
99
|
+
cd $1/..
|
100
|
+
}
|
36
101
|
|
37
|
-
#
|
38
|
-
|
102
|
+
#
|
103
|
+
# Make a copy of the old contents
|
104
|
+
#
|
105
|
+
function safe_copy() {
|
106
|
+
msg "Making a safety copy of the old contents on traq/$1.safe.zip ... "
|
107
|
+
zip -q traq/$1.safe.zip `cat traq/$1.list` &> /dev/null
|
108
|
+
}
|
39
109
|
|
40
|
-
#
|
41
|
-
|
110
|
+
#
|
111
|
+
# Install the new files
|
112
|
+
#
|
113
|
+
function install_new_files() {
|
114
|
+
msg "Unzipping $1.zip ... "
|
115
|
+
unzip -o traq/$1.zip &> /dev/null
|
116
|
+
}
|
42
117
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
118
|
+
#
|
119
|
+
# Create database if needed
|
120
|
+
#
|
121
|
+
function createdb() {
|
122
|
+
msg "Creating database if needed ..."
|
123
|
+
bundle exec rake db:create &> /dev/null
|
124
|
+
}
|
125
|
+
|
126
|
+
#
|
127
|
+
# Run migrations if needed
|
128
|
+
#
|
129
|
+
function migrate() {
|
130
|
+
migrations=$(grep "^db/migrate" traq/${config_id}.list)
|
131
|
+
if [ -n "$migrations" ]; then
|
132
|
+
msg "Running migrations ... "
|
133
|
+
bundle exec rake db:migrate 2> /dev/null
|
50
134
|
fi
|
135
|
+
}
|
51
136
|
|
52
|
-
|
53
|
-
|
54
|
-
|
137
|
+
#
|
138
|
+
# Precompile assets if needed
|
139
|
+
#
|
140
|
+
function assets() {
|
141
|
+
if [ -d app/assets ]; then
|
142
|
+
msg "Compiling assets ... "
|
143
|
+
bundle exec rake assets:precompile 2> /dev/null
|
144
|
+
fi
|
145
|
+
}
|
146
|
+
|
147
|
+
#
|
148
|
+
# Change file permissions on public dir
|
149
|
+
#
|
150
|
+
function permissions() {
|
151
|
+
if [ -d public ]; then
|
152
|
+
msg "Changing file permissions on public to 0755 ... "
|
153
|
+
chmod -R 0755 public/*
|
154
|
+
fi
|
155
|
+
}
|
156
|
+
|
157
|
+
#
|
158
|
+
# Fix current gems, running bundle
|
159
|
+
#
|
160
|
+
function fix_gems() {
|
161
|
+
msg "Fixing gems ..."
|
162
|
+
local basedir=$(gem_dir | cut -f1-3 -d/)
|
163
|
+
local owner=$(gemdir_owner)
|
164
|
+
local curdir=$(pwd)
|
165
|
+
local curuser=$(whoami)
|
166
|
+
msg "Gem dir owner is \e[1m${owner}\e[0m"
|
167
|
+
|
168
|
+
# if gemdir owner and current user is root, try to install gems system wide
|
169
|
+
if [ "${owner}" == "root" -a "${curuser}" == "root" ]; then
|
170
|
+
msg "Performing a \e[1msystem wide gem install using root\e[0m"
|
171
|
+
bundle install
|
172
|
+
# install gems on rvm system path or vendor/bundle
|
173
|
+
else
|
174
|
+
# if gemdir is the current user dir, install there
|
175
|
+
if [ "${basedir}" == "/home/${owner}" ]; then
|
176
|
+
msg "Performing a \e[1mlocal gem install on home dir\e[0m"
|
55
177
|
bundle install
|
178
|
+
# if user is not root and gemdir is not the home dir, install on vendor
|
56
179
|
else
|
57
|
-
msg "
|
180
|
+
msg "Performing a \e[1mlocal gem install on vendor/bundle\e[0m"
|
181
|
+
bundle install --path vendor/bundle
|
58
182
|
fi
|
59
183
|
fi
|
60
|
-
|
184
|
+
}
|
61
185
|
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
186
|
+
#
|
187
|
+
# Make a sanity check to see if all the tools needed are available
|
188
|
+
#
|
189
|
+
function sanity_check() {
|
190
|
+
if [ -z "$(which unzip)" ]; then
|
191
|
+
msg "\e[31mThere's no \e[1munzip\e[0;31m tool installed on the server. Please install it before proceeding again\e[0m"
|
192
|
+
exit 2
|
193
|
+
fi
|
194
|
+
}
|
69
195
|
|
70
|
-
#
|
71
|
-
|
72
|
-
msg "Compiling assets ... " "$verbose" "false"
|
73
|
-
bundle exec rake assets:precompile 2> /dev/null
|
74
|
-
msg "done." "$verbose" "true"
|
75
|
-
fi
|
196
|
+
# force the production enviroment
|
197
|
+
export RAILS_ENV=production
|
76
198
|
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
199
|
+
config_dir="$1" # config dir
|
200
|
+
config_id="$2" # config id
|
201
|
+
verbose="$3" # verbose mode
|
202
|
+
newline="true" # default newline on messages
|
203
|
+
logfile="/tmp/traq$$.log" # log file
|
204
|
+
|
205
|
+
# sanity check
|
206
|
+
sanity_check
|
207
|
+
|
208
|
+
# parse command line options
|
209
|
+
while getopts "horgid" OPTION
|
210
|
+
do
|
211
|
+
case ${OPTION} in
|
212
|
+
h)
|
213
|
+
usage
|
214
|
+
exit 1
|
215
|
+
;;
|
216
|
+
o)
|
217
|
+
echo "Gem dir owner is: $(gemdir_owner)"
|
218
|
+
exit 1
|
219
|
+
;;
|
220
|
+
r)
|
221
|
+
echo "RVM gem dir owner is: $(rvm_owner)"
|
222
|
+
exit 1
|
223
|
+
;;
|
224
|
+
g)
|
225
|
+
echo "Ruby gems dir owner is: $(rubygems_owner)"
|
226
|
+
exit 1
|
227
|
+
;;
|
228
|
+
i)
|
229
|
+
echo "Gems provider is $(gem_provider)"
|
230
|
+
exit 1
|
231
|
+
;;
|
232
|
+
d)
|
233
|
+
echo "Gems dir is $(gem_dir)"
|
234
|
+
exit 1
|
235
|
+
;;
|
236
|
+
*)
|
237
|
+
usage
|
238
|
+
exit 1
|
239
|
+
;;
|
240
|
+
esac
|
241
|
+
done
|
242
|
+
|
243
|
+
msg "Log file is ${logfile}"
|
244
|
+
|
245
|
+
# move to the correct directory
|
246
|
+
dir="${1}"
|
247
|
+
cd_app_dir "${dir}"
|
248
|
+
safe_copy "${config_id}"
|
249
|
+
|
250
|
+
# here is where things happens on the server
|
251
|
+
install_new_files "${config_id}"
|
252
|
+
fix_gems
|
253
|
+
createdb
|
254
|
+
migrate
|
255
|
+
assets
|
256
|
+
permissions
|
83
257
|
|
84
258
|
# restart server
|
85
259
|
if [ -x ./traq/server.sh -a -f ./traq/server.sh ]; then
|
86
260
|
./traq/server.sh
|
87
|
-
fi
|
261
|
+
fi
|
88
262
|
|
89
263
|
# extra configs
|
90
264
|
if [ -x ./traq/extra.sh -a -f ./traq/extra.sh ]; then
|
@@ -92,4 +266,4 @@ if [ -x ./traq/extra.sh -a -f ./traq/extra.sh ]; then
|
|
92
266
|
fi
|
93
267
|
|
94
268
|
# erase file
|
95
|
-
rm traq/$
|
269
|
+
rm traq/${config_id}.zip
|
data/lib/deployer.rb
CHANGED
@@ -1,63 +1,63 @@
|
|
1
1
|
module Traquitana
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
2
|
+
class Deployer
|
3
|
+
def initialize(options=nil)
|
4
|
+
@config = Traquitana::Config.instance
|
5
|
+
@verbose = !options.nil? && options[:verbose]
|
6
|
+
@config.filename = options[:filename] if options[:filename]
|
7
|
+
@config.target = options[:target] if options[:target]
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
STDOUT.puts "\e[1mRunning Traquitana version #{VERSION}\e[0m\n\n"
|
12
|
+
Traquitana::Migrator.new.run
|
13
|
+
|
14
|
+
if !File.exist?(@config.filename)
|
15
|
+
STDERR.puts "\e[31mNo config file (#{@config.filename}) found."
|
16
|
+
STDERR.puts "Did you run \e[1mtraq setup\e[0;31m ?"
|
17
|
+
STDERR.puts "Run it and check the configuration before deploying.\e[0m"
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
@config.load
|
22
|
+
|
23
|
+
@options = @config.password.size>1 ? {:password=>@config.password} : {}
|
24
|
+
@server = @config.server.to_s.size>0 ? @config.server : "none"
|
25
|
+
@shell = @config.shell ? "#{@config.shell} " : ""
|
26
|
+
@network = Traquitana::SSH.new(@config.host,@config.user,@options)
|
27
|
+
|
28
|
+
@packager = Traquitana::Packager.new
|
29
|
+
@packager.verbose = @verbose
|
30
|
+
all_list_file, all_list_zip = @packager.pack
|
31
|
+
if !File.exists?(all_list_file) ||
|
32
|
+
!File.exists?(all_list_zip)
|
33
|
+
STDERR.puts "\e[31mCould not create the needed files.\e[0m"
|
34
|
+
exit 2
|
35
|
+
end
|
36
|
+
|
37
|
+
# check if the traq destination and config directories exists
|
38
|
+
@network.execute(["mkdir -p #{@config.directory}/traq"],@verbose)
|
39
|
+
@updater = Traquitana::Bar.new
|
40
|
+
|
41
|
+
STDOUT.puts "Sending files ..."
|
42
|
+
@network.send_files([["#{File.dirname(File.expand_path(__FILE__))}/../config/proc.sh","#{@config.directory}/traq/proc.sh"],
|
43
|
+
["#{File.dirname(File.expand_path(__FILE__))}/../config/#{@server}.sh","#{@config.directory}/traq/server.sh"],
|
44
|
+
[all_list_file,"#{@config.directory}/traq/#{File.basename(all_list_file)}"],
|
45
|
+
[all_list_zip ,"#{@config.directory}/traq/#{File.basename(all_list_zip)}"]],@updater)
|
46
|
+
STDOUT.puts "\e[32mAll files sent.\e[0m\n\n"
|
47
|
+
|
48
|
+
@network.execute(["chmod +x #{@config.directory}/traq/proc.sh"],@verbose)
|
49
|
+
@network.execute(["chmod +x #{@config.directory}/traq/server.sh"],@verbose)
|
50
|
+
|
51
|
+
cmd = "#{@config.directory}/traq/proc.sh #{@config.directory}/traq #{@packager.id} #{@verbose}"
|
52
|
+
cmd = "#{@shell} \"#{cmd}\"" if @shell
|
53
|
+
|
54
|
+
STDOUT.puts "Running remote update commands, please wait ..."
|
55
|
+
STDOUT.puts @network.execute([cmd],@verbose).join
|
56
|
+
|
57
|
+
# clean up
|
58
|
+
File.unlink(all_list_file)
|
59
|
+
File.unlink(all_list_zip)
|
60
|
+
STDOUT.puts "\e[32mAll done. Have fun.\e[0m\n"
|
61
|
+
end
|
62
|
+
end
|
63
63
|
end
|
data/lib/ssh.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "net/scp"
|
2
2
|
require "net/ssh"
|
3
|
+
require "highline/import"
|
3
4
|
|
4
5
|
module Traquitana
|
5
6
|
class SSH
|
@@ -9,22 +10,41 @@ module Traquitana
|
|
9
10
|
@host = host
|
10
11
|
@user = user
|
11
12
|
@options = options || {}
|
12
|
-
|
13
|
+
@options[:verbose] = :error
|
14
|
+
STDOUT.puts "Connecting to \e[1m#{@host}\e[0m using user \e[1m#{@user}\e[0m"
|
13
15
|
end
|
14
16
|
|
15
17
|
def execute(cmds,verbose=false)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
rst = []
|
19
|
+
|
20
|
+
Net::SSH.start(@host,@user,@options) do |ssh|
|
21
|
+
ssh.open_channel do |channel|
|
22
|
+
channel.request_pty do |ch, success|
|
23
|
+
raise "Can't get PTY" unless success
|
24
|
+
for cmd in cmds
|
25
|
+
STDOUT.puts "Executing #{cmd} on remote host ..." if verbose
|
26
|
+
rst << ch.exec(cmd)
|
27
|
+
end # for
|
28
|
+
|
29
|
+
ch.on_data do |ch, data|
|
30
|
+
msg = data.inspect.to_s.gsub(/^"/,"").gsub(/"$/,"").gsub(/"\\"/,"\\").gsub("\\r","").gsub("\\n","\n").gsub("\\e","\e").strip.chomp
|
31
|
+
if data.inspect =~ /sudo/
|
32
|
+
pwd = ask("\nNeed password to run as root/sudo: ") {|c| c.echo = "*"}
|
33
|
+
channel.send_data("#{pwd}\n")
|
34
|
+
sleep 0.1
|
35
|
+
else
|
36
|
+
puts msg if msg.size > 1
|
37
|
+
end
|
38
|
+
ch.wait
|
39
|
+
end
|
40
|
+
end # tty
|
41
|
+
end # channel
|
42
|
+
end # ssh start
|
43
|
+
rst
|
24
44
|
end
|
25
45
|
|
26
46
|
def send_files(col,updater=nil)
|
27
|
-
|
47
|
+
Net::SCP.start(@host,@user,@options) do |scp|
|
28
48
|
for files in col
|
29
49
|
from, to = *files
|
30
50
|
next if from.nil? || to.nil?
|
data/lib/traquitana/version.rb
CHANGED
data/spec/config/Gemfile
CHANGED
data/traquitana.gemspec
CHANGED
@@ -15,9 +15,10 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Traquitana::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency("rubyzip", [">= 1.0.0"])
|
19
|
-
gem.add_dependency("net-ssh", [">= 0"])
|
20
|
-
gem.add_dependency("net-scp", [">= 0"])
|
18
|
+
gem.add_dependency("rubyzip" , [">= 1.0.0"])
|
19
|
+
gem.add_dependency("net-ssh" , [">= 0"])
|
20
|
+
gem.add_dependency("net-scp" , [">= 0"])
|
21
|
+
gem.add_dependency("highline", [">= 0"])
|
21
22
|
|
22
23
|
gem.license = "GPL-2"
|
23
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traquitana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubyzip
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: highline
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
description: Simple tool for deploy Rails apps
|
63
79
|
email:
|
64
80
|
- eustaquiorangel@gmail.com
|
@@ -153,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
169
|
version: '0'
|
154
170
|
requirements: []
|
155
171
|
rubyforge_project:
|
156
|
-
rubygems_version: 1.8.
|
172
|
+
rubygems_version: 1.8.23
|
157
173
|
signing_key:
|
158
174
|
specification_version: 3
|
159
175
|
summary: Just a simple tool to deploy Rails apps with SSH and some shell scripts
|