youthtree-capistrano 0.1.3 → 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.
@@ -1,13 +1,13 @@
1
1
  module YouthTree
2
2
  module Capistrano
3
- VERSION = "0.1.3".freeze
3
+ VERSION = "0.2.0".freeze
4
4
 
5
5
  def self.load(&blk)
6
6
  ::Capistrano::Configuration.instance(:must_exist).load(&blk)
7
7
  end
8
8
 
9
9
  def self.load_recipe!(*names)
10
- names.flatten.each { |name| require "youthtree/recipes/#{name}" }
10
+ names.flatten.each { |name| require "youth_tree/recipes/#{name}" }
11
11
  end
12
12
 
13
13
  def self.load_named(name, &blk)
@@ -15,7 +15,7 @@ module YouthTree
15
15
  end
16
16
 
17
17
  def self.load_all!
18
- load_recipe! %w(base rvm git bundler settings db unicorn compass barista jammit uploads)
18
+ load_recipe! %w(base rvm git bundler settings db unicorn compass barista jammit uploads syncing)
19
19
  load { load 'deploy' }
20
20
  load_recipe! 'deploy_hooks'
21
21
  end
@@ -23,8 +23,8 @@ YouthTree::Capistrano.load do
23
23
 
24
24
  %w(staging production).each do |env_name|
25
25
  task env_name.to_sym do
26
- puts "** Switching Rails Env to #{env_name} **"
27
- set :rails_env, env_name
26
+ puts "** Switching stage to #{env_name} **"
27
+ set :stage, env_name
28
28
  end
29
29
  end
30
30
 
@@ -32,18 +32,19 @@ YouthTree::Capistrano.load do
32
32
  yt_cset :use_sudo, false
33
33
  yt_cset :keep_releases, 10
34
34
 
35
- yt_cset(:rails_env) { default_stage }
35
+ yt_cset(:stage) { default_stage }
36
+ yt_cset(:rails_env) { stage }
36
37
  yt_cset(:application) { raise "Please Ensure you set the application name." }
37
38
  yt_cset(:user) { application }
38
39
  yt_cset(:runner) { user }
39
40
  yt_cset(:group) { user }
40
- yt_cset(:deploy_to) { "/opt/#{application}/#{rails_env}" }
41
+ yt_cset(:deploy_to) { "/opt/#{application}/#{stage}" }
41
42
 
42
43
  yt_cset :server_hosts, Hash.new
43
44
 
44
- role(:web) { server_hosts[rails_env] }
45
- role(:app) { server_hosts[rails_env] }
46
- role(:db, :primary => true) { server_hosts[rails_env] }
45
+ role(:web) { server_hosts[stage] }
46
+ role(:app) { server_hosts[stage] }
47
+ role(:db, :primary => true) { server_hosts[stage] }
47
48
 
48
49
  host_for_env :staging, "dracorex.youthtree.org.au"
49
50
  host_for_env :production, "dryptosaurus.youthtree.org.au"
@@ -0,0 +1,104 @@
1
+ require 'ostruct'
2
+ YouthTree::Capistrano.load_named(:syncing) do
3
+
4
+ yt_cset(:syncing_version_name) { "#{application}-#{stage}-#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}" }
5
+ yt_cset(:syncing_remote_dir) { "#{shared_path}/sync" }
6
+ yt_cset(:syncing_remote_archive) { "#{syncing_remote_dir}/#{syncing_version_name}.sql.bz2" }
7
+ yt_cset(:syncing_local_archive) { "/tmp/#{syncing_version_name}.sql.bz2" }
8
+
9
+ yt_cset :syncing_remote_blacklist, ["production"]
10
+
11
+ namespace :sync do
12
+
13
+ def config_from(text, env = ENV['RAILS_ENV'])
14
+ full_config = YAML.load(text) || {}
15
+ config = full_config[env || "development"] || {}
16
+ OpenStruct.new(config)
17
+ end
18
+
19
+ def remote_db_config
20
+ config_from capture("cat '#{shared_path}/#{database_shared_config}'"), rails_env
21
+ end
22
+
23
+ def local_db_config
24
+ config_from File.read("config/database.yml")
25
+ end
26
+
27
+ def options_for_config(config)
28
+ host_command = config.host.nil? ? '' : "-h #{config.host}"
29
+ "-u #{config.username} --password='#{config.password}' #{host_command} #{config.database}"
30
+ end
31
+
32
+ def dump_command_for(config)
33
+ "mysqldump #{options_for_config(config)}"
34
+ end
35
+
36
+ def load_command_for(config)
37
+ "mysql #{options_for_config(config)}"
38
+ end
39
+
40
+ task :cleanup_remote do
41
+ run "rm -rf #{syncing_remote_archive}"
42
+ end
43
+
44
+ task :cleanup_local do
45
+ run "rm -rf #{syncing_local_archive}"
46
+ end
47
+
48
+ task :prepare do
49
+ run "mkdir -p '#{syncing_remote_dir}'"
50
+ end
51
+
52
+ desc "Dumps the remote db to a file"
53
+ task :save_remote_db do
54
+ run "#{dump_command_for(remote_db_config)} | bzip2 -9 > #{syncing_remote_archive}"
55
+ end
56
+
57
+ desc "Loads data into the remote db from the given file"
58
+ task :load_remote_db do
59
+ run "bzip2 -c -d #{syncing_remote_archive} | #{load_command_for(remote_db_config)} && rm -rf #{syncing_remote_archive}"
60
+ end
61
+
62
+ desc "Dumps the local db to a file"
63
+ task :save_local_db do
64
+ system "#{dump_command_for(local_db_config)} | bzip2 -9 > #{syncing_local_archive}"
65
+ end
66
+
67
+ desc "Loads data into the local db from the given file"
68
+ task :load_local_db do
69
+ system "bzip2 -c -d #{syncing_local_archive} | #{load_command_for(local_db_config)} && rm -rf #{syncing_local_archive}"
70
+ end
71
+
72
+ task :download_remote_db do
73
+ download syncing_remote_archive, syncing_local_archive, :once => true
74
+ end
75
+
76
+ task :upload_local_db do
77
+ upload syncing_local_archive, syncing_remote_archive, :once => true
78
+ end
79
+
80
+ desc "Downloads the database into the current environment from the remote server"
81
+ task :down do
82
+ prepare
83
+ save_remote_db
84
+ download_remote_db
85
+ cleanup_remote
86
+ load_local_db
87
+ end
88
+
89
+ desc "Uploads the database for the current environment to the remote server"
90
+ task :up do
91
+ if syncing_remote_blacklist.include?(stage.to_s)
92
+ STDERR.puts "**** Can't upload to #{stage} ****"
93
+ exit 1
94
+ end
95
+ prepare
96
+ save_local_db
97
+ upload_local_db
98
+ cleanup_local
99
+ load_remote_db
100
+ end
101
+
102
+ end
103
+
104
+ end
@@ -1,2 +1,2 @@
1
- require 'youthtree/capistrano'
1
+ require 'youth_tree/capistrano'
2
2
  YouthTree::Capistrano.load_all! if defined?(Capistrano)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{youthtree-capistrano}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Darcy Laycock"]
12
- s.date = %q{2010-08-28}
12
+ s.date = %q{2010-09-02}
13
13
  s.description = %q{Capistrano tasks used for common Youth Tree deployments.}
14
14
  s.email = %q{sutto@sutto.net}
15
15
  s.extra_rdoc_files = [
@@ -18,20 +18,21 @@ Gem::Specification.new do |s|
18
18
  s.files = [
19
19
  "README.md",
20
20
  "Rakefile",
21
+ "lib/youth_tree/capistrano.rb",
22
+ "lib/youth_tree/recipes/barista.rb",
23
+ "lib/youth_tree/recipes/base.rb",
24
+ "lib/youth_tree/recipes/bundler.rb",
25
+ "lib/youth_tree/recipes/compass.rb",
26
+ "lib/youth_tree/recipes/db.rb",
27
+ "lib/youth_tree/recipes/deploy_hooks.rb",
28
+ "lib/youth_tree/recipes/git.rb",
29
+ "lib/youth_tree/recipes/jammit.rb",
30
+ "lib/youth_tree/recipes/rvm.rb",
31
+ "lib/youth_tree/recipes/settings.rb",
32
+ "lib/youth_tree/recipes/syncing.rb",
33
+ "lib/youth_tree/recipes/unicorn.rb",
34
+ "lib/youth_tree/recipes/uploads.rb",
21
35
  "lib/youthtree-capistrano.rb",
22
- "lib/youthtree/capistrano.rb",
23
- "lib/youthtree/recipes/barista.rb",
24
- "lib/youthtree/recipes/base.rb",
25
- "lib/youthtree/recipes/bundler.rb",
26
- "lib/youthtree/recipes/compass.rb",
27
- "lib/youthtree/recipes/db.rb",
28
- "lib/youthtree/recipes/deploy_hooks.rb",
29
- "lib/youthtree/recipes/git.rb",
30
- "lib/youthtree/recipes/jammit.rb",
31
- "lib/youthtree/recipes/rvm.rb",
32
- "lib/youthtree/recipes/settings.rb",
33
- "lib/youthtree/recipes/unicorn.rb",
34
- "lib/youthtree/recipes/uploads.rb",
35
36
  "youthtree-capistrano.gemspec"
36
37
  ]
37
38
  s.homepage = %q{http://github.com/YouthTree/youthtree-capistrano}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youthtree-capistrano
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Darcy Laycock
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-28 00:00:00 +08:00
18
+ date: 2010-09-02 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,20 +73,21 @@ extra_rdoc_files:
73
73
  files:
74
74
  - README.md
75
75
  - Rakefile
76
+ - lib/youth_tree/capistrano.rb
77
+ - lib/youth_tree/recipes/barista.rb
78
+ - lib/youth_tree/recipes/base.rb
79
+ - lib/youth_tree/recipes/bundler.rb
80
+ - lib/youth_tree/recipes/compass.rb
81
+ - lib/youth_tree/recipes/db.rb
82
+ - lib/youth_tree/recipes/deploy_hooks.rb
83
+ - lib/youth_tree/recipes/git.rb
84
+ - lib/youth_tree/recipes/jammit.rb
85
+ - lib/youth_tree/recipes/rvm.rb
86
+ - lib/youth_tree/recipes/settings.rb
87
+ - lib/youth_tree/recipes/syncing.rb
88
+ - lib/youth_tree/recipes/unicorn.rb
89
+ - lib/youth_tree/recipes/uploads.rb
76
90
  - lib/youthtree-capistrano.rb
77
- - lib/youthtree/capistrano.rb
78
- - lib/youthtree/recipes/barista.rb
79
- - lib/youthtree/recipes/base.rb
80
- - lib/youthtree/recipes/bundler.rb
81
- - lib/youthtree/recipes/compass.rb
82
- - lib/youthtree/recipes/db.rb
83
- - lib/youthtree/recipes/deploy_hooks.rb
84
- - lib/youthtree/recipes/git.rb
85
- - lib/youthtree/recipes/jammit.rb
86
- - lib/youthtree/recipes/rvm.rb
87
- - lib/youthtree/recipes/settings.rb
88
- - lib/youthtree/recipes/unicorn.rb
89
- - lib/youthtree/recipes/uploads.rb
90
91
  - youthtree-capistrano.gemspec
91
92
  has_rdoc: true
92
93
  homepage: http://github.com/YouthTree/youthtree-capistrano