gploy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +24 -0
- data/Rakefile +51 -0
- data/bin/gploy +32 -0
- data/lib/gploy/configure.rb +132 -0
- data/lib/gploy/helpers.rb +86 -0
- data/lib/gploy.rb +2 -0
- metadata +81 -0
data/README.textile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
h2. LICENSE:
|
2
|
+
|
3
|
+
(The MIT License)
|
4
|
+
|
5
|
+
Copyright (c) 2008 Edipo Luis Federle
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
a copy of this software and associated documentation files (the
|
9
|
+
'Software'), to deal in the Software without restriction, including
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
21
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
23
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
24
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/specification'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
|
7
|
+
GEM = "gploy"
|
8
|
+
GEM_VERSION = "0.0.1"
|
9
|
+
SUMMARY = "Sample gem to configure rails project deploy using git(locaweb server only)"
|
10
|
+
AUTHOR = "Edipo Luis Federle"
|
11
|
+
EMAIL = "edipofederle@gmail.com"
|
12
|
+
HOMEPAGE = "http://edipolf.com"
|
13
|
+
|
14
|
+
|
15
|
+
spec = Gem::Specification.new do |s|
|
16
|
+
s.name = GEM
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.summary = SUMMARY
|
20
|
+
s.require_paths = ['bin', 'lib']
|
21
|
+
s.executables = ["gploy"]
|
22
|
+
s.add_dependency(%q<rubigen>, [">= 1.3.4"])
|
23
|
+
s.files = FileList['bin/*', 'lib/**/*.rb', '[A-Z]*'].to_a
|
24
|
+
|
25
|
+
s.author = AUTHOR
|
26
|
+
s.email = EMAIL
|
27
|
+
s.homepage = HOMEPAGE
|
28
|
+
|
29
|
+
s.rubyforge_project = GEM # GitHub bug, gem isn't being build when this miss
|
30
|
+
end
|
31
|
+
|
32
|
+
Spec::Rake::SpecTask.new do |t|
|
33
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
34
|
+
t.spec_opts = %w(-fs --color)
|
35
|
+
end
|
36
|
+
|
37
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
38
|
+
pkg.gem_spec = spec
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Install the gem locally"
|
42
|
+
task :install => [:package] do
|
43
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Create a gemspec file"
|
47
|
+
task :make_spec do
|
48
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
49
|
+
file.puts spec.to_ruby
|
50
|
+
end
|
51
|
+
end
|
data/bin/gploy
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "rubigen"
|
5
|
+
|
6
|
+
if %w(-v --version).include? ARGV.first
|
7
|
+
require "gploy"
|
8
|
+
puts "#{File.basename($0)} - #{Gploy::Configure::VERSION}"
|
9
|
+
exit(0)
|
10
|
+
end
|
11
|
+
|
12
|
+
if %(-configure -c).include? ARGV.first
|
13
|
+
require "gploy"
|
14
|
+
c = Gploy::Configure.new
|
15
|
+
c.configure_server
|
16
|
+
end
|
17
|
+
if %(-pr).include? ARGV.first
|
18
|
+
require "gploy"
|
19
|
+
c = Gploy::Configure.new
|
20
|
+
c.configure_hook
|
21
|
+
end
|
22
|
+
if %(-setup -s).include? ARGV.first
|
23
|
+
require "gploy"
|
24
|
+
c = Gploy::Configure.new
|
25
|
+
c.setup
|
26
|
+
end
|
27
|
+
if %(-update-hook -uh).include? ARGV.first
|
28
|
+
require "gploy"
|
29
|
+
c = Gploy::Configure.new
|
30
|
+
c.upload_hook
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'net/ssh'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'yaml'
|
5
|
+
require 'net/sftp'
|
6
|
+
|
7
|
+
module Gploy
|
8
|
+
class Configure
|
9
|
+
|
10
|
+
include Helpers
|
11
|
+
VERSION = '0.0.1'
|
12
|
+
|
13
|
+
def configure_server
|
14
|
+
create_file_and_direcotry_unless_exists("config", "config.yaml")
|
15
|
+
puts "Files created into the config directory. Now need edit config.yaml"
|
16
|
+
puts ""
|
17
|
+
puts "A suggestion for you"
|
18
|
+
puts "---------------------------------------------------------"
|
19
|
+
puts "You can put this content into your config.yaml file and edit it"
|
20
|
+
post_commands_server
|
21
|
+
puts ""
|
22
|
+
end
|
23
|
+
|
24
|
+
def configure_hook
|
25
|
+
read_config_file
|
26
|
+
create_file_and_direcotry_unless_exists("config", "post-receive")
|
27
|
+
puts "Now you should edit config/post-receive file, like this:"
|
28
|
+
puts ""
|
29
|
+
post_commands
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
read_config_file
|
34
|
+
remote
|
35
|
+
initialize_local_repo
|
36
|
+
create_repo(@app_name)
|
37
|
+
add_remote(@url, @user, @app_name, @origin)
|
38
|
+
push_local(@origin)
|
39
|
+
clone_into_server(@app_name)
|
40
|
+
sys_link(@app_name)
|
41
|
+
tmp_create(@app_name)
|
42
|
+
update_hook_into_server(@user, @url, @app_name)
|
43
|
+
run_tasks
|
44
|
+
puts "OK. No error Found. You now can run git push #{@origin} master for update your project"
|
45
|
+
end
|
46
|
+
|
47
|
+
def upload_hook
|
48
|
+
read_config_file
|
49
|
+
remote
|
50
|
+
update_hook(@user, @url, @app_name)
|
51
|
+
puts "File successfully Updated"
|
52
|
+
end
|
53
|
+
|
54
|
+
def path
|
55
|
+
"config/post-receive"
|
56
|
+
end
|
57
|
+
|
58
|
+
def run_tasks
|
59
|
+
puts "Run db:migrate and Restart Server"
|
60
|
+
migrate(@app_name)
|
61
|
+
restart_server(@app_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def read_config_file
|
65
|
+
config = YAML.load_file("config/config.yaml")
|
66
|
+
config["config"].each { |key, value| instance_variable_set("@#{key}", value) }
|
67
|
+
end
|
68
|
+
|
69
|
+
def remote
|
70
|
+
@shell = start(@url, @user, @password)
|
71
|
+
end
|
72
|
+
|
73
|
+
def start(server, user, pass)
|
74
|
+
Net::SSH.start(server, user, :password => pass)
|
75
|
+
end
|
76
|
+
|
77
|
+
def path_hook(name)
|
78
|
+
"~/repos/#{name}.git/hooks/post-receive"
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_repo(name)
|
82
|
+
run_remote "cd repos/ && mkdir #{name}.git && cd #{name}.git && git init --bare"
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_hook_file
|
86
|
+
unless dirExists?("config")
|
87
|
+
Dir.mkdir("config")
|
88
|
+
end
|
89
|
+
FileUtils.touch("config/post-receive")
|
90
|
+
end
|
91
|
+
|
92
|
+
def initialize_local_repo
|
93
|
+
puts "Starting local git repository"
|
94
|
+
unless dirExists?(".git/")
|
95
|
+
execute("git init && git add . && git commit -m 'Initial Commit' ")
|
96
|
+
else
|
97
|
+
puts "Git is already configured in this project"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_file_and_direcotry_unless_exists(dir, file)
|
102
|
+
unless dirExists?("#{dir}")
|
103
|
+
puts "directory #{dir} created successfully"
|
104
|
+
Dir.mkdir(dir)
|
105
|
+
end
|
106
|
+
unless File.exists?("config/#{file}")
|
107
|
+
puts "File #{file} created successfully"
|
108
|
+
FileUtils.touch "#{dir}/#{file}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def add_remote(server, user, name, origin)
|
113
|
+
execute("git remote add #{origin} #{user}@#{server}:~/repos/#{name}.git")
|
114
|
+
end
|
115
|
+
|
116
|
+
def clone(name)
|
117
|
+
@shell.exec!("git clone ~/repos/#{name}.git ~/rails_app/#{name}")
|
118
|
+
end
|
119
|
+
|
120
|
+
def clone_into_server(name)
|
121
|
+
run_remote "git clone repos/#{name}.git ~/rails_app/#{name}"
|
122
|
+
end
|
123
|
+
|
124
|
+
def push_local(origin)
|
125
|
+
run "git push #{origin} master"
|
126
|
+
end
|
127
|
+
|
128
|
+
def tmp_create(name)
|
129
|
+
run_remote "cd rails_app/#{name}/ && mkdir tmp"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'logger'
|
2
|
+
module Gploy
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def log_messager(msg)
|
6
|
+
@log.info(msg)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run_remote(command)
|
10
|
+
@shell.exec!(command)
|
11
|
+
end
|
12
|
+
|
13
|
+
def dirExists?(dir)
|
14
|
+
File.directory? dir
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(command)
|
18
|
+
Kernel.system command
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(command, disable_sudo = false)
|
22
|
+
if disable_sudo
|
23
|
+
Kernel.system command
|
24
|
+
else
|
25
|
+
Kernel.system "#{@sudo}#{command}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def sys_link(name)
|
30
|
+
puts "Symbolic link created successfully"
|
31
|
+
run_remote "ln -s ~/rails_app/#{name}/public ~/public_html/#{name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def read_hook_sample(name)
|
35
|
+
puts "Escrevendo Hook File"
|
36
|
+
path = "~/repos/#{name}.git/hooks/post-receive"
|
37
|
+
File.open("config/post-receive", "r") do |fline|
|
38
|
+
while(line = fline.gets)
|
39
|
+
@shell.exec!("echo '#{line}' >> #{path}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_hook_into_server(username, url, name)
|
45
|
+
run "chmod +x config/post-receive && scp config/post-receive #{username}@#{url}:repos/#{name}.git/hooks/"
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_hook(username, url, name)
|
49
|
+
run "scp config/post-receive #{username}@#{url}:repos/#{name}.git/hooks/"
|
50
|
+
end
|
51
|
+
|
52
|
+
def migrate(name)
|
53
|
+
run_remote "cd rails_app/#{name}/ && rake db:migrate RAILS_ENV=production"
|
54
|
+
end
|
55
|
+
|
56
|
+
def restart_server(name)
|
57
|
+
run_remote "cd rails_app/#{name}/tmp && touch restart.txt"
|
58
|
+
puts "Server Restarted"
|
59
|
+
end
|
60
|
+
|
61
|
+
def post_commands
|
62
|
+
commands = <<CMD
|
63
|
+
#!/bin/sh
|
64
|
+
cd ~/rails_app/#{@app_name}
|
65
|
+
env -i git reset --hard
|
66
|
+
env -i git pull #{@origin} master
|
67
|
+
env -i rake db:migrate RAILS_ENV=production
|
68
|
+
env -i touch ~/rails_app/#{@app_name}/tmp/restart.txt
|
69
|
+
|
70
|
+
CMD
|
71
|
+
puts commands
|
72
|
+
end
|
73
|
+
|
74
|
+
def post_commands_server
|
75
|
+
commands = <<CMD
|
76
|
+
config:
|
77
|
+
url: <user_server>
|
78
|
+
user: <userbae>
|
79
|
+
password: <password>
|
80
|
+
app_name: <app_name>
|
81
|
+
origin: <git origin>
|
82
|
+
CMD
|
83
|
+
puts commands
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/gploy.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Edipo Luis Federle
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-23 00:00:00 -03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rubigen
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 3
|
30
|
+
- 4
|
31
|
+
version: 1.3.4
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description:
|
35
|
+
email: edipofederle@gmail.com
|
36
|
+
executables:
|
37
|
+
- gploy
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- bin/gploy
|
44
|
+
- lib/gploy/configure.rb
|
45
|
+
- lib/gploy/helpers.rb
|
46
|
+
- lib/gploy.rb
|
47
|
+
- Rakefile
|
48
|
+
- README.textile
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://edipolf.com
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- bin
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project: gploy
|
76
|
+
rubygems_version: 1.3.6
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Sample gem to configure rails project deploy using git(locaweb server only)
|
80
|
+
test_files: []
|
81
|
+
|