o2h 0.1.0 → 0.1.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/lib/o2h/recipes/deploy.rb +2 -1
- data/lib/o2h/recipes/sync.rb +76 -0
- data/lib/o2h/version.rb +1 -1
- data/o2h.gemspec +1 -0
- data/spec/recipes/deploy_spec.rb +5 -1
- data/spec/recipes/git_spec.rb +1 -2
- data/spec/recipes/sync_spec.rb +32 -0
- metadata +53 -47
data/lib/o2h/recipes/deploy.rb
CHANGED
@@ -14,9 +14,10 @@ set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEA
|
|
14
14
|
set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
|
15
15
|
set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip }
|
16
16
|
|
17
|
-
|
17
|
+
after 'deploy:update_code', 'deploy:set_permissions', :roles => :web
|
18
18
|
|
19
19
|
namespace :deploy do
|
20
|
+
|
20
21
|
task :set_permissions do
|
21
22
|
# Change the owner and group of everything under the
|
22
23
|
# deployment directory to webadmin and apache
|
@@ -0,0 +1,76 @@
|
|
1
|
+
_cset(:sync_db_via) { :scp }
|
2
|
+
_cset(:sync_db_file) { "#{application}-dump.sql.gz" }
|
3
|
+
_cset(:sync_db_remote_file) { "#{shared_path}/backup/#{sync_db_file}" }
|
4
|
+
_cset(:sync_db_remote_config) { "#{shared_path}/config/database.yml" }
|
5
|
+
_cset(:sync_db_local_file) { "tmp/#{sync_db_file}" }
|
6
|
+
_cset(:sync_db_local_config) { "config/database.yml" }
|
7
|
+
|
8
|
+
namespace :sync do
|
9
|
+
|
10
|
+
namespace :db do
|
11
|
+
#
|
12
|
+
# Reads the database credentials from the local config/database.yml file
|
13
|
+
# +db+ the name of the environment to get the credentials for
|
14
|
+
# Returns config hash
|
15
|
+
#
|
16
|
+
def database_config(db = rails_env)
|
17
|
+
database = YAML::load_file(sync_db_local_config)
|
18
|
+
database and database["#{db}"]
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Reads the database credentials from the remote config/database.yml file
|
23
|
+
# +db+ the name of the environment to get the credentials for
|
24
|
+
# Returns username, password, database
|
25
|
+
#
|
26
|
+
def remote_database_config(db = rails_env)
|
27
|
+
remote_config = capture("cat #{sync_db_remote_config}")
|
28
|
+
database = YAML::load(remote_config)
|
29
|
+
database and database["#{db}"]
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Dump, fetch and import remote database to local"
|
33
|
+
task :default do
|
34
|
+
dump
|
35
|
+
fetch
|
36
|
+
import
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Dump remote database to :sync_db_file"
|
40
|
+
task :dump do
|
41
|
+
file = sync_db_file
|
42
|
+
remote_file = sync_db_remote_file
|
43
|
+
|
44
|
+
remote = remote_database_config
|
45
|
+
|
46
|
+
raise "remote database config not found" unless remote
|
47
|
+
|
48
|
+
require 'pg_dumper'
|
49
|
+
|
50
|
+
pg = PgDumper.new(remote["database"], 'pg_dump')
|
51
|
+
pg.output = remote_file
|
52
|
+
pg.clean!
|
53
|
+
pg.compress! 9
|
54
|
+
pg.auth = remote
|
55
|
+
|
56
|
+
run pg.command
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Import database from :sync_db_local_file"
|
60
|
+
task :import do
|
61
|
+
local = database_config
|
62
|
+
raise "local database config not found" unless local
|
63
|
+
|
64
|
+
pg = PgDumper.new(local["database"], "psql")
|
65
|
+
pg.auth = local
|
66
|
+
|
67
|
+
run_locally "gunzip #{sync_db_local_file} | #{pg.command}"
|
68
|
+
end
|
69
|
+
|
70
|
+
task :fetch do
|
71
|
+
download sync_db_remote_file, sync_db_local_file, :via => sync_db_via
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
data/lib/o2h/version.rb
CHANGED
data/o2h.gemspec
CHANGED
data/spec/recipes/deploy_spec.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "deploy" do
|
4
|
+
before { subject.load('deploy') }
|
4
5
|
include_context :capistrano
|
5
6
|
|
7
|
+
let(:deploy) { subject.namespaces[:deploy] }
|
8
|
+
|
6
9
|
context "domain my-domain.com" do
|
7
10
|
before {
|
8
11
|
subject.set :domain, 'my-domain.com'
|
@@ -12,7 +15,8 @@ describe "deploy" do
|
|
12
15
|
its(:group) { should == :www }
|
13
16
|
|
14
17
|
it "performs set_permissions after deploy" do
|
15
|
-
|
18
|
+
# raise deploy.callbacks[:after].inspect
|
19
|
+
deploy.should callback(:set_permissions).after(:update_code)
|
16
20
|
end
|
17
21
|
|
18
22
|
context 'set_permissions task' do
|
data/spec/recipes/git_spec.rb
CHANGED
@@ -5,8 +5,7 @@ describe "git" do
|
|
5
5
|
|
6
6
|
its(:scm) { should == :git }
|
7
7
|
its(:branch) { should == :master }
|
8
|
-
its(:deploy_via) { should == :
|
9
|
-
its(:git_shallow_clone) { should == true }
|
8
|
+
its(:deploy_via) { should == :remote_git }
|
10
9
|
its(:git_enable_submodules) { should == true }
|
11
10
|
|
12
11
|
context 'without application set' do
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "sync" do
|
4
|
+
before { subject.load 'deploy' }
|
5
|
+
|
6
|
+
include_context :capistrano
|
7
|
+
|
8
|
+
context 'db task' do
|
9
|
+
let(:application) { "app" }
|
10
|
+
let(:host) { "host" }
|
11
|
+
let(:port) { "port" }
|
12
|
+
let(:username) { "username" }
|
13
|
+
let(:namespace) { subject.namespaces[:sync].namespaces[:db] }
|
14
|
+
let(:database) { "o2h-db" }
|
15
|
+
let(:remote_database) { {"database" => database, "host" => host, "port" => port, "username" => username} }
|
16
|
+
let(:local_database) { {"database" => "local-db", "port" => "local-port", "username" => "local-username"} }
|
17
|
+
|
18
|
+
before do
|
19
|
+
subject.set(:application) { application }
|
20
|
+
subject.set(:shared_path) { "/shared/#{application}" }
|
21
|
+
namespace.stub(:remote_database_config) { remote_database }
|
22
|
+
namespace.stub(:database_config) { local_database }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set proper repository" do
|
26
|
+
subject.should_receive(:download)
|
27
|
+
subject.should_receive(:run_locally).with("gunzip tmp/app-dump.sql.gz | psql -p local-port local-db")
|
28
|
+
subject.execute_task(task)
|
29
|
+
subject.should have_run("pg_dump -c -Z 9 -p #{port} -h #{host} -U #{username} -f /shared/app/backup/app-dump.sql.gz #{database}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,60 +1,67 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: o2h
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Michal Cichra
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-12-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: newrelic_rpm
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70347822648100 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
20
|
+
- !ruby/object:Gem::Version
|
23
21
|
version: 3.3.0
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: capistrano
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *70347822648100
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: capistrano
|
27
|
+
requirement: &70347822647600 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
29
|
+
requirements:
|
32
30
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
31
|
+
- !ruby/object:Gem::Version
|
34
32
|
version: 2.9.0
|
35
33
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: rvm
|
39
34
|
prerelease: false
|
40
|
-
|
35
|
+
version_requirements: *70347822647600
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rvm
|
38
|
+
requirement: &70347822647120 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
40
|
+
requirements:
|
43
41
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
42
|
+
- !ruby/object:Gem::Version
|
45
43
|
version: 1.9.2
|
46
44
|
type: :runtime
|
47
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70347822647120
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pg_dumper
|
49
|
+
requirement: &70347822646500 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.5
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70347822646500
|
48
58
|
description: Collection of recipes and gem dependencies for o2h deployment
|
49
|
-
email:
|
59
|
+
email:
|
50
60
|
- michal@o2h.cz
|
51
61
|
executables: []
|
52
|
-
|
53
62
|
extensions: []
|
54
|
-
|
55
63
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
64
|
+
files:
|
58
65
|
- .gitignore
|
59
66
|
- .simplecov
|
60
67
|
- .travis.yml
|
@@ -77,11 +84,13 @@ files:
|
|
77
84
|
- lib/o2h/recipes/host/static.rb
|
78
85
|
- lib/o2h/recipes/host/unicorn.rb
|
79
86
|
- lib/o2h/recipes/rvm.rb
|
87
|
+
- lib/o2h/recipes/sync.rb
|
80
88
|
- lib/o2h/version.rb
|
81
89
|
- o2h.gemspec
|
82
90
|
- spec/recipes/bluepill_spec.rb
|
83
91
|
- spec/recipes/deploy_spec.rb
|
84
92
|
- spec/recipes/git_spec.rb
|
93
|
+
- spec/recipes/sync_spec.rb
|
85
94
|
- spec/spec_helper.rb
|
86
95
|
- spec/support/shared_contexts/capistrano.rb
|
87
96
|
- test/Capfile
|
@@ -89,38 +98,35 @@ files:
|
|
89
98
|
- test/config/deploy.rb
|
90
99
|
homepage: http://o2h.cz
|
91
100
|
licenses: []
|
92
|
-
|
93
101
|
post_install_message:
|
94
102
|
rdoc_options: []
|
95
|
-
|
96
|
-
require_paths:
|
103
|
+
require_paths:
|
97
104
|
- lib
|
98
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
106
|
none: false
|
100
|
-
requirements:
|
101
|
-
- -
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version:
|
104
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
112
|
none: false
|
106
|
-
requirements:
|
107
|
-
- -
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version:
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
110
117
|
requirements: []
|
111
|
-
|
112
118
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.8.
|
119
|
+
rubygems_version: 1.8.10
|
114
120
|
signing_key:
|
115
121
|
specification_version: 3
|
116
122
|
summary: Collection of recipes and gem dependencies for o2h deployment
|
117
|
-
test_files:
|
123
|
+
test_files:
|
118
124
|
- spec/recipes/bluepill_spec.rb
|
119
125
|
- spec/recipes/deploy_spec.rb
|
120
126
|
- spec/recipes/git_spec.rb
|
127
|
+
- spec/recipes/sync_spec.rb
|
121
128
|
- spec/spec_helper.rb
|
122
129
|
- spec/support/shared_contexts/capistrano.rb
|
123
130
|
- test/Capfile
|
124
131
|
- test/Gemfile
|
125
132
|
- test/config/deploy.rb
|
126
|
-
has_rdoc:
|