Reputation: 2469
I am trying to upload my files and folder to my server using capistrano3. I want that folder to be shared amongst all the releases. For example I have a folder named media and it contains sub directories and files. I want that to be placed under shared directory created by Capistrano 3. I have seen this
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
Is there any way where I can upload all the files and subdirectories of media into shared directory.
Note :Basically I want my uploads to be untouched from capistrano3. Is there any way where I will just create the structure of the uploads folder and it will remain intact from my capistrano deploys. Thanks in advance.
Upvotes: 3
Views: 1068
Reputation: 2516
Add the media
dir into linked_dirs
, if you want that folder to be shared amongst all the releases.
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system media}
Then write a task like this:
namespace :deploy do
desc 'upload media files'
task :upload_media_files do
remote_path, local_path = "#{fetch(:deploy_to)}/shared/media", '/your/local/media/path'
on release_roles :app do
upload!(local_path, remote_path, recursive: true)
end
end
end
after 'deploy:check', 'deploy:upload_media_files'
It's a scp
command. According to the source code, the command would be: scp -t -r /remote/shared/media
.
If you don't want overwrite the existing files, you should use rsync
namespace :deploy do
desc 'upload media files'
task :upload_media_files do
remote_path, local_path = "#{fetch(:deploy_to)}/shared", '/your/local/media/path'
on release_roles :app do |server|
system("rsync -avzr #{local_path} #{fetch(:deployer)}@#{server.hostname}:#{remote_path}")
end
end
end
after 'deploy:check', 'deploy:upload_media_files'
Upvotes: 1