Permalink
Browse files

merged pull request 2

  • Loading branch information...
tilsammans committed Aug 4, 2011
2 parents 9ad0c61 + 904ada4 commit f246f1be41f2f8ded0915472b0388db625f3c983
Showing with 112 additions and 62 deletions.
  1. +3 −0 .gitignore
  2. +11 −12 README → README.rdoc
  3. +12 −0 Rakefile
  4. +33 −0 capistrano_transmit.gemspec
  5. +0 −1 init.rb
  6. +0 −1 install.rb
  7. +53 −0 lib/capistrano/transmit.rb
  8. +0 −47 recipes/deploy.rb
  9. +0 −1 uninstall.rb
View
@@ -0,0 +1,3 @@
+pkg
+doc
+Manifest
View
@@ -1,5 +1,4 @@
-Capistrano Transmit
-===================
+= Capistrano Transmit
Rails tasks to work with production data and assets.
@@ -19,16 +18,19 @@ as well so we don't need to gzip the contents first. All this assumes both your
production and development environment are Unix. Tested on Linux production and
Mac OS X development.
+== Installation
-Installation
-============
+ ruby script/plugin install git://github.com/tilsammans/capistrano_transmit.git
+
+or in your +Gemfile+:
-ruby script/plugin install git://github.com/tilsammans/capistrano_transmit.git
+ gem 'capistrano_transmit'
+
+Then add to your deploy.rb:
+ require 'capistrano/transmit'
-
-Examples
-========
+== Examples
cap transmit:get:mysql # Fetch the remote production MySQL database
# and overwrite your local development database with it
@@ -37,10 +39,7 @@ cap transmit:get:assets # Fetch the remote assets into your local development e
cap transmit:put:mysql # Overwrite the production MySQL database with your development data
-
-
-Prerequisites
-=============
+== Prerequisites
This Capistrano extension assumes some variables are present in your deploy.rb:
View
@@ -0,0 +1,12 @@
+require 'rubygems'
+require 'rake'
+require 'echoe'
+
+Echoe.new('capistrano_transmit', '0.1.0') do |p|
+ p.summary = "Copies mysql databases between remote production and local development servers."
+ p.url = "http://github.com/tilsammans/capistrano_transmit"
+ p.author = "Joost Baaij"
+ p.email = "joost@spacebabies.nl"
+ p.runtime_dependencies = ["capistrano"]
+ p.development_dependencies = []
+end
@@ -0,0 +1,33 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{capistrano_transmit}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Joost Baaij"]
+ s.date = %q{2011-07-21}
+ s.description = %q{Copies mysql databases between remote production and local development servers.}
+ s.email = %q{joost@spacebabies.nl}
+ s.extra_rdoc_files = ["README.rdoc", "lib/capistrano/transmit.rb"]
+ s.files = ["MIT-LICENSE", "README.rdoc", "Rakefile", "lib/capistrano/transmit.rb", "Manifest", "capistrano_transmit.gemspec"]
+ s.homepage = %q{http://github.com/tilsammans/capistrano_transmit}
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Capistrano_transmit", "--main", "README.rdoc"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{capistrano_transmit}
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{Copies mysql databases between remote production and local development servers.}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<capistrano>, [">= 0"])
+ else
+ s.add_dependency(%q<capistrano>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<capistrano>, [">= 0"])
+ end
+end
View
@@ -1 +0,0 @@
-# Include hook code here
View
@@ -1 +0,0 @@
-# Install hook code here
View
@@ -0,0 +1,53 @@
+unless Capistrano::Configuration.respond_to?(:instance)
+ abort "capistrano/transmit requires Capistrano 2"
+end
+
+Capistrano::Configuration.instance.load do
+ after "transmit:get:mysql", "transmit:cleanup"
+ after "transmit:put:mysql", "transmit:cleanup"
+
+ namespace :transmit do
+ namespace :get do
+ desc 'Fetch the remote production database and overwrite your local development database with it'
+ task :mysql, :roles => :db do
+ run "mysqldump --opt --quick --extended-insert --skip-lock-tables -u #{db_remote['username']} --password='#{db_remote['password']}' --host='#{db_remote['host']}' #{db_remote['database']} | gzip > #{dumpfile}"
+
+ system "rsync -vP #{user}@#{deploy_host}:#{dumpfile} tmp/#{db_local["database"]}.sql.gz"
+ system "gunzip < tmp/#{db_local["database"]}.sql.gz | mysql -u #{db_local['username']} --password='#{db_local['password']}' --host='#{db_local['host']}' #{db_local['database']}"
+ end
+
+ desc 'Fetch the assets from the production server to the development environment'
+ task :assets, :roles => :app do
+ system "rsync -Lcrvz #{user}@#{deploy_host}:#{current_path}/public ."
+ end
+ end
+
+ namespace :put do
+ desc 'Upload the local development database to the remote production database and overwrite it'
+ task :mysql, :roles => :db do
+ system "mysqldump --opt -u #{db_local['username']} --password='#{db_local['password']}' --host='#{db_local['host']}' #{db_local['database']} > tmp/#{db_local['database']}.sql"
+
+ system "rsync -vP tmp/#{db_local['database']}.sql #{user}@#{deploy_host}:#{dumpfile}"
+ run "mysql -u #{db_remote['username']} --password='#{db_remote['password']}' --host='#{db_remote['host']}' #{db_remote['database']} < #{dumpfile}"
+ end
+ end
+
+ task :cleanup do
+ run "rm #{dumpfile}"
+ system "rm tmp/#{db_local['database']}.sql.gz"
+ end
+ end
+
+ set(:db_remote) do
+ db_config = capture "cat #{current_path}/config/database.yml"
+ YAML::load(db_config)['production']
+ end
+
+ set(:db_local) do
+ YAML::load_file("config/database.yml")['development']
+ end
+
+ set :dumpfile do
+ "#{current_path}/tmp/#{db_remote['database']}.sql.gz"
+ end
+end
View
@@ -1,47 +0,0 @@
-after "transmit:get:mysql", "transmit:cleanup"
-after "transmit:put:mysql", "transmit:cleanup"
-
-namespace :transmit do
- namespace :get do
- desc 'Fetch the remote production database and overwrite your local development database with it'
- task :mysql, :roles => :db do
- run "mysqldump --opt --quick --extended-insert --skip-lock-tables -u #{db_remote['username']} --password='#{db_remote['password']}' -h #{db_remote['host']} #{db_remote['database']} | gzip > #{dumpfile}"
-
- system "rsync -vP #{user}@#{deploy_host}:#{dumpfile} tmp/#{db_local["database"]}.sql.gz"
- system "gunzip < tmp/#{db_local["database"]}.sql.gz | mysql -u #{db_local['username']} --password='#{db_local['password']}' --host='#{db_local['host']}' #{db_local['database']}"
- end
-
- desc 'Fetch the assets from the production server to the development environment'
- task :assets, :roles => :app do
- system "rsync -Lcrvz #{user}@#{deploy_host}:#{current_path}/public ."
- end
- end
-
- namespace :put do
- desc 'Upload the local development database to the remote production database and overwrite it'
- task :mysql, :roles => :db do
- system "mysqldump --opt -u #{db_local['username']} --password='#{db_local['password']}' #{db_local['database']} > tmp/#{db_local['database']}.sql"
-
- system "rsync -vP tmp/#{db_local['database']}.sql #{user}@#{deploy_host}:#{dumpfile}"
- run "mysql -u #{db_remote['username']} --password='#{db_remote['password']}' -h #{db_remote['host']} #{db_remote['database']} < #{dumpfile}"
- end
- end
-
- task :cleanup do
- run "rm #{dumpfile}"
- system "rm tmp/#{db_local['database']}.sql.gz"
- end
-end
-
-set(:db_remote) do
- db_config = capture "cat #{current_path}/config/database.yml"
- YAML::load(db_config)['production']
-end
-
-set(:db_local) do
- YAML::load_file("config/database.yml")['development']
-end
-
-set :dumpfile do
- "#{current_path}/tmp/#{db_remote['database']}.sql.gz"
-end
View
@@ -1 +0,0 @@
-# Uninstall hook code here

0 comments on commit f246f1b

Please sign in to comment.