magic_recipes 0.0.1
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.
- data/MIT-LICENSE +20 -0
- data/README.markdown +47 -0
- data/Rakefile +27 -0
- data/bin/g_cap +45 -0
- data/bin/git_cap +35 -0
- data/lib/generators/magic_recipes/capify_generator.rb +40 -0
- data/lib/generators/magic_recipes/templates/Capfile.tt +7 -0
- data/lib/generators/magic_recipes/templates/deploy.rb.tt +68 -0
- data/lib/magic_recipes/assets.rb +98 -0
- data/lib/magic_recipes/db.rb +40 -0
- data/lib/magic_recipes/gems.rb +19 -0
- data/lib/magic_recipes/git.rb +31 -0
- data/lib/magic_recipes/nginx.rb +58 -0
- data/lib/magic_recipes/nodejs.rb +26 -0
- data/lib/magic_recipes/passenger.rb +25 -0
- data/lib/magic_recipes/postgresql.rb +51 -0
- data/lib/magic_recipes/private_pub.rb +77 -0
- data/lib/magic_recipes/rbenv.rb +46 -0
- data/lib/magic_recipes/rvm.rb +43 -0
- data/lib/magic_recipes/templates/nginx_passenger.erb +27 -0
- data/lib/magic_recipes/templates/nginx_private_pub.erb +13 -0
- data/lib/magic_recipes/templates/nginx_thin.erb +30 -0
- data/lib/magic_recipes/templates/nginx_unicorn.erb +30 -0
- data/lib/magic_recipes/templates/postgresql.yml.erb +8 -0
- data/lib/magic_recipes/templates/private_pub_yml.erb +10 -0
- data/lib/magic_recipes/templates/thin_app_yml.erb +18 -0
- data/lib/magic_recipes/templates/thin_private_pub_yml.erb +19 -0
- data/lib/magic_recipes/templates/unicorn.rb.erb +8 -0
- data/lib/magic_recipes/templates/unicorn_init.erb +84 -0
- data/lib/magic_recipes/thin.rb +44 -0
- data/lib/magic_recipes/unicorn.rb +44 -0
- data/lib/magic_recipes.rb +75 -0
- data/lib/tasks/magic_recipes_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/spec_helper.rb +40 -0
- metadata +269 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Torsten Wetzel <torstenwetzel@berlinmagic.com>
|
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.markdown
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# MagicRecipes
|
2
|
+
|
3
|
+
.. some capistrano-recipes for our deployment .. still in development.
|
4
|
+
|
5
|
+
Code is inspired by:
|
6
|
+
|
7
|
+
- [Ryan Bates](https://github.com/ryanb) .. [railscast #337](http://railscasts.com/episodes/337-capistrano-recipes) = some of the recipes
|
8
|
+
|
9
|
+
- [Sergey Nartimov](https://github.com/lest/capistrano-deploy) = the load mechanism
|
10
|
+
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
add magic_recipes to your Gemfile
|
14
|
+
|
15
|
+
gem 'magic_recipes', :require => nil
|
16
|
+
|
17
|
+
run bundle install
|
18
|
+
|
19
|
+
run the generator
|
20
|
+
|
21
|
+
rails g magic_recipes:capify
|
22
|
+
|
23
|
+
edit 'config/deploy'
|
24
|
+
|
25
|
+
enjoy some magic
|
26
|
+
|
27
|
+
|
28
|
+
## ToDo´s
|
29
|
+
|
30
|
+
- add tests (rspec+cucumber)
|
31
|
+
- make expect-cap-task (bin/*_cap)
|
32
|
+
|
33
|
+
- improve: passenger, unicorn rbenv, postgesql, nodejs, gems, db, git, rvm
|
34
|
+
- add: puma, varnish, search-stuff, vps-stuff
|
35
|
+
|
36
|
+
|
37
|
+
## Ready
|
38
|
+
|
39
|
+
and in use .. but not tested
|
40
|
+
|
41
|
+
- nginx
|
42
|
+
- thin
|
43
|
+
- assets
|
44
|
+
- private_pub ... needs [nginx_tcp_proxy_module](https://github.com/yaoweibin/nginx_tcp_proxy_module) for nginx
|
45
|
+
|
46
|
+
### Licence
|
47
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'MagicRecipes'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
data/bin/g_cap
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/expect -f
|
2
|
+
# Expect script to supply username/password to cap deploy to git private repository
|
3
|
+
# This script needs username and password as arguments to connect to git server:
|
4
|
+
# plus sudo password .. untested !!!
|
5
|
+
# ------------------------------------------------------------------------
|
6
|
+
# ./git_cap gitusr gitpwd su_pwd
|
7
|
+
# -------------------------------------------------------------------------
|
8
|
+
# set Variables
|
9
|
+
set g_user [lrange $argv 0 0]
|
10
|
+
set g_pwd [lrange $argv 1 1]
|
11
|
+
set su_pwd [lrange $argv 2 2]
|
12
|
+
set timeout -1
|
13
|
+
|
14
|
+
spawn cap deploy
|
15
|
+
match_max 100000
|
16
|
+
|
17
|
+
# Look for git stuff
|
18
|
+
|
19
|
+
# Look for user prompt
|
20
|
+
expect "*?sername:*"
|
21
|
+
send -- "$g_user\r"
|
22
|
+
send -- "\r"
|
23
|
+
# Look for passwod prompt
|
24
|
+
expect "*?assword:*"
|
25
|
+
send -- "$g_pwd\r"
|
26
|
+
send -- "\r"
|
27
|
+
# Look for user prompt
|
28
|
+
expect "*?sername:*"
|
29
|
+
send -- "$g_user\r"
|
30
|
+
send -- "\r"
|
31
|
+
# Look for passwod prompt
|
32
|
+
expect "*?assword:*"
|
33
|
+
send -- "$g_pwd\r"
|
34
|
+
send -- "\r"
|
35
|
+
|
36
|
+
# Look for sudo pwd
|
37
|
+
|
38
|
+
# Look for passwod prompt
|
39
|
+
expect "*?assword:*"
|
40
|
+
send -- "$su_pwd\r"
|
41
|
+
send -- "\r"
|
42
|
+
exp_continue
|
43
|
+
|
44
|
+
|
45
|
+
expect eof
|
data/bin/git_cap
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/expect -f
|
2
|
+
# Expect script to supply username/password to cap deploy to git private repository
|
3
|
+
# This script needs username and password as arguments to connect to git server:
|
4
|
+
# ------------------------------------------------------------------------
|
5
|
+
# ./git_cap gitusr gitpwd
|
6
|
+
# -------------------------------------------------------------------------
|
7
|
+
# set Variables
|
8
|
+
set g_user [lrange $argv 0 0]
|
9
|
+
set g_pwd [lrange $argv 1 1]
|
10
|
+
set timeout -1
|
11
|
+
|
12
|
+
spawn cap deploy
|
13
|
+
match_max 100000
|
14
|
+
|
15
|
+
# Look for user prompt
|
16
|
+
expect "*?sername:*"
|
17
|
+
send -- "$g_user\r"
|
18
|
+
send -- "\r"
|
19
|
+
|
20
|
+
# Look for passwod prompt
|
21
|
+
expect "*?assword:*"
|
22
|
+
send -- "$g_pwd\r"
|
23
|
+
send -- "\r"
|
24
|
+
|
25
|
+
# Look for user prompt
|
26
|
+
expect "*?sername:*"
|
27
|
+
send -- "$g_user\r"
|
28
|
+
send -- "\r"
|
29
|
+
|
30
|
+
# Look for passwod prompt
|
31
|
+
expect "*?assword:*"
|
32
|
+
send -- "$g_pwd\r"
|
33
|
+
send -- "\r"
|
34
|
+
|
35
|
+
expect eof
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails/generators'
|
3
|
+
|
4
|
+
module MagicRecipes
|
5
|
+
module Generators
|
6
|
+
class CapifyGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
desc "Some visuals."
|
11
|
+
def initial_desc
|
12
|
+
puts(' * * * * * * * * * * * * * * * * * * * * * * * * * *')
|
13
|
+
puts(' - - - - - - - - M A G I C - R E C I P E S - - - - - - - - - - -')
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
def create_root_files
|
19
|
+
if File.exists?( "#{ Rails.root }/Capfile" )
|
20
|
+
File.rename("#{ Rails.root }/Capfile", "#{ Rails.root }/Capfile.old")
|
21
|
+
end
|
22
|
+
if File.exists?( "#{ Rails.root }/config/deploy.rb" )
|
23
|
+
File.rename("#{ Rails.root }/config/deploy.rb", "#{ Rails.root }/config/deploy.rb.old")
|
24
|
+
end
|
25
|
+
template "Capfile.tt", "#{ Rails.root }/Capfile"
|
26
|
+
template "deploy.rb.tt", "#{ Rails.root }/config/deploy.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
def end_desc
|
32
|
+
puts(" - - - - - - - - you are ready for magic! - - - - - - - - - - -")
|
33
|
+
puts(' * * * * * * * * * * * * * * * * * * * * * * * * * *')
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2
|
+
# Magic - Recipes
|
3
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
4
|
+
# Usage:
|
5
|
+
# magic_recipes :rvm, :nginx, :private_pub, :thin
|
6
|
+
# available:
|
7
|
+
# :rvm, :rbenv, :nginx, :private_pub, :thin, :passenger, :unicorn, :assets, :gems
|
8
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
9
|
+
|
10
|
+
magic_recipes :rvm, :nginx, :private_pub, :thin
|
11
|
+
|
12
|
+
|
13
|
+
server "0.0.0.0", :web, :app, :db, :primary => true
|
14
|
+
|
15
|
+
set :user, "deploy" #=> ssh-user
|
16
|
+
set :password, "password" #=> sudo-pwd
|
17
|
+
set :domains, ["example.com", "www.example.com"] #=> domain list
|
18
|
+
set :application, "example-app" #=> app / folder name
|
19
|
+
set :app_name, "exampleapp" #=> shortname for app
|
20
|
+
set :server_ip, "0.0.0.0" #=> IP of the Server
|
21
|
+
set :deploy_to, "/home/deploy/apps/#{application}" #=> deploy path
|
22
|
+
set :rails_env, "production" #=> Rails environment
|
23
|
+
|
24
|
+
|
25
|
+
# rvm variables:
|
26
|
+
# => set :rvm_ruby, '1.9.3' #=> Ruby version
|
27
|
+
# => set :rvm_patch, 'p0' #=> Patch level
|
28
|
+
# => set :rvm_gemset, 'global' #=> Gemset
|
29
|
+
# => set :rvm_path, '/usr/local/rvm' #=> RVM-Path
|
30
|
+
|
31
|
+
|
32
|
+
# nginx variables:
|
33
|
+
# => set :rails_server, 'thin' #=> Rails-Server ( thin | passenger | unicorn )
|
34
|
+
# => set :app_instances, 3 #=> Server instances
|
35
|
+
# => set :http_enabled_path, '/opt/nginx/http-enabled' #=> HTTP-folder (sites-enabled)
|
36
|
+
# => set :tcp_enabled_path, '/opt/nginx/tcp-enabled' #=> TCP-folder (needs nginx_tcp_proxy_module)
|
37
|
+
# => set :default_site, false #=> Is this site the server default ?
|
38
|
+
|
39
|
+
|
40
|
+
# thin variables:
|
41
|
+
# => set :thin_path, '/etc/thin' #=> Thin config path
|
42
|
+
|
43
|
+
|
44
|
+
# private_pub variables:
|
45
|
+
# => set :private_pub_domain, "0.0.0.0" #=> private_pub domain
|
46
|
+
# => set :private_pub_host, 9200 #=> public port
|
47
|
+
# => set :private_pub_port, 9292 #=> intern port
|
48
|
+
# => set :private_pub_key, "882293e492b7e7a2fed266a5f38062420e12fb75eae5f145e256af60dc9681bc"
|
49
|
+
|
50
|
+
|
51
|
+
# assets variables:
|
52
|
+
# => set :normalize_asset_timestamps, true #=> ?
|
53
|
+
# => set :make_pulbic_folder_public, true #=> chmod 777 on 'public' and 'tmp' folder
|
54
|
+
|
55
|
+
|
56
|
+
# GitHub
|
57
|
+
# => set :scm, :git
|
58
|
+
# => set :repository, "git@github.com:gitname/repo.git" #=> for private-repos: "https://github.com/gitname/repo.git"
|
59
|
+
# => set :deploy_via, :copy #=> :copy | :remote_cache | ..
|
60
|
+
# => set :branch, :master #=> Git branch
|
61
|
+
# => # set :local_repository, "/path/to/repo.git" #=> for local-path
|
62
|
+
# => # set :git_enable_submodules, 1 #=> Git submodules
|
63
|
+
|
64
|
+
|
65
|
+
# if you want to clean up old releases on each deploy uncomment this:
|
66
|
+
# => set :keep_releases, 3
|
67
|
+
# => after "deploy:restart", "deploy:cleanup"
|
68
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module MagicRecipes
|
3
|
+
module Assets
|
4
|
+
def self.load_into(configuration)
|
5
|
+
configuration.load do
|
6
|
+
|
7
|
+
set_default :asset_env, "RAILS_GROUPS=assets"
|
8
|
+
set_default :assets_prefix, "assets"
|
9
|
+
set_default :assets_role, [:web]
|
10
|
+
|
11
|
+
set_default :normalize_asset_timestamps, false
|
12
|
+
set_default :make_pulbic_folder_public, false
|
13
|
+
|
14
|
+
before 'deploy:finalize_update', 'deploy:assets:symlink'
|
15
|
+
after 'deploy:update_code', 'deploy:assets:precompile'
|
16
|
+
|
17
|
+
namespace :deploy do
|
18
|
+
namespace :assets do
|
19
|
+
desc <<-DESC
|
20
|
+
[internal] This task will set up a symlink to the shared directory \
|
21
|
+
for the assets directory. Assets are shared across deploys to avoid \
|
22
|
+
mid-deploy mismatches between old application html asking for assets \
|
23
|
+
and getting a 404 file not found error. The assets cache is shared \
|
24
|
+
for efficiency. If you customize the assets path prefix, override the \
|
25
|
+
:assets_prefix variable to match.
|
26
|
+
DESC
|
27
|
+
task :symlink, :roles => assets_role, :except => { :no_release => true } do
|
28
|
+
run <<-CMD
|
29
|
+
rm -rf #{latest_release}/public/#{assets_prefix} &&
|
30
|
+
mkdir -p #{latest_release}/public &&
|
31
|
+
mkdir -p #{shared_path}/assets &&
|
32
|
+
ln -s #{shared_path}/assets #{latest_release}/public/#{assets_prefix}
|
33
|
+
CMD
|
34
|
+
end
|
35
|
+
|
36
|
+
desc <<-DESC
|
37
|
+
Run the asset precompilation rake task. You can specify the full path \
|
38
|
+
to the rake executable by setting the rake variable. You can also \
|
39
|
+
specify additional environment variables to pass to rake via the \
|
40
|
+
asset_env variable. The defaults are:
|
41
|
+
|
42
|
+
set :rake, "rake"
|
43
|
+
set :rails_env, "production"
|
44
|
+
set :asset_env, "RAILS_GROUPS=assets"
|
45
|
+
DESC
|
46
|
+
task :precompile, :roles => assets_role, :except => { :no_release => true } do
|
47
|
+
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile"
|
48
|
+
if make_pulbic_folder_public
|
49
|
+
chmod
|
50
|
+
end
|
51
|
+
# run <<-CMD
|
52
|
+
# source '/usr/local/rvm/scripts/rvm' &&
|
53
|
+
# rvm use 1.9.3 &&
|
54
|
+
# cd #{latest_release} &&
|
55
|
+
# #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile &&
|
56
|
+
# #{sudo} chmod -R 777 public/ &&
|
57
|
+
# #{sudo} chmod -R 777 tmp/
|
58
|
+
# CMD
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "make the public folder public for all (777)"
|
62
|
+
task :chmod, :roles => assets_role, :except => { :no_release => true } do
|
63
|
+
run "cd #{latest_release} && #{sudo} chmod -R 777 public/ && #{sudo} chmod -R 777 tmp/"
|
64
|
+
# run <<-CMD
|
65
|
+
# source '/usr/local/rvm/scripts/rvm' &&
|
66
|
+
# rvm use 1.9.3 &&
|
67
|
+
# cd #{latest_release} &&
|
68
|
+
# #{sudo} chmod -R 777 public/ &&
|
69
|
+
# #{sudo} chmod -R 777 tmp/
|
70
|
+
# CMD
|
71
|
+
end
|
72
|
+
|
73
|
+
desc <<-DESC
|
74
|
+
Run the asset clean rake task. Use with caution, this will delete \
|
75
|
+
all of your compiled assets. You can specify the full path \
|
76
|
+
to the rake executable by setting the rake variable. You can also \
|
77
|
+
specify additional environment variables to pass to rake via the \
|
78
|
+
asset_env variable. The defaults are:
|
79
|
+
|
80
|
+
set :rake, "rake"
|
81
|
+
set :rails_env, "production"
|
82
|
+
set :asset_env, "RAILS_GROUPS=assets"
|
83
|
+
DESC
|
84
|
+
task :clean, :roles => assets_role, :except => { :no_release => true } do
|
85
|
+
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:clean"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module MagicRecipes
|
3
|
+
module Db
|
4
|
+
def self.load_into(configuration)
|
5
|
+
configuration.load do
|
6
|
+
|
7
|
+
namespace :db do
|
8
|
+
|
9
|
+
desc "seed the database"
|
10
|
+
task :seed do
|
11
|
+
run <<-CMD
|
12
|
+
source '/usr/local/rvm/scripts/rvm' &&
|
13
|
+
rvm use 1.9.3 &&
|
14
|
+
cd #{latest_release} &&
|
15
|
+
#{rake} db:seed RAILS_ENV=#{rails_env}
|
16
|
+
CMD
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "migrate the database"
|
20
|
+
task :migrate do
|
21
|
+
run <<-CMD
|
22
|
+
source '/usr/local/rvm/scripts/rvm' &&
|
23
|
+
rvm use 1.9.3 &&
|
24
|
+
cd #{latest_release} &&
|
25
|
+
#{rake} db:migrate RAILS_ENV=#{rails_env}
|
26
|
+
CMD
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# eof
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module MagicRecipes
|
3
|
+
module Gems
|
4
|
+
def self.load_into(configuration)
|
5
|
+
configuration.load do
|
6
|
+
|
7
|
+
namespace :gems do
|
8
|
+
task :install do
|
9
|
+
run "cd #{deploy_to}/current && RAILS_ENV=production bundle install --no-deployment"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# after :deploy, "gems:install"
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module MagicRecipes
|
3
|
+
module Rvm
|
4
|
+
def self.load_into(configuration)
|
5
|
+
configuration.load do
|
6
|
+
|
7
|
+
|
8
|
+
set_default :git_usr, "gitusr"
|
9
|
+
set_default :git_pwd, "gitpwd"
|
10
|
+
|
11
|
+
namespace :git do
|
12
|
+
|
13
|
+
# Restart Passenger
|
14
|
+
desc "avoid Username and Passwort input twice"
|
15
|
+
task :private do
|
16
|
+
# should start git_cap localy
|
17
|
+
if git_usr && git_usr != "gitusr" && git_pwd && git_pwd != "gitpwd"
|
18
|
+
run system( "../../../bin/git_cap #{git_usr} #{git_pwd}" )
|
19
|
+
end
|
20
|
+
# %x()
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
# eof
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module MagicRecipes
|
3
|
+
module Nginx
|
4
|
+
def self.load_into(configuration)
|
5
|
+
configuration.load do
|
6
|
+
|
7
|
+
set_default :rails_server, 'thin'
|
8
|
+
set_default :http_enabled_path, '/opt/nginx/http-enabled'
|
9
|
+
set_default :tcp_enabled_path, '/opt/nginx/tcp-enabled'
|
10
|
+
set_default :default_site, false
|
11
|
+
|
12
|
+
|
13
|
+
namespace :nginx do
|
14
|
+
|
15
|
+
desc "Install latest stable release of nginx"
|
16
|
+
task :install, roles: :web do
|
17
|
+
run "#{sudo} add-apt-repository ppa:nginx/stable"
|
18
|
+
run "#{sudo} apt-get -y update"
|
19
|
+
run "#{sudo} apt-get -y install nginx"
|
20
|
+
end
|
21
|
+
after "deploy:install", "nginx:install"
|
22
|
+
|
23
|
+
|
24
|
+
desc "Setup nginx configuration for this application"
|
25
|
+
task :setup, roles: :web do
|
26
|
+
template "nginx_#{rails_server}.erb", "/tmp/nginx_http_conf"
|
27
|
+
run "#{sudo} rm #{http_enabled_path}/#{app_name}_*"
|
28
|
+
run "#{sudo} mv /tmp/nginx_http_conf #{http_enabled_path}/#{app_name}_#{rails_server}.conf"
|
29
|
+
end
|
30
|
+
after "deploy:setup", "nginx:setup"
|
31
|
+
|
32
|
+
|
33
|
+
%w[start stop].each do |command|
|
34
|
+
desc "#{command} nginx"
|
35
|
+
task command, roles: :web do
|
36
|
+
run "#{sudo} service nginx #{command}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
desc "restart nginx-server"
|
42
|
+
task :restart, roles: :web do
|
43
|
+
setup
|
44
|
+
stop
|
45
|
+
start
|
46
|
+
end
|
47
|
+
after "deploy", "nginx:restart"
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
# eof
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module MagicRecipes
|
3
|
+
module Nodejs
|
4
|
+
def self.load_into(configuration)
|
5
|
+
configuration.load do
|
6
|
+
|
7
|
+
# code is taken from railscast #337
|
8
|
+
|
9
|
+
namespace :nodejs do
|
10
|
+
desc "Install the latest relase of Node.js"
|
11
|
+
task :install, roles: :app do
|
12
|
+
run "#{sudo} add-apt-repository ppa:chris-lea/node.js"
|
13
|
+
run "#{sudo} apt-get -y update"
|
14
|
+
run "#{sudo} apt-get -y install nodejs"
|
15
|
+
end
|
16
|
+
after "deploy:install", "nodejs:install"
|
17
|
+
end
|
18
|
+
|
19
|
+
# eof
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module MagicRecipes
|
3
|
+
module Passenger
|
4
|
+
def self.load_into(configuration)
|
5
|
+
configuration.load do
|
6
|
+
|
7
|
+
set_default :pre_start, false # => pre_start the first domain ?
|
8
|
+
|
9
|
+
namespace :passenger do
|
10
|
+
|
11
|
+
# Restart Passenger
|
12
|
+
desc "Restart - Passenger"
|
13
|
+
task :restart, :roles => :app, :except => { :no_release => true } do
|
14
|
+
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
|
15
|
+
end
|
16
|
+
after "deploy:restart", "passenger:restart"
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module MagicRecipes
|
3
|
+
module Assets
|
4
|
+
def self.load_into(configuration)
|
5
|
+
configuration.load do
|
6
|
+
|
7
|
+
# code is taken from railscast #337
|
8
|
+
|
9
|
+
set_default(:postgresql_host, "localhost")
|
10
|
+
set_default(:postgresql_user) { application }
|
11
|
+
set_default(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
|
12
|
+
set_default(:postgresql_database) { "#{application}_production" }
|
13
|
+
|
14
|
+
namespace :postgresql do
|
15
|
+
desc "Install the latest stable release of PostgreSQL."
|
16
|
+
task :install, roles: :db, only: {primary: true} do
|
17
|
+
run "#{sudo} add-apt-repository ppa:pitti/postgresql"
|
18
|
+
run "#{sudo} apt-get -y update"
|
19
|
+
run "#{sudo} apt-get -y install postgresql libpq-dev"
|
20
|
+
end
|
21
|
+
after "deploy:install", "postgresql:install"
|
22
|
+
|
23
|
+
desc "Create a database for this application."
|
24
|
+
task :create_database, roles: :db, only: {primary: true} do
|
25
|
+
run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"}
|
26
|
+
run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user};"}
|
27
|
+
end
|
28
|
+
after "deploy:setup", "postgresql:create_database"
|
29
|
+
|
30
|
+
desc "Generate the database.yml configuration file."
|
31
|
+
task :setup, roles: :app do
|
32
|
+
run "mkdir -p #{shared_path}/config"
|
33
|
+
template "postgresql.yml.erb", "#{shared_path}/config/database.yml"
|
34
|
+
end
|
35
|
+
after "deploy:setup", "postgresql:setup"
|
36
|
+
|
37
|
+
desc "Symlink the database.yml file into latest release"
|
38
|
+
task :symlink, roles: :app do
|
39
|
+
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
40
|
+
end
|
41
|
+
after "deploy:finalize_update", "postgresql:symlink"
|
42
|
+
end
|
43
|
+
|
44
|
+
# eof
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|