gploy 0.1.7 → 0.2.0
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/.deploys +3 -0
- data/.gitignore +7 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +54 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +2 -12
- data/bin/gploy +31 -45
- data/config/gploy.yml +14 -0
- data/gploy.gemspec +22 -28
- data/lib/gploy.rb +3 -6
- data/lib/gploy/configure.rb +61 -144
- data/lib/gploy/deep_symbolize.rb +61 -0
- data/lib/gploy/gploy.yml +10 -0
- data/lib/gploy/helpers.rb +10 -84
- data/lib/gploy/settings.rb +35 -0
- data/lib/gploy/version.rb +3 -0
- data/spec/config/gploy.yml +14 -0
- data/spec/gploy_spec.rb +36 -0
- data/spec/settings_spec.rb +22 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/tasks +3 -0
- data/tmp/rspec_guard_result +1 -0
- metadata +130 -80
- data/Manifest +0 -23
- data/README.markdown +0 -120
- data/config/config.yaml +0 -0
- data/config/post-receive +0 -0
- data/install.rb +0 -0
- data/lib/TODO.txt +0 -1
- data/lib/gploy/logger.rb +0 -8
- data/lib/gploy/teste.rb +0 -5
- data/test/TimeChange.rb +0 -14
- data/test/config/config.yaml +0 -0
- data/test/config/post-receive +0 -0
- data/test/db/schema.rb +0 -0
- data/test/helper.rb +0 -24
- data/test/suite.rb +0 -7
- data/test/test_configuration.rb +0 -23
- data/test/test_configure.rb +0 -143
- data/test/test_logger.rb +0 -0
- data/test/unMocker.rb +0 -13
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
# Symbolizes all of hash's keys and subkeys.
|
3
|
+
# Also allows for custom pre-processing of keys (e.g. downcasing, etc)
|
4
|
+
# if the block is given:
|
5
|
+
#
|
6
|
+
# somehash.deep_symbolize { |key| key.downcase }
|
7
|
+
#
|
8
|
+
# Usage: either include it into global Hash class to make it available to
|
9
|
+
# to all hashes, or extend only your own hash objects with this
|
10
|
+
# module.
|
11
|
+
# E.g.:
|
12
|
+
# 1) class Hash; include DeepSymbolizable; end
|
13
|
+
# 2) myhash.extend DeepSymbolizable
|
14
|
+
|
15
|
+
module DeepSymbolizable
|
16
|
+
def deep_symbolize(&block)
|
17
|
+
method = self.class.to_s.downcase.to_sym
|
18
|
+
syms = DeepSymbolizable::Symbolizers
|
19
|
+
syms.respond_to?(method) ? syms.send(method, self, &block) : self
|
20
|
+
end
|
21
|
+
|
22
|
+
module Symbolizers
|
23
|
+
extend self
|
24
|
+
|
25
|
+
# the primary method - symbolizes keys of the given hash,
|
26
|
+
# preprocessing them with a block if one was given, and recursively
|
27
|
+
# going into all nested enumerables
|
28
|
+
def hash(hash, &block)
|
29
|
+
hash.inject({}) do |result, (key, value)|
|
30
|
+
# Recursively deep-symbolize subhashes
|
31
|
+
value = _recurse_(value, &block)
|
32
|
+
|
33
|
+
# Pre-process the key with a block if it was given
|
34
|
+
key = yield key if block_given?
|
35
|
+
# Symbolize the key string if it responds to to_sym
|
36
|
+
sym_key = key.to_sym rescue key
|
37
|
+
|
38
|
+
# write it back into the result and return the updated hash
|
39
|
+
result[sym_key] = value
|
40
|
+
result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# walking over arrays and symbolizing all nested elements
|
45
|
+
def array(ary, &block)
|
46
|
+
ary.map { |v| _recurse_(v, &block) }
|
47
|
+
end
|
48
|
+
|
49
|
+
# handling recursion - any Enumerable elements (except String)
|
50
|
+
# is being extended with the module, and then symbolized
|
51
|
+
def _recurse_(value, &block)
|
52
|
+
if value.is_a?(Enumerable) && !value.is_a?(String)
|
53
|
+
# support for a use case without extended core Hash
|
54
|
+
value.extend DeepSymbolizable unless value.class.include?(DeepSymbolizable)
|
55
|
+
value = value.deep_symbolize(&block)
|
56
|
+
end
|
57
|
+
value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/gploy/gploy.yml
ADDED
data/lib/gploy/helpers.rb
CHANGED
@@ -1,78 +1,15 @@
|
|
1
|
-
|
2
|
-
module Helpers
|
3
|
-
LOG_PATH = './log/gploylog.log'
|
4
|
-
|
5
|
-
def check_if_dir_log_exists
|
6
|
-
unless dirExists?("log")
|
7
|
-
Dir.mkdir("log")
|
8
|
-
false
|
9
|
-
else
|
10
|
-
true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def logger(msg, type)
|
15
|
-
puts "--> #{msg}"
|
16
|
-
File.open(LOG_PATH, 'a+') do |f|
|
17
|
-
f.puts "#{Time.now} => |#{type}| #{msg}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def run_remote(command)
|
22
|
-
@shell.exec!(command)
|
23
|
-
end
|
24
|
-
|
25
|
-
def dirExists?(dir)
|
26
|
-
File.directory? dir
|
27
|
-
end
|
1
|
+
require 'net/ssh'
|
28
2
|
|
29
|
-
|
3
|
+
module Gploy
|
4
|
+
module Helpers
|
5
|
+
def remote_command(host, user, password)
|
6
|
+
Net::SSH.start(host, user, :password => password)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run_local(command)
|
30
10
|
Kernel.system command
|
31
11
|
end
|
32
|
-
|
33
|
-
def sys_link(name)
|
34
|
-
run_remote "ln -s ~/rails_app/#{name}/public ~/public_html/#{name}"
|
35
|
-
end
|
36
|
-
|
37
|
-
def update_hook_into_server(username, url, name)
|
38
|
-
run_local "chmod +x config/post-receive && scp config/post-receive #{username}@#{url}:repos/#{name}.git/hooks/"
|
39
|
-
end
|
40
|
-
|
41
|
-
def update_hook(username, url, name)
|
42
|
-
run_local "scp config/post-receive #{username}@#{url}:repos/#{name}.git/hooks/"
|
43
|
-
end
|
44
12
|
|
45
|
-
def useMigrations?
|
46
|
-
if File.exists?("db/schema.rb")
|
47
|
-
true
|
48
|
-
else
|
49
|
-
false
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def migrate(name)
|
54
|
-
log("Running DB:MIGRATE for #{name} app")
|
55
|
-
if useMigrations?
|
56
|
-
run_remote "cd rails_app/#{name}/ && rake db:migrate RAILS_ENV=production"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def restart_server(name)
|
61
|
-
run_remote "cd rails_app/#{name}/tmp && touch restart.txt"
|
62
|
-
end
|
63
|
-
|
64
|
-
def post_commands(config)
|
65
|
-
commands = <<CMD
|
66
|
-
#!/bin/sh
|
67
|
-
cd ~/rails_app/#{config["config"]["app_name"]}
|
68
|
-
env -i git reset --hard
|
69
|
-
env -i git pull #{config["config"]["origin"]} master
|
70
|
-
env -i rake db:migrate RAILS_ENV=production
|
71
|
-
env -i touch ~/rails_app/#{config["config"]["app_name"]}/tmp/restart.txt
|
72
|
-
CMD
|
73
|
-
puts commands
|
74
|
-
end
|
75
|
-
|
76
13
|
def post_commands_server
|
77
14
|
commands = <<CMD
|
78
15
|
config:
|
@@ -84,17 +21,6 @@ CMD
|
|
84
21
|
CMD
|
85
22
|
puts commands
|
86
23
|
end
|
24
|
+
|
87
25
|
end
|
88
|
-
|
89
|
-
def colorize(text, color_code)
|
90
|
-
"#{color_code}#{text}e[0m"
|
91
|
-
end
|
92
|
-
|
93
|
-
def red(text)
|
94
|
-
colorize(text, "e[31m")
|
95
|
-
end
|
96
|
-
def green(text)
|
97
|
-
colorize(text, "e[32m")
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Settings
|
2
|
+
# again - it's a singleton, thus implemented as a self-extended module
|
3
|
+
extend self
|
4
|
+
|
5
|
+
@_settings = {}
|
6
|
+
attr_reader :_settings
|
7
|
+
|
8
|
+
# This is the main point of entry - we call Settings.load! and provide
|
9
|
+
# a name of the file to read as it's argument. We can also pass in some
|
10
|
+
# options, but at the moment it's being used to allow per-environment
|
11
|
+
# overrides in Rails
|
12
|
+
def load!(filename, options = {})
|
13
|
+
hsh = YAML::load_file(filename)
|
14
|
+
hsh.extend DeepSymbolizable
|
15
|
+
newsets = hsh.deep_symbolize
|
16
|
+
newsets = newsets[options[:env].to_sym] if \
|
17
|
+
options[:env] && \
|
18
|
+
newsets[options[:env].to_sym]
|
19
|
+
deep_merge!(@_settings, newsets)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Deep merging of hashes
|
23
|
+
# deep_merge by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
|
24
|
+
def deep_merge!(target, data)
|
25
|
+
merger = proc{|key, v1, v2|
|
26
|
+
Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
|
27
|
+
target.merge! data, &merger
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(name, *args, &block)
|
31
|
+
@_settings[name.to_sym] ||
|
32
|
+
fail(NoMethodError, "unknown configuration root #{name}", caller)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
ruby_env:
|
2
|
+
rake: /root/.rbenv/versions/1.9.3-p194/bin/rake
|
3
|
+
|
4
|
+
deploy:
|
5
|
+
url: localhost
|
6
|
+
user: root
|
7
|
+
password: secret
|
8
|
+
app_name: my_app
|
9
|
+
repo: https://github.com/edipofederle/blog.git
|
10
|
+
path: /var/www/apps
|
11
|
+
number_releases: 3
|
12
|
+
|
13
|
+
tasks:
|
14
|
+
dbmigrate: RAILS_ENV=production rake db:migrate
|
data/spec/gploy_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gploy'
|
3
|
+
|
4
|
+
describe Gploy do
|
5
|
+
|
6
|
+
let (:ssh_connection) { mock("SSH Connection") }
|
7
|
+
before (:each) do
|
8
|
+
Net::SSH.stub(:start) { ssh_connection }
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should setup server side' do
|
12
|
+
File.stub(:exists?).with("config/gploy.yml").and_return(true)
|
13
|
+
new_release = Time.now.to_s.gsub(/\W/, '')
|
14
|
+
|
15
|
+
ssh_connection.should_receive(:exec!).ordered.with("cd /var/www/apps && mkdir my_app && cd /var/www/apps/my_app && mkdir #{new_release}")
|
16
|
+
ssh_connection.should_receive(:exec!).ordered.with("cd /var/www/apps/my_app && git clone https://github.com/edipofederle/blog.git #{new_release}")
|
17
|
+
ssh_connection.should_receive(:exec!).ordered.with("cd /var/www/apps/my_app && ln -s #{new_release}/public/ current")
|
18
|
+
gploy = Gploy::Configure.new
|
19
|
+
out = capture_stdout{gploy.run("deploy:setup")}
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
it "test bin" do
|
24
|
+
gploy = Gploy::Configure.new
|
25
|
+
message = "invalid command. Valid commands are [\"help\", \"deploy:setup\", \"deploy:tasks\"]."
|
26
|
+
expect { gploy.run("teste") }.to raise_error(ArgumentError, message)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should execute tasks" do
|
30
|
+
new_release = Time.now.to_s.gsub(/\W/, '')
|
31
|
+
ssh_connection.should_receive(:exec!).ordered.with("cd /var/www/apps/my_app/#{new_release} && RAILS_ENV=production /root/.rbenv/versions/1.9.3-p194/bin/rake db:migrate")
|
32
|
+
gploy = Gploy::Configure.new
|
33
|
+
gploy.run("deploy:tasks")
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gploy'
|
3
|
+
|
4
|
+
describe Settings do
|
5
|
+
|
6
|
+
it "should read server configs" do
|
7
|
+
Settings.load!("spec/config/gploy.yml")
|
8
|
+
Settings.deploy[:url].should eq "localhost"
|
9
|
+
Settings.deploy[:password].should eq "secret"
|
10
|
+
Settings.deploy[:app_name].should eq "my_app"
|
11
|
+
Settings.deploy[:repo].should eq "https://github.com/edipofederle/blog.git"
|
12
|
+
Settings.deploy[:path].should eq "/var/www/apps"
|
13
|
+
Settings.deploy[:number_releases].should eq 3
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should read tasks configs" do
|
17
|
+
Settings.load!("spec/config/gploy.yml")
|
18
|
+
Settings.tasks[:dbmigrate].should eq "RAILS_ENV=production rake db:migrate"
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/tasks
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
metadata
CHANGED
@@ -1,103 +1,153 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gploy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 7
|
10
|
-
version: 0.1.7
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Edipo L Federle
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
date: 2013-06-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: net-ssh
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.6.7
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.6.7
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: net-sftp
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.1.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.1.1
|
78
|
+
description: Deployment
|
79
|
+
email:
|
80
|
+
- edipofederle@gmail.com
|
81
|
+
executables:
|
24
82
|
- gploy
|
25
83
|
extensions: []
|
26
|
-
|
27
|
-
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
files:
|
37
|
-
- Manifest
|
38
|
-
- README.markdown
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .DS_Store
|
87
|
+
- .deploys
|
88
|
+
- .gitignore
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- Guardfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
39
94
|
- Rakefile
|
40
95
|
- bin/gploy
|
41
|
-
- config/
|
42
|
-
-
|
43
|
-
-
|
44
|
-
- lib/TODO.txt
|
96
|
+
- config/gploy.yml
|
97
|
+
- gploy.gemspec
|
98
|
+
- lib/.DS_Store
|
45
99
|
- lib/gploy.rb
|
100
|
+
- lib/gploy/.DS_Store
|
46
101
|
- lib/gploy/configure.rb
|
102
|
+
- lib/gploy/deep_symbolize.rb
|
103
|
+
- lib/gploy/gploy.yml
|
47
104
|
- lib/gploy/helpers.rb
|
48
|
-
- lib/gploy/
|
49
|
-
- lib/gploy/
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
- test/test_logger.rb
|
59
|
-
- test/unMocker.rb
|
60
|
-
- gploy.gemspec
|
105
|
+
- lib/gploy/settings.rb
|
106
|
+
- lib/gploy/version.rb
|
107
|
+
- spec/.DS_Store
|
108
|
+
- spec/config/.DS_Store
|
109
|
+
- spec/config/gploy.yml
|
110
|
+
- spec/gploy_spec.rb
|
111
|
+
- spec/settings_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/tasks
|
114
|
+
- tmp/rspec_guard_result
|
61
115
|
homepage: http://github.com/edipofederle/gploy
|
62
|
-
licenses:
|
63
|
-
|
116
|
+
licenses:
|
117
|
+
- MIT
|
64
118
|
post_install_message:
|
65
|
-
rdoc_options:
|
66
|
-
|
67
|
-
- --inline-source
|
68
|
-
- --title
|
69
|
-
- Gploy
|
70
|
-
- --main
|
71
|
-
- README.markdown
|
72
|
-
require_paths:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
73
121
|
- lib
|
74
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
123
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
80
|
-
segments:
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
segments:
|
81
129
|
- 0
|
82
|
-
|
83
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
hash: -4607167905146522349
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
132
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
|
89
|
-
segments:
|
90
|
-
-
|
91
|
-
-
|
92
|
-
version: "1.2"
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
hash: -4607167905146522349
|
93
140
|
requirements: []
|
94
|
-
|
95
|
-
|
96
|
-
rubygems_version: 1.8.5
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 1.8.24
|
97
143
|
signing_key:
|
98
144
|
specification_version: 3
|
99
|
-
summary:
|
100
|
-
test_files:
|
101
|
-
-
|
102
|
-
-
|
103
|
-
-
|
145
|
+
summary: Deployment with git
|
146
|
+
test_files:
|
147
|
+
- spec/.DS_Store
|
148
|
+
- spec/config/.DS_Store
|
149
|
+
- spec/config/gploy.yml
|
150
|
+
- spec/gploy_spec.rb
|
151
|
+
- spec/settings_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
- spec/tasks
|