Skip to content

Instantly share code, notes, and snippets.

@pierot
Created February 1, 2011 13:51
Show Gist options
  • Save pierot/805879 to your computer and use it in GitHub Desktop.
Save pierot/805879 to your computer and use it in GitHub Desktop.
Capistrano snippet to secure deployment environment
set :stages, %w(testing staging production)
set :default_stage, "testing"
require 'capistrano/ext/multistage'
task :protect do
# http://www.htaccesstools.com/htaccess-authentication/
run "echo 'username:$apr1$gT8Ap...$3f8RadFS7xottW8AYVX5b0' >> #{File.join(current_path, '.htpasswd')}"
run "echo 'AuthType Basic' >> #{File.join(current_path, '.htaccess')}"
run "echo 'AuthName \"Restricted\"' >> #{File.join(current_path, '.htaccess')}"
run "echo 'AuthUserFile /absolute/path/to/.htpasswd' >> #{File.join(current_path, '.htaccess')}"
run "echo 'Require valid-user' >> #{File.join(current_path, '.htaccess')}"
end
task :restart, :roles => :app, :except => { :no_release => true } do
if [:testing, :staging].include? stage
deploy.protect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment