Skip to content

Commit

Permalink
Merge pull request #51 from IntractableQuery/master
Browse files Browse the repository at this point in the history
Protect remote server from pushing
  • Loading branch information
sgruhier committed Oct 29, 2014
2 parents 8afc3f5 + 25f82f6 commit adedf1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Add to config/deploy.rb:

# if you want to work on a specific local environment (default = ENV['RAILS_ENV'] || 'development')
set :locals_rails_env, "production"

# if you are highly paranoid and want to prevent any push operation to the server
set :disallow_pushing, true
```

Add to .gitignore
Expand Down
15 changes: 11 additions & 4 deletions lib/capistrano-db-tasks/dbtasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
set :assets_dir, 'system' unless fetch(:assets_dir)
set :local_assets_dir, 'public' unless fetch(:local_assets_dir)
set :skip_data_sync_confirm, (ENV['SKIP_DATA_SYNC_CONFIRM'].to_s.downcase == 'true')
set :disallow_pushing, false unless fetch(:disallow_pushing)

namespace :capistrano_db_tasks do
task :check_can_push do
raise "pushing is disabled, set disallow_pushing to false to carry out this operation" if fetch(:disallow_pushing)
end
end

namespace :db do
namespace :remote do
desc 'Synchronize your remote database using local database data'
task :sync do
task :sync => 'capistrano_db_tasks:check_can_push' do
on roles(:db) do
if fetch(:skip_data_sync_confirm) || Util.prompt('Are you sure you want to REPLACE THE REMOTE DATABASE with local database')
Database.local_to_remote(self)
Expand Down Expand Up @@ -43,7 +50,7 @@
namespace :assets do
namespace :remote do
desc 'Synchronize your remote assets using local assets'
task :sync do
task :sync => 'capistrano_db_tasks:check_can_push' do
on roles(:app) do
puts "Assets directories: #{fetch(:assets_dir)}"
if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your server assets with local assets")
Expand Down Expand Up @@ -75,7 +82,7 @@
namespace :app do
namespace :remote do
desc 'Synchronize your remote assets AND database using local assets and database'
task :sync do
task :sync => 'capistrano_db_tasks:check_can_push' do
if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to REPLACE THE REMOTE DATABASE AND your remote assets with local database and assets(#{fetch(:assets_dir)})")
on roles(:db) do
Database.local_to_remote(self)
Expand Down Expand Up @@ -110,4 +117,4 @@

desc 'Synchronize your remote assets AND database using local assets and database'
task :push => "app:remote:sync"
end
end

0 comments on commit adedf1c

Please sign in to comment.