Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds reasonable defaults, uses Array for directories #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions lib/capistrano-db-tasks/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,37 @@ module Asset
extend self

def remote_to_local(cap)
servers = Capistrano::Configuration.env.send(:servers)
server = servers.detect { |s| s.roles.include?(:app) }
port = server.netssh_options[:port] || 22
user = server.netssh_options[:user]
[cap.fetch(:assets_dir)].flatten.each do |dir|
system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' #{user}@#{server}:#{cap.current_path}/#{dir} #{cap.fetch(:local_assets_dir)}")
raise "server with role app is undefined" if server.nil?
# puts "assets_dir: #{cap.shared_path}/#{Array(cap.fetch(:assets_dir))}"
# puts "local_assets_dir: #{Array(cap.fetch(:local_assets_dir))}"
Array(cap.fetch(:assets_dir)).each do |dir|
system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' #{user}@#{server}:#{cap.shared_path}/#{dir} #{Array(cap.fetch(:local_assets_dir)).join}")
end
end

def local_to_remote(cap)
servers = Capistrano::Configuration.env.send(:servers)
server = servers.detect { |s| s.roles.include?(:app) }
port = server.netssh_options[:port] || 22
user = server.netssh_options[:user]
[cap.fetch(:assets_dir)].flatten.each do |dir|
system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' ./#{dir} #{user}@#{server}:#{cap.current_path}/#{cap.fetch(:local_assets_dir)}")
raise "server with role app is undefined" if server.nil?
Array(cap.fetch(:assets_dir)).each do |dir|
system("rsync -a --del -L -K -vv --progress --rsh='ssh -p #{port}' ./#{dir} #{user}@#{server}:#{cap.current_path}/#{Array(cap.fetch(:local_assets_dir)).join}")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it generates directories with comma (,) separator after slash (/)?

end
end

def to_string(cap)
[cap.fetch(:assets_dir)].flatten.join(" ")
end

private

def server
servers = Capistrano::Configuration.env.send(:servers)
servers.detect { |s| s.roles.include?(:app) }
end

def port
server.netssh_options[:port] || 22
end

def user
server.netssh_options[:user]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #97

end
end
10 changes: 6 additions & 4 deletions lib/capistrano-db-tasks/dbtasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
set :local_rails_env, ENV['RAILS_ENV'] || 'development' unless fetch(:local_rails_env)
set :rails_env, fetch(:stage) || 'production' unless fetch(:rails_env)
set :db_local_clean, false unless fetch(:db_local_clean)
set :assets_dir, 'system' unless fetch(:assets_dir)
set :local_assets_dir, 'public' unless fetch(:local_assets_dir)
set :assets_dir, %w(public/system) unless fetch(:assets_dir)
set :local_assets_dir, %w(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)
set :compressor, :gzip unless fetch(:compressor)
Expand Down Expand Up @@ -56,7 +56,8 @@
desc 'Synchronize your remote assets using local assets'
task :sync => 'capistrano_db_tasks:check_can_push' do
on roles(:app) do
puts "Assets directories: #{fetch(:assets_dir)}"
puts "Remote assets directories: #{self.shared_path}/#{fetch(:assets_dir).join(', ')}"
puts "Local assets directories: #{fetch(:local_assets_dir).join(', ')}"
if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your server assets with local assets")
Asset.local_to_remote(self)
end
Expand All @@ -68,7 +69,8 @@
desc 'Synchronize your local assets using remote assets'
task :sync do
on roles(:app) do
puts "Assets directories: #{fetch(:local_assets_dir)}"
puts "Remote assets directories: #{self.shared_path}/#{fetch(:assets_dir).join(', ')}"
puts "Local assets directories: #{fetch(:local_assets_dir).join(', ')}"
if fetch(:skip_data_sync_confirm) || Util.prompt("Are you sure you want to erase your local assets with server assets")
Asset.remote_to_local(self)
end
Expand Down