o2h 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- #after :'deploy:update_code', :'deploy:set_permissions', :roles => :web
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
+
@@ -1,3 +1,3 @@
1
1
  module O2h
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency 'newrelic_rpm', '~> 3.3.0'
19
19
  gem.add_dependency 'capistrano', '~> 2.9.0'
20
20
  gem.add_dependency 'rvm', '~> 1.9.2'
21
+ gem.add_dependency 'pg_dumper', '~> 0.1.5'
21
22
  end
@@ -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
- subject.should callback('deploy:set_permissions').after('deploy')
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
@@ -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 == :remote_cache }
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
- date: 2011-12-05 00:00:00 Z
14
- dependencies:
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
- prerelease: false
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
- requirement: &id002 !ruby/object:Gem::Requirement
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
- requirement: &id003 !ruby/object:Gem::Requirement
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
- version_requirements: *id003
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: "0"
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: "0"
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
110
117
  requirements: []
111
-
112
118
  rubyforge_project:
113
- rubygems_version: 1.8.11
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: