metastrano 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 John Paul Narowski
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.
@@ -0,0 +1,18 @@
1
+ = metastrano
2
+
3
+ Description goes here.
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
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 John Paul Narowski. See LICENSE for details.
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "metastrano"
8
+ gem.summary = %Q{Capistrno recipes for Passenger, MySQL Etc}
9
+ gem.description = %Q{This is a gem that is suppose to help you automate all of your server deployment and project maintenance tasks}
10
+ gem.email = "jnarowski@gmail.com"
11
+ gem.files = [
12
+ ".document",
13
+ ".gitignore",
14
+ "LICENSE",
15
+ "README.rdoc",
16
+ "Rakefile",
17
+ Dir["{spec,lib}/**/*"],
18
+ "test/helper.rb",
19
+ "test/test_metastrano.rb"
20
+ ]
21
+ gem.homepage = "http://github.com/jnarowski/metastrano"
22
+ gem.authors = ["John Paul Narowski"]
23
+ gem.add_development_dependency "rspec", ">= 1.2.9"
24
+ gem.add_development_dependency "capistrano", ">= 2.3.0"
25
+ gem.add_development_dependency "erb"
26
+ end
27
+ rescue LoadError
28
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
29
+ end
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ begin
39
+ require 'rcov/rcovtask'
40
+ Rcov::RcovTask.new do |test|
41
+ test.libs << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ end
45
+ rescue LoadError
46
+ task :rcov do
47
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
48
+ end
49
+ end
50
+
51
+ task :test => :check_dependencies
52
+
53
+ task :default => :test
54
+
55
+ require 'rake/rdoctask'
56
+ Rake::RDocTask.new do |rdoc|
57
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
58
+
59
+ rdoc.rdoc_dir = 'rdoc'
60
+ rdoc.title = "metastrano #{version}"
61
+ rdoc.rdoc_files.include('README*')
62
+ rdoc.rdoc_files.include('lib/**/*.rb')
63
+ end
@@ -0,0 +1,8 @@
1
+ require 'capistrano'
2
+ require 'capistrano/cli'
3
+
4
+ Dir.glob(File.join(File.dirname(__FILE__), '/recipes/*.rb')).each { |f| load f }
5
+
6
+ Capistrano::Configuration.instance(:must_exist).load do
7
+ set :config_files, 'database.yml' unless exists?(:config_files)
8
+ end
@@ -0,0 +1,40 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ #----------------------------------------------------------------
4
+ # Apache Strategy
5
+ #----------------------------------------------------------------
6
+
7
+ namespace :apache do
8
+
9
+ desc "Restarts Apache - sudo service httpd restart"
10
+ task :restart, :roles => :app do
11
+ run "#{sudo} service httpd restart"
12
+ end
13
+
14
+ desc "Creates the .conf file in the shared config directory, and creates a symlink to /etc/httpd/conf.d/application.conf"
15
+ task :create_vhost do
16
+ set(:server_name) { Capistrano::CLI.ui.ask "Enter ServerName" } unless exists?(:server_name)
17
+
18
+ vhost = ERB.new <<-EOF
19
+ <VirtualHost *:80>
20
+ ServerName #{server_name}
21
+ DocumentRoot #{current_path}/public
22
+
23
+ CustomLog #{shared_path}/log/access.log combined
24
+ ErrorLog #{shared_path}/log/error.log
25
+ </VirtualHost>
26
+ EOF
27
+
28
+ # uploads the above vhost file onto the server
29
+ put vhost.result, "#{shared_path}/config/#{application}.conf"
30
+
31
+ # removes any existing apache conf files
32
+ sudo "rm -f /etc/httpd/conf.d/#{application}.conf"
33
+ # move the application.conf file into your apache folder
34
+ sudo "mv #{shared_path}/config/#{application}.conf /etc/httpd/conf.d/#{application}.conf"
35
+ # make a symbolic link back to the shared config directory
36
+ sudo "ln -nfs /etc/httpd/conf.d/#{application}.conf #{shared_path}/config/#{application}.conf"
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,106 @@
1
+ require 'erb'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ namespace :db do
5
+
6
+ desc "Runs rake db:seed to load in default seed data"
7
+ task :seed, :roles => :db do
8
+ run "cd #{current_path} && #{sudo} rake RAILS_ENV=production db:seed"
9
+ end
10
+
11
+ #----------------------------------------------------------------
12
+ # MySQL Specific
13
+ #----------------------------------------------------------------
14
+
15
+ namespace :mysql do
16
+
17
+ desc "Create MySQL database and user for this environment using prompted or preset values"
18
+ task :setup, :roles => :db, :only => { :primary => true } do
19
+ prepare_for_db_command # sets up the usernames and passwords
20
+ create_db # creates the production database
21
+ # create a test db if requested
22
+ if Capistrano::CLI.ui.agree("Do you want to also create a test database? - #{application}_test - (Y/N)")
23
+ set :db_name, "#{application}_test"
24
+ create_db
25
+ end
26
+ create_yaml
27
+ end
28
+
29
+ desc "Creates a MySQL database and grants the user permission"
30
+ task :create_db do
31
+ sql = <<-SQL
32
+ CREATE DATABASE IF NOT EXISTS #{db_name};
33
+ GRANT ALL PRIVILEGES ON #{db_name}.* TO #{db_user}@localhost IDENTIFIED BY '#{db_pass}';
34
+ SQL
35
+
36
+ run "mysql --user=#{db_admin_user} -p --execute=\"#{sql}\"" do |channel, stream, data|
37
+ if data =~ /^Enter password:/
38
+ pass = Capistrano::CLI.password_prompt "Enter database password for '#{db_admin_user}':"
39
+ channel.send_data "#{pass}\n"
40
+ end
41
+ end
42
+ end
43
+
44
+ desc "Create database.yml in shared path with settings for current stage and test env"
45
+ task :create_yaml do
46
+ set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" } unless exists?(:db_user)
47
+ set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" } unless exists?(:db_pass)
48
+
49
+ db_config = ERB.new <<-EOF
50
+ base: &base
51
+ adapter: mysql
52
+ username: #{db_user}
53
+ password: #{db_pass}
54
+
55
+ #{environment}:
56
+ database: #{application}_#{environment}
57
+ <<: *base
58
+
59
+ test:
60
+ database: #{application}_test
61
+ <<: *base
62
+ EOF
63
+ run "mkdir -p #{shared_path}/config"
64
+ put db_config.result, "#{shared_path}/config/database.yml"
65
+ end
66
+
67
+ desc "Updates the symlink for database.yml file to the just deployed release."
68
+ task :symlink, :except => { :no_release => true } do
69
+ run "rm -f #{release_path}/config/database.yml"
70
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
71
+ end
72
+
73
+ desc "Loads remote production data into development database. Uses your local database.yml file for development and production passwords"
74
+ task :load_remote_data, :roles => :db, :only => { :primary => true } do
75
+ require 'yaml'
76
+
77
+ # First lets get the remote database config file so that we can read in the database settings
78
+ get("#{shared_path}/config/database.yml", "tmp/database.yml")
79
+
80
+ # load the production settings within the database file
81
+ remote_settings = YAML::load_file("tmp/database.yml")["production"]
82
+
83
+ # we also need the local settings so that we can import the fresh database properly
84
+ local_settings = YAML::load_file("config/database.yml")["development"]
85
+
86
+ filename = "dump.#{Time.now.strftime '%Y-%m-%d_%H:%M:%S'}.sql.gz"
87
+ on_rollback { delete "/tmp/#{filename}" }
88
+
89
+ run "mysqldump -u #{remote_settings['username']} --password=#{remote_settings['password']} #{remote_settings['database']} | gzip > /tmp/#{filename}" do |channel, stream, data|
90
+ puts data
91
+ end
92
+
93
+ get "/tmp/#{filename}", "/tmp/#{filename}"
94
+ run_locally "gunzip -c /tmp/#{filename} | mysql -u #{local_settings['username']} #{local_settings['password']} #{local_settings['database']} && rm -f gunzip #{filename} && rm -f tmp/database.yml"
95
+ end
96
+ end
97
+
98
+ def prepare_for_db_command
99
+ set :db_name, "#{application}_#{environment}" unless exists?(:db_name)
100
+ set(:db_admin_user) { Capistrano::CLI.ui.ask "Username with priviledged database access (to create db):" } unless exists?(:db_admin_user)
101
+ set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" } unless exists?(:db_user)
102
+ set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" } unless exists?(:db_pass)
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,24 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ #----------------------------------------------------------------
4
+ # Deploy Strategy
5
+ # - this assumes you are using passanger
6
+ #----------------------------------------------------------------
7
+
8
+ namespace :deploy do
9
+ desc "Restarting mod_rails with restart.txt"
10
+ task :restart, :roles => :app, :except => { :no_release => true } do
11
+ apache.restart
12
+ end
13
+
14
+ desc "Update the crontab file if you are using the whenever GEM"
15
+ task :update_crontab, :roles => :db do
16
+ run "cd #{release_path} && #{sudo} whenever --update-crontab #{application}"
17
+ end
18
+
19
+ [:start, :stop].each do |t|
20
+ desc "#{t} task is a no-op with mod_rails"
21
+ task t, :roles => :app do ; end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ #----------------------------------------------------------------
4
+ # git
5
+ #----------------------------------------------------------------
6
+
7
+ namespace :git do
8
+ desc "Creates a remote git repo"
9
+ task :create_repo, :roles => :app, :except => { :no_release => true } do
10
+ sudo "mkdir /home/git/#{application}.git && cd /home/git/#{application}.git && git --bare init"
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,20 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ #----------------------------------------------------------------
4
+ # Rake Tasks
5
+ #----------------------------------------------------------------
6
+
7
+ namespace :rake do
8
+
9
+ desc "Builds the most recent javascript and css files by running 'rake asset:packager:destroy_all' then 'rake asset:packager:build_all'"
10
+ task :rebuild_assets, :roles => :db do
11
+ run "cd #{current_path}; #{sudo} rake asset:packager:delete_all; #{sudo} rake asset:packager:build_all"
12
+ end
13
+
14
+ desc "Install gems for your rails app -- rake gems:install"
15
+ task :gems_install, :roles => :app do
16
+ run "cd #{current_path} && #{sudo} rake RAILS_ENV=production gems:install"
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,52 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ #----------------------------------------------------------------
4
+ # Symlink Strategy
5
+ #----------------------------------------------------------------
6
+
7
+ namespace :symlink do
8
+ desc <<-DESC
9
+ Create shared directories. Specify which directories are shared via:
10
+ set :shared_dirs, %w(avatars videos)
11
+ DESC
12
+ task :create_shared_dirs, :roles => :app do
13
+ shared_dirs.each { |link| run "mkdir -p #{shared_path}/#{link}" } if shared_dirs
14
+ end
15
+
16
+ desc <<-DESC
17
+ Create links to shared directories from current deployment's public directory.
18
+ Specify which directories are shared via:
19
+ set :shared_dirs, %w(avatars videos)
20
+ DESC
21
+ task :shared_directories, :roles => :app do
22
+ shared_dirs.each do |link|
23
+ run "rm -rf #{release_path}/public/#{link}"
24
+ run "ln -nfs #{shared_path}/#{link} #{release_path}/public/#{link}"
25
+ end if shared_dirs
26
+ end
27
+
28
+ desc <<-DESC
29
+ Create links to config files stored in shared config directory.
30
+ Specify which config files to link using the following:
31
+ set :config_files, 'database.yml'
32
+ DESC
33
+ task :shared_config_files, :roles => :app do
34
+ config_files.each do |file_path|
35
+ begin
36
+ run "#{sudo} rm #{config_path}#{file_path}"
37
+ run "#{sudo} ln -nfs #{shared_config_path}#{file_path} #{config_path}#{file_path}"
38
+ rescue
39
+ puts "Problem linking to #{file_path}. Be sure file already exists in #{shared_config_path}."
40
+ end
41
+ end if config_files
42
+ end
43
+ end
44
+
45
+ def config_path
46
+ "#{current_release}/config/"
47
+ end
48
+
49
+ def shared_config_path
50
+ "#{shared_path}/config/"
51
+ end
52
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'metastrano'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMetastrano < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metastrano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - John Paul Narowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-19 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: capistrano
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: erb
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: This is a gem that is suppose to help you automate all of your server deployment and project maintenance tasks
46
+ email: jnarowski@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - lib/metastrano.rb
61
+ - lib/recipes/apache.rb
62
+ - lib/recipes/db.rb
63
+ - lib/recipes/deploy.rb
64
+ - lib/recipes/git.rb
65
+ - lib/recipes/rake.rb
66
+ - lib/recipes/symlink.rb
67
+ - test/helper.rb
68
+ - test/test_metastrano.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/jnarowski/metastrano
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.3.5
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Capistrno recipes for Passenger, MySQL Etc
97
+ test_files:
98
+ - test/helper.rb
99
+ - test/test_metastrano.rb