Capistrano 2: Capistranos shared/image folder is empty after running cap deploy - ruby-on-rails

I am on capistrano version 2.I have store users images in rails public/image folder,but on remote server i want to put images store inside public/image folder into shared/image folder.
My code for capistrano's deploy.rb file is as below.
set :shared_children, shared_children + %w{public/images}
after 'deploy:update_code', 'deploy:symlink_uploads'
namespace :deploy do
task :symlink_uploads do
run "ln -nfs /home/ubuntu/shared/image /home/ubuntu/current/public/image"
end
end
With the above code when i run cap deploy the symlink and code get updated successfully but my shared/images folder doesn't contain any image.
I check my svn repo and images are present in public/image folder then why those images are not coming in shared/image folder after running cap deploy command??
Please help
Thanks,

Related

Capistrano Deploy recipe to symlink Ruby on Rails folder public/images, not working

Every time I upload images it goes to public/images/upload then when I run a cap deploy they get erased since it creates a new current directory.
How do I instruct Capistrano to move the files in public/images/upload to the shared/images/ then symlink those images to the current(new) release ?
after "deploy:update_code", "deploy:symlink_shared"
after "deploy:restart", "deploy:cleanup"
namespace :deploy do
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
desc "Symlink shared configs and folders on each release."
task :symlink_shared do
run "ln -nfs #{shared_path}/images/upload #{release_path}/public/images/uploads"
end
end
Have try to expand shared directory list?
#deploy.rb
set :shared_children, shared_children + %w{public/images/uploads}
Edit : Remove you code and set shared_children variable.
After that make a cap deploy:setup so that updated your shared dir.

syncing folder after deploy

Everytime I deploy my redmine repository with capistrano my files are gone. I can see that capistrano symlinks the public directory, but not the {ROOT}/files directory.
I've read some articles on the internet but can't seem to get it work.
So I want is to keep my files in the {APPROOT/files} directory after a deploy
Many thanks for reading this.
You have two solutions:
1: Put your files directory in public/shared, which persists over the deployments.
2: Add a task in your capistrano recipe to create the symlink after each deploy:
task :create_files_symlink, :roles => :app do
run "ln -nfs #{shared_path}/files #{release_path}/files"
end
after 'deploy:update_code', 'create_files_symlink'

database.yml deployment best practice

I don't check my database.yml file into source control and I was wondering what others do/best practice for copying this file over to the server when deploying.
I use Capistrano for deployment.
Currently, I keep a shared folder called shared that lives outside of my deply_to dirs. I keep my database.yml and other config files there and have a hook in cap to cp those over during deployment. Here is my simple cap task for doing the copy:
after "deploy:update_code","deploy:config_symlink"
namespace :deploy do
task :config_symlink do
run "cp #{shared_path}/../../shared/database.yml #{release_path}/config/database.yml"
end
end
My deployment script was breaking using the after "deploy:update_code" hook because that step seemed to be trying to access the DB already. So I do:
before "deploy:assets:precompile", 'deploy:symlink_shared'
namespace :deploy do
task :symlink_shared do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
end
I've been beating my head on this one for quite some time, and have figured out an easier solution for Capistrano 3. Hope this helps those out there.
I couldn't for the life of me get the "run" or "execute" commands to work in my deploy.rb file. As it turns out, in Capistrano 3, you should put your database.yml underneath the deployment_directory/shared folder. Then, in your deployment.rb file, include the file in the linked_files variable and it automatically gets symlinked to the same path during deployment.
Here's an example:
For starters, I don't have database.yml checked into source control. My database.yml is located here on the production server:
var/www/myapp/shared/config/database.yml
In my deployment.rb, I've added this line
set :linked_files, %w{config/database.yml}
During the deployment, capistrano automatically symlinks the file to:
var/www/myapp/current/config/database.yml
Hope this helps others out there. I've really been beating my head on the wall on this today.

Apache2, Git, Capistrano & Rails - creating symlinks

I'm sort of stuck with adding symlinks to my app on the server. I currently have the following in .gitignore:
/non-public/system/uploads/*
I basically don't want Git to store the contents of the upload directory. So far so good.
On my server, inside my deploy.rb, I have the following:
namespace :customs do
task :symlink, :roles => :app do
run <<-CMD
ln -nfs #{shared_path}/system/uploads #{release_path}/non-public/system/uploads
CMD
end
end
after "deploy:symlink","customs:symlink"
after "deploy", "deploy:cleanup"
I want to create a symlink after each deployment for the uploads directory, but I keep getting a failed error message because the non-public/system/uploads directory doesn't exist in the git repository in the first place.
I've verified this by taking a look at the repository, and the structure /non-public/system/uploads doesn't exist because I have that set in .gitignore to ignore it.
I've looked at the Git wiki and it doesn't track directories, so I must be missing something. How do other developers symlink the uploads directory with their server?
What I'll usually do on my cap deploys is to create the directories, by doing a basic
set :deploy_to, "/this/dir"
run "mkdir -p #{deploy_to}/then/more/dirs"
after "deploy:symlink"
namespace :deploy....
....
....
then provide the run code to do some symlinks either on an after or whatever. This probably not optimal for all situations, but for the simple stuff it usually gets the job done.

Where do you put your app-config-files when deploying rails with capistrano and svn

I have two config-files
/app/config/database.yml
and
/app/config/userconfig.yml
i don't want to put the database credentials and userconfig in the svn-repository, so i have database.yml.dist and userconfig.yml.dist checked in.
What is the best way to get copys of the dist-files in the shared-directory when deploying the app for the first time?
For later deploys i'll link to them from /app/current/config
You should place your config files in
/path/to/deployed_app/shared
Then in a capistrano task, sym link to those files:
namespace :deploy do
task :symlink_shared do
run "ln -s #{shared_path}/database.yml #{release_path}/config/"
end
end
before "deploy:restart", "deploy:symlink_shared"
In Capistrano v3, you can use a task called deploy:symlink:shared.
Provide a list of files you placed in the shared directory, so Capistrano knows which files to symlink when the task is run. This is typically done in deploy.rb:
set :linked_files, %w{
app/config/database.yml
app/config/userconfig.yml
}
Related: Capistrano - How to put files in the shared folder?

Resources