deprec 2.2.0 → 2.2.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/CHANGELOG CHANGED
@@ -1,6 +1,14 @@
1
1
  # deprec changelog
2
2
 
3
- = 2.2.1 (Jul 10, 2011)
3
+ = 2.2.1 (Jul 15, 2011)
4
+
5
+ * deprec now provides rake tasks
6
+
7
+ Just add this to your Rakefile
8
+
9
+ require 'deprec/rake'
10
+
11
+ = 2.2.0 (Jul 10, 2011)
4
12
 
5
13
  * First release since rewrite of http://deprec.org
6
14
  * Tidy up of various recipes
data/docs/README.rails CHANGED
@@ -1,17 +1,23 @@
1
- deprec: Install Ruby on Rails app on fresh Ubuntu 7.10 (gutsy), 8.04 (hardy)
2
- ============================================================================
1
+ Install Ruby on Rails app with deprec
2
+ =====================================
3
3
 
4
- * Quickstart
4
+ The rack recipes should work with any rack app.
5
5
 
6
- cd your_rails_app
7
- depify .
8
- # Edit config/deploy.rb
9
- cap deprec:rails:install_stack
6
+ *Quickstart*
10
7
 
11
- # WARNING! Don't run the following command if you are using a shared
12
- # database server that has already been installed.
13
- cap deprec:db:install
8
+ $ cap deprec:rack:install_stack
14
9
 
15
- cap deploy:setup
16
- cap deploy
17
- cap deploy:migrate
10
+ $ cd your_rails_app
11
+ $ depify .
12
+ # Edit config/deploy.rb and config/deploy/uat.rb
13
+
14
+ # WARNING! Don't run the following command if you are using a shared
15
+ # database server that has already been installed.
16
+ $ cap deprec:db:install
17
+
18
+ $ cap deploy:setup HOSTS=mbailey@uat
19
+
20
+ $ cap deprec:rack:config HOSTS=mbailey@uat
21
+
22
+ # ssh to git@github.com from uat and accept hostkey
23
+ $ cap deploy
@@ -0,0 +1,6 @@
1
+
2
+ # Add option to symlink apache vhosts
3
+ #
4
+ # This will make updating with deploys easier
5
+ #
6
+ ln -sf /srv/brandish/current/config/uat/passenger/apache_vhost brandish
@@ -0,0 +1,68 @@
1
+ # Copyright 2011 Chris Griego
2
+ #
3
+ # Capistrano::Configuration.instance(:must_exist).load do
4
+ # require 'capistrano/recipes/deploy'
5
+
6
+ def _cset(name, *args, &block)
7
+ unless exists?(name)
8
+ set(name, *args, &block)
9
+ end
10
+ end
11
+
12
+ _cset :asset_env, "RAILS_GROUPS=assets"
13
+ _cset :rails_env, "production"
14
+
15
+ # rails-3.1 does not use asset timestamps
16
+ set :normalize_asset_timestamps, false
17
+
18
+ after 'deploy:update_code', 'deploy:assets:symlink'
19
+ after 'deploy:update_code', 'deploy:assets:precompile'
20
+
21
+ namespace :deploy do
22
+ namespace :assets do
23
+ desc <<-DESC
24
+ [internal] This task will set up a symlink to the shared directory \
25
+ for the assets directory. Assets are shared across deploys to avoid \
26
+ mid-deploy mismatches between old application html asking for assets \
27
+ and getting a 404 file not found error.
28
+ DESC
29
+ task :symlink, :roles => :web, :except => { :no_release => true } do
30
+ run <<-CMD
31
+ rm -rf #{latest_release}/public/assets &&
32
+ mkdir -p #{latest_release}/public &&
33
+ mkdir -p #{shared_path}/assets &&
34
+ ln -s #{shared_path}/assets #{latest_release}/public/assets
35
+ CMD
36
+ end
37
+
38
+ desc <<-DESC
39
+ Run the asset precompilation rake task. You can specify the full path \
40
+ to the rake executable by setting the rake variable. You can also \
41
+ specify additional environment variables to pass to rake via the \
42
+ asset_env variable. The defaults are:
43
+
44
+ set :rake, "rake"
45
+ set :rails_env, "production"
46
+ set :asset_env, "RAILS_GROUPS=assets"
47
+ DESC
48
+ task :precompile, :roles => :web, :except => { :no_release => true } do
49
+ run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile"
50
+ end
51
+
52
+ desc <<-DESC
53
+ Run the asset clean rake task. Use with caution, this will delete \
54
+ all of your compiled assets. You can specify the full path \
55
+ to the rake executable by setting the rake variable. You can also \
56
+ specify additional environment variables to pass to rake via the \
57
+ asset_env variable. The defaults are:
58
+
59
+ set :rake, "rake"
60
+ set :rails_env, "production"
61
+ set :asset_env, "RAILS_GROUPS=assets"
62
+ DESC
63
+ task :clean, :roles => :web, :except => { :no_release => true } do
64
+ run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:clean"
65
+ end
66
+ end
67
+ end
68
+ end
@@ -390,16 +390,6 @@ module Deprec2
390
390
  end
391
391
  end
392
392
 
393
- # deprecated...I don't see any need for this
394
- # Set the value if not already set
395
- # This method is accessible to all recipe files
396
- def self.default(name, *args, &block)
397
- puts "********** deprecation warning **********"
398
- puts "Could you use set() instead of default()?"
399
- puts "*****************************************"
400
- set(name, *args, &block) unless exists?(name)
401
- end
402
-
403
393
  private
404
394
 
405
395
  ##
@@ -0,0 +1,10 @@
1
+ $VERBOSE = nil
2
+
3
+ # Load deprec rakefile extensions
4
+ %w(
5
+ db
6
+ environments
7
+ ).each do |task|
8
+ load File.join(File.dirname(__FILE__), 'rake', "#{task}.rake")
9
+ end
10
+
@@ -0,0 +1,37 @@
1
+ require 'find'
2
+ namespace :deprec do
3
+
4
+ namespace :db do
5
+
6
+ # Task written by Craig Ambrose <craigambrose.com>
7
+ desc "Backup the database to a file. Options: DIR=backup_dir RAILS_ENV=production MAX=20"
8
+ task :backup => :environment do
9
+ unless defined? RAILS_ENV
10
+ RAILS_ENV = ENV['RAILS_ENV'] ||= 'development'
11
+ end
12
+ max_backups = (ENV['MAX'] || 20).to_i
13
+ datestamp = Time.now.strftime("%Y%m%d-%H%M%S")
14
+ backup_dir = ENV['DIR'] || "db/backups"
15
+ backup_file = File.join(backup_dir, "#{RAILS_ENV}-#{datestamp}.sql.gz")
16
+ FileUtils.mkdir_p(backup_dir)
17
+ db_config = ActiveRecord::Base.configurations[RAILS_ENV]
18
+ pass = ''
19
+ pass = '-p' + db_config['password'] if db_config['password']
20
+ sh "mysqldump -u #{db_config['username']} #{pass} #{db_config['database']} -Q --add-drop-table -O add-locks=FALSE -O lock-tables=FALSE | gzip -c > #{backup_file}"
21
+ puts "Created backup: #{backup_file}"
22
+ dir = Dir.new(backup_dir)
23
+ all_backups = dir.entries[2..-1].sort.reverse
24
+ unwanted_backups = all_backups[max_backups..-1] || []
25
+ for unwanted_backup in unwanted_backups
26
+ FileUtils.rm_rf(File.join(backup_dir, unwanted_backup))
27
+ puts "deleted #{unwanted_backup}"
28
+ end
29
+ puts "Deleted #{unwanted_backups.length} backups, #{all_backups.length - unwanted_backups.length} backups available"
30
+ end
31
+
32
+ desc "Restore database"
33
+ task :restore => :environment do
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ # This coolness is from Chris Wanstrath
2
+ # http://errtheblog.com/posts/31-rake-around-the-rosie
3
+
4
+ %w(development production staging testing).each do |env|
5
+ desc "Runs the following task in the #{env} environment"
6
+ task env.to_sym do
7
+ RAILS_ENV = ENV['RAILS_ENV'] = env
8
+ end
9
+ end
@@ -3,11 +3,18 @@ Capistrano::Configuration.instance(:must_exist).load do
3
3
 
4
4
  # Set the value if not already set
5
5
  # This method is accessible to all recipe files
6
- def self.default(name, *args, &block)
6
+ # Defined and used by capistrano/deploy tasks
7
+ def _cset(name, *args, &block)
7
8
  unless exists?(name)
8
9
  set(name, *args, &block)
9
10
  end
10
11
  end
12
+
13
+ # deprecated
14
+ alias :default :_cset
15
+
16
+ # _cset :rake, 'rake'
17
+ _cset :rake, 'rakes'
11
18
 
12
19
  # Deprec checks here for local versions of config templates before it's own
13
20
  set :local_template_dir, File.join('config','templates')
@@ -19,6 +19,14 @@ Capistrano::Configuration.instance(:must_exist).load do
19
19
  set :passenger_pool_idle_time, 300
20
20
  set :passenger_rails_autodetect, 'on'
21
21
  set :passenger_rails_spawn_method, 'smart' # smart | conservative
22
+ set :passenger_redirect_to_canonical_hostname, true
23
+ set(:passenger_server_alii) {
24
+ if domain =~ /^www\./
25
+ domain.sub 'www.', ''
26
+ else
27
+ "www.#{domain}"
28
+ end
29
+ }
22
30
 
23
31
  desc "Install Passenger"
24
32
  task :install, :roles => :app do
@@ -3,13 +3,25 @@ Capistrano::Configuration.instance(:must_exist).load do
3
3
  namespace :deprec do
4
4
  namespace :users do
5
5
 
6
- set(:users_target_user) { Capistrano::CLI.ui.ask "Enter userid" do |q| q.default = current_user; end }
7
- set(:users_target_group) { Capistrano::CLI.ui.ask "Enter group name for new user" do |q| q.default = 'deploy'; end }
8
- set(:users_make_admin) { Capistrano::CLI.ui.ask "Should this be an admin account?" do |q| q.default = 'no'; end }
6
+ set(:users_target_user) {
7
+ Capistrano::CLI.ui.ask "Enter userid" do |q|
8
+ q.default = current_user;
9
+ end
10
+ }
11
+ set(:users_target_group) {
12
+ Capistrano::CLI.ui.ask "Enter group name for new user" do |q|
13
+ q.default = users_target_user;
14
+ end
15
+ }
16
+ set(:users_make_admin) {
17
+ Capistrano::CLI.ui.ask "Should this be an admin account?" do |q|
18
+ q.default = 'no';
19
+ end
20
+ }
9
21
 
10
22
  desc "Create account"
11
23
  task :add do
12
- [users_target_user, users_make_admin] # get input
24
+ [users_target_user, users_target_group, users_make_admin] # get input
13
25
  new_password = get_new_password
14
26
 
15
27
  # Grab a list of all users with keys
@@ -19,7 +31,8 @@ Capistrano::Configuration.instance(:must_exist).load do
19
31
 
20
32
  Array(users_target_user).each do |user|
21
33
 
22
- deprec2.useradd(user, :shell => '/bin/bash')
34
+ deprec2.groupadd(users_target_group)
35
+ deprec2.useradd(user, :group => group, :shell => '/bin/bash')
23
36
  deprec2.invoke_with_input("passwd #{user}", /UNIX password/, new_password)
24
37
 
25
38
  if users_make_admin.match(/y/i)
@@ -10,13 +10,16 @@ global
10
10
  pidfile /var/run/haproxy.pid
11
11
  daemon
12
12
 
13
+
13
14
  defaults
14
- option forwardfor
15
+ # Stats page at /haproxy?stats
15
16
  stats enable
16
- stats auth myuser:mypass
17
- balance roundrobin
18
- option httpclose
17
+ stats auth admin:secret
18
+
19
19
  mode http
20
+ option forwardfor # Adds X-Forwarded-For header to http reqs
21
+ option httpclose # Needed for forwardfor
22
+ balance roundrobin
20
23
  retries 3
21
24
  option redispatch
22
25
  maxconn 2000
@@ -24,8 +27,23 @@ defaults
24
27
  clitimeout 50000
25
28
  srvtimeout 50000
26
29
 
27
- listen example_lb *:81
30
+
31
+ frontend web *:80
32
+
33
+ acl www hdr_beg(host) -i www
34
+
35
+ acl ip_local src 192.168.0.0/24
36
+
37
+ use_backend example_lb if www ip_local
38
+
39
+ default_backend localhost
40
+
41
+
42
+ backend example_lb
28
43
  option httpchk HEAD /check.txt HTTP/1.0
29
44
  server web1 127.0.0.1:80 weight 6 maxconn 12 check # cookie A
30
45
  server web2 127.0.0.1:80 weight 10 maxconn 12 check # cookie B
31
46
 
47
+
48
+ backend localhost
49
+ server LOCALHOST 127.0.0.1:80
@@ -1,28 +1,52 @@
1
- # Don't cause the server to break if Passenger module not loaded
2
- <IfModule passenger_module>
3
- <VirtualHost *:80>
4
- ServerName <%= domain %>
5
- <%- 4.times do |counter| -%>
6
- ServerAlias <%= domain.sub(/.*?\./, "assets#{counter}.") %>
7
- <%- end %>
8
- DocumentRoot "<%= passenger_document_root %>"
9
- CustomLog <%= apache_log_dir %>/<%= application %>-access.log combined
10
- ErrorLog <%= apache_log_dir %>/<%= application %>-error.log
1
+ <IfModule passenger_module>
2
+ <VirtualHost *:80>
3
+
4
+ ServerName <%= domain %>
5
+ <%- Array(passenger_server_alii).each do |server_alias| -%>
6
+ ServerAlias <%= server_alias %>
7
+ <%- end -%>
8
+
9
+ <%- if passenger_redirect_to_canonical_hostname -%>
10
+ # Redirect to canonical hostname
11
+ RewriteEngine On
12
+ RewriteCond %{HTTP_HOST} !^<%= domain.gsub('.','\.') %> [NC]
13
+ RewriteCond %{HTTP_HOST} !^$
14
+ RewriteRule ^/?(.*) http://<%= domain %>/$1 [L,R=301,NE]
15
+ <%- end -%>
16
+
17
+ DocumentRoot <%= passenger_document_root %>
18
+ <Directory <%= passenger_document_root %>>
19
+ Allow from all
20
+ Options -MultiViews
21
+ </Directory>
22
+
23
+ CustomLog <%= apache_log_dir %>/<%= application %>-access.log combined
24
+ ErrorLog <%= apache_log_dir %>/<%= application %>-error.log
11
25
 
12
- RackEnv <%= rack_env %>
13
- RailsEnv <%= rack_env %>
14
- # RailsAllowModRewrite <%= passenger_rails_allow_mod_rewrite %>
15
- #
16
- # Check for maintenance file and redirect all requests
17
- RewriteEngine On
18
- RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
19
- RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
20
- RewriteCond %{SCRIPT_FILENAME} !maintenance.html
21
- RewriteRule ^.*$ /system/maintenance.html [L]
22
- <Directory "<%= passenger_document_root %>">
23
- Order allow,deny
24
- Allow from all
25
- </Directory>
26
- </VirtualHost>
27
- </IfModule>
26
+ RackEnv <%= rack_env %>
27
+ RailsEnv <%= rack_env %>
28
+
29
+ # Enable caching of assets containing a fingerprint
30
+ # Browsers need never check for newer versions of an
31
+ # asset because the fingerprint would be different.
32
+ <FilesMatch "/assets/[^.]+-[a-z0-9]{32}\.">
33
+ # Add far-future expiration dates
34
+ <IfModule mod_expires.c>
35
+ ExpiresActive On
36
+ ExpiresDefault "access plus 10 years"
37
+ </IfModule>
38
+ # Disable ETags
39
+ <IfModule mod_expires.c>
40
+ Header unset "ETag"
41
+ </IfModule>
42
+ </FilesMatch>
28
43
 
44
+ # Check for maintenance file and redirect all requests
45
+ RewriteEngine On
46
+ RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
47
+ RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
48
+ RewriteCond %{SCRIPT_FILENAME} !maintenance.html
49
+ RewriteRule ^.*$ /system/maintenance.html [L]
50
+
51
+ </VirtualHost>
52
+ </IfModule>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: deprec
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.2.0
5
+ version: 2.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike Bailey
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-10 00:00:00 Z
13
+ date: 2011-07-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: capistrano
@@ -59,6 +59,8 @@ files:
59
59
  - docs/nagios.txt
60
60
  - lib/deprec_cmd_completion.sh
61
61
  - lib/deprec_minus_rails.rb
62
+ - lib/deprec/rake.rb
63
+ - lib/deprec/TODO.txt
62
64
  - lib/deprec/recipes.rb
63
65
  - lib/deprec/capistrano_extensions.rb
64
66
  - lib/deprec/recipes/deprecated.rb
@@ -253,7 +255,10 @@ files:
253
255
  - lib/deprec/templates/bash/bash_global
254
256
  - lib/deprec/templates/ddclient/ddclient.erb
255
257
  - lib/deprec/templates/ddclient/ddclient.conf.erb
258
+ - lib/deprec/callbacks/asset_pipeline.rb
256
259
  - lib/deprec/recipes_minus_rails.rb
260
+ - lib/deprec/rake/db.rake
261
+ - lib/deprec/rake/environments.rake
257
262
  - lib/vmbuilder_plugins/all.rb
258
263
  - lib/vmbuilder_plugins/apt.rb
259
264
  - lib/vmbuilder_plugins/emerge.rb