captools 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +9 -0
- data/README.txt +53 -0
- data/Rakefile +16 -0
- data/bin/captools +5 -0
- data/lib/captools.rb +3 -0
- data/lib/captools/recipes.rb +95 -0
- metadata +59 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
captools
|
2
|
+
by Jake Howerton, Evan Short
|
3
|
+
http://nycrb.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This is meant to be a repository of useful capistrano tasks and other automation.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* There are only two tasks
|
12
|
+
* +pull_assets+ can help you download assets( like images) from a staging or production server to your local environment
|
13
|
+
* +pull_database+ will grab all your production data for you and stick it in your development database ( this could possibly be dangerous if you dont think about it first)
|
14
|
+
* The tasks are currently highly dependent on my environment... lets generalize them
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
Capistrano task repository
|
19
|
+
|
20
|
+
== REQUIREMENTS:
|
21
|
+
|
22
|
+
* mysql gem
|
23
|
+
* yaml
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
* <tt>gem install captools</tt>
|
28
|
+
* run +captools+ once
|
29
|
+
|
30
|
+
== LICENSE:
|
31
|
+
|
32
|
+
(The MIT License)
|
33
|
+
|
34
|
+
Copyright (c) 2007 FIX
|
35
|
+
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
37
|
+
a copy of this software and associated documentation files (the
|
38
|
+
'Software'), to deal in the Software without restriction, including
|
39
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
40
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
41
|
+
permit persons to whom the Software is furnished to do so, subject to
|
42
|
+
the following conditions:
|
43
|
+
|
44
|
+
The above copyright notice and this permission notice shall be
|
45
|
+
included in all copies or substantial portions of the Software.
|
46
|
+
|
47
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
48
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
49
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
50
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
51
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
52
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
53
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/captools.rb'
|
6
|
+
|
7
|
+
Hoe.new('captools', Captools::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'captools'
|
9
|
+
p.summary = 'some sweet capistrano tools'
|
10
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
11
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
#p.extra_deps
<<
['mysql']
|
14
|
+
end
|
15
|
+
|
16
|
+
# vim: syntax=Ruby
|
data/bin/captools
ADDED
data/lib/captools.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'mysql'
|
2
|
+
Capistrano.configuration(:must_exist).load do
|
3
|
+
|
4
|
+
desc <<-DESC
|
5
|
+
This task will pulldown data and dump it into your local dev database.
|
6
|
+
DESC
|
7
|
+
task :pull_database, :roles => :db, :only => { :primary => true } do
|
8
|
+
require "yaml"
|
9
|
+
# the on_rollback handler is only executed if this task is executed within
|
10
|
+
# a transaction (see below), AND it or a subsequent task fails.
|
11
|
+
@buffer = YAML::load_file('config/database.yml')
|
12
|
+
|
13
|
+
def create_database
|
14
|
+
db = Mysql.real_connect("localhost", @buffer["development"]["username"], @buffer["development"]["password"])
|
15
|
+
db.query("CREATE database #{@buffer["development"]["database"]};")
|
16
|
+
db.close
|
17
|
+
end
|
18
|
+
|
19
|
+
def connect_to_db
|
20
|
+
Mysql.real_connect("localhost", @buffer["development"]["username"], @buffer["development"]["password"], @buffer["development"]["database"])
|
21
|
+
end
|
22
|
+
|
23
|
+
# connect to the MySQL server
|
24
|
+
begin
|
25
|
+
dbh = connect_to_db
|
26
|
+
rescue
|
27
|
+
if $!.to_s =~ /Unknown database/
|
28
|
+
set :create_db?, proc { Capistrano::CLI.password_prompt("Would you like to create the database #{@buffer["development"]["database"]} [Yn] :") }
|
29
|
+
if create_db? == ("Y" || "y") || create_db?.length == 0
|
30
|
+
create_database
|
31
|
+
puts "Database created.."
|
32
|
+
if proc { Capistrano::CLI.password_prompt("Run migrations now? [Yn] :") } == ("Y" || "y") || create_db?.length == 0
|
33
|
+
system "rake db:migrate"
|
34
|
+
dbh = connect_to_db
|
35
|
+
else
|
36
|
+
puts "You will need to migrate your local database before running this command again."
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
else
|
40
|
+
puts "Exiting..."
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
else
|
44
|
+
puts "Mysql threw the following error #{$!.to_s}"
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
#get local version
|
50
|
+
local_version = dbh.query("SELECT version FROM schema_info").fetch_row[0].to_i
|
51
|
+
|
52
|
+
set :environment_database_password, proc { Capistrano::CLI.password_prompt("#{rails_env} database remote Password : ") }
|
53
|
+
@buffer = YAML::load_file('config/database.yml')
|
54
|
+
|
55
|
+
#get remote version
|
56
|
+
run("#{current_path}/script/runner -e production 'puts ActiveRecord::Migrator.current_version'") { |c, s, data| @remote_version = data.to_i}
|
57
|
+
|
58
|
+
if @remote_version == local_version
|
59
|
+
puts "Your Database Structure is in sync with the remote server..."
|
60
|
+
set :db_password, proc { Capistrano::CLI.password_prompt("Remote Database Password : ") }
|
61
|
+
tmp_file = File.new("tmp/dump.sql", "w+")
|
62
|
+
run "mysqldump -u #{@buffer["production"]["username"]} -p #{@buffer["production"]["database"]}" do |ch, stream, out|
|
63
|
+
ch.send_data "#{db_password}\n" if out =~ /^Enter password:/
|
64
|
+
tmp_file << out unless out =~ /^Enter password:/
|
65
|
+
end
|
66
|
+
tmp_file.close
|
67
|
+
system "mysql -u #{@buffer["development"]["username"]} #{@buffer["development"]["database"]} < tmp/dump.sql"
|
68
|
+
else
|
69
|
+
if local_version > @remote_version
|
70
|
+
puts "The Remote Database Structure is out of date. Please commit any new migrations and run cap migrate on the remote machine before running this task."
|
71
|
+
else
|
72
|
+
puts "Your Database Structure is out of date. Please run rake migrate on your machine( your working copy might not be up to date! ) before running this task."
|
73
|
+
end
|
74
|
+
exit
|
75
|
+
end
|
76
|
+
dbh.close
|
77
|
+
end
|
78
|
+
|
79
|
+
desc <<-DESC
|
80
|
+
This task will pulldown production assets and dump it into your local public folder.
|
81
|
+
DESC
|
82
|
+
task :pull_assets, :roles => :app, :only => { :primary => true } do
|
83
|
+
|
84
|
+
#change dir and tar assets
|
85
|
+
run "cd #{asset_path} && tar cf assets.tar ./*"
|
86
|
+
|
87
|
+
#download the newly created tarball
|
88
|
+
system "scp #{user}@#{pull_host}:#{asset_path}/assets.tar ./public/assets.tar"
|
89
|
+
|
90
|
+
#untar
|
91
|
+
system "cd public && tar xvf ./assets.tar && cd .."
|
92
|
+
system "rm -f public/assets.tar"
|
93
|
+
delete "#{asset_path}/assets.tar"
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: captools
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-01-29 00:00:00 -05:00
|
8
|
+
summary: some sweet capistrano tools
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ryand-ruby@zenspider.com
|
12
|
+
homepage: " by Jake Howerton, Evan Short"
|
13
|
+
rubyforge_project: captools
|
14
|
+
description: "== FEATURES/PROBLEMS: * There are only two tasks * +pull_assets+ can help you download assets( like images) from a staging or production server to your local environment * +pull_database+ will grab all your production data for you and stick it in your development database ( this could possibly be dangerous if you dont think about it first) * The tasks are currently highly dependent on my environment... lets generalize them == SYNOPSIS: Capistrano task repository == REQUIREMENTS:"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Ryan Davis
|
30
|
+
files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
- Rakefile
|
35
|
+
- bin/captools
|
36
|
+
- lib/captools.rb
|
37
|
+
- lib/captools/recipes.rb
|
38
|
+
test_files: []
|
39
|
+
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
executables:
|
45
|
+
- captools
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
dependencies:
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: hoe
|
53
|
+
version_requirement:
|
54
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.1.7
|
59
|
+
version:
|