ninja-deploy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm use ruby-1.8.7-p302@gemdev
2
+ rvm info ruby
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ninja Loss
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = ninja-deploy
2
+
3
+ Common shared deployment recipes.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Ninja Loss. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ninja-deploy"
8
+ gem.summary = %Q{Common shared deployment recipes.}
9
+ gem.description = %Q{Common shared deployment recipes for your pleasure.}
10
+ gem.email = "ninja.loss@gmail.com"
11
+ gem.homepage = "http://github.com/ninja-loss/ninja-deploy"
12
+ gem.authors = ["Ninja Loss"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ begin
39
+ require 'yard'
40
+ YARD::Rake::YardocTask.new
41
+ rescue LoadError
42
+ task :yardoc do
43
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
44
+ end
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,86 @@
1
+ Capistrano::Configuration.instance( :must_exist ).load do
2
+ namespace :db do
3
+ namespace :dump do
4
+ desc 'Dump a remote database, fetch the dump file to local and then load it to the development database'
5
+ task :to_local_db, :roles => :db, :only => { :primary => true } do
6
+ local_file_full_path = dump_database_to_local
7
+
8
+ puts "*** Reading local database config..."
9
+ username, password, database, host = database_config( 'development' )
10
+
11
+ puts "*** Loading data to local #{database} database"
12
+ system "bzip2 -d -c #{local_file_full_path} | mysql -u #{username} --password='#{password}' #{database}"
13
+
14
+ puts "*** Removing local dump file..."
15
+ system "rm #{local_file_full_path}"
16
+ end
17
+
18
+ desc 'Dump a remote database and fetch the dump file to local /tmp directory'
19
+ task :to_local_file, :roles => :db, :only => { :primary => true } do
20
+ local_file_full_path = dump_database_to_local
21
+ puts "*** You can find the dump file at: #{local_file_full_path}"
22
+ end
23
+
24
+ # desc "Dump a remote database, fetch the dump file to the staging server and then load it to the staging database"
25
+ # task :to_staging, :roles => :db, :only => { :primary => true } do
26
+ #
27
+ # end
28
+ end
29
+
30
+ def dump_database_to_local
31
+ prepare_for_database_dump
32
+
33
+ puts "*** Reading database credentials... "
34
+ user, password, database, host = remote_database_config( rails_env )
35
+
36
+ dump_database( password )
37
+
38
+ local_file_full_path = "/tmp/#{File.basename dump_file_bz2_full_path}"
39
+ puts "*** Fetching the dump file from '#{dump_file_bz2_full_path}' and putting it at '#{local_file_full_path}'..."
40
+ get dump_file_bz2_full_path, local_file_full_path
41
+
42
+ remove_dump_file
43
+
44
+ local_file_full_path
45
+ end
46
+
47
+ def prepare_for_database_dump
48
+ now = Time.now
49
+ run "mkdir -p #{shared_path}/db_backups"
50
+ dump_time = [now.year, now.month, now.day, now.hour, now.min, now.sec].join( '' )
51
+ set :dump_file, "#{environment_database}-dump-#{dump_time}.dmp"
52
+ set :dump_file_path, "#{shared_path}/db_backups"
53
+ set :dump_file_full_path, "#{dump_file_path}/#{dump_file}"
54
+ set :dump_file_bz2_full_path, "#{dump_file_full_path}.bz2"
55
+ end
56
+
57
+ def dump_database( password )
58
+ puts "*** Dumping #{environment_database} database..."
59
+ run "mysqldump --add-drop-table -u #{environment_db_user} -h #{environment_db_host.gsub('-master', '-replica')} -p#{password} #{environment_database} | bzip2 -c > #{dump_file_bz2_full_path}"
60
+ end
61
+
62
+ def remove_dump_file
63
+ puts "*** Removing the dump file from the server..."
64
+ run "rm #{dump_file_bz2_full_path}"
65
+ end
66
+
67
+ # Reads the database credentials from the local config/database.yml file
68
+ # +db+ the name of the environment to get the credentials for
69
+ # Returns username, password, database
70
+ #
71
+ def database_config( db )
72
+ database = YAML::load_file( 'config/database.yml' )
73
+ return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database'], database["#{db}"]['host']
74
+ end
75
+
76
+ # Reads the database credentials from the remote config/database.yml file
77
+ # +db+ the name of the environment to get the credentials for
78
+ # Returns username, password, database
79
+ #
80
+ def remote_database_config( db )
81
+ remote_config = capture("cat #{shared_path}/config/database.yml")
82
+ database = YAML::load( remote_config )
83
+ return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database'], database["#{db}"]['host']
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module NinjaDeploy
2
+ VERSION = File.read( "#{File.dirname __FILE__}/../VERSION" ).chomp
3
+ end
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ninja-deploy}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ninja Loss"]
12
+ s.date = %q{2010-11-09}
13
+ s.description = %q{Common shared deployment recipes for your pleasure.}
14
+ s.email = %q{ninja.loss@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rvmrc",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/ninja_deploy.rb",
28
+ "lib/ninja_deploy/recipes/database.rb",
29
+ "ninja-deploy.gemspec",
30
+ "spec/ninja-deploy_spec.rb",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/ninja-loss/ninja-deploy}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{Common shared deployment recipes.}
39
+ s.test_files = [
40
+ "spec/ninja-deploy_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
50
+ s.add_development_dependency(%q<yard>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_dependency(%q<yard>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_dependency(%q<yard>, [">= 0"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "NinjaDeploy" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'ninja-deploy'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ninja-deploy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Ninja Loss
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-09 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: yard
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ description: Common shared deployment recipes for your pleasure.
52
+ email: ninja.loss@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - LICENSE
59
+ - README.rdoc
60
+ files:
61
+ - .document
62
+ - .gitignore
63
+ - .rvmrc
64
+ - LICENSE
65
+ - README.rdoc
66
+ - Rakefile
67
+ - VERSION
68
+ - lib/ninja_deploy.rb
69
+ - lib/ninja_deploy/recipes/database.rb
70
+ - ninja-deploy.gemspec
71
+ - spec/ninja-deploy_spec.rb
72
+ - spec/spec.opts
73
+ - spec/spec_helper.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/ninja-loss/ninja-deploy
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Common shared deployment recipes.
108
+ test_files:
109
+ - spec/ninja-deploy_spec.rb
110
+ - spec/spec_helper.rb