I have upgraded to Capistrano 3 and successfully deployed several Rails apps on a new server.
Previously with Capistrano 2 deployments the Rails logs magically went to /myapp/shared/log/production.log
With my Cap3 deployments the logs are in the app folder myapp/current/log/production.log
Is this intentional or have I missed setting something up?
Is there some special way to set it up so that they go to /shared/log ?
Just found the answer.
You need to uncomment the following line in deploy.rb
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
Related
I'm using Capistrano to deploy my Rails 7.0.2 app with Ruby 3.1.1, when I run cap production deploy and then when Capistrano runs:
deploy:assets:precompile
$HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
I receive the following error :
ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `bin/rails credentials:edit`
deploy.rb:
# config valid for current version and patch releases of Capistrano
lock '~> 3.17.0'
set :application, 'app'
set :repo_url, 'git#github.com:foo/app.git'
# Deploy to the user's home directory
set :deploy_to, "/#{fetch :application}"
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
# Only keep the last 5 re
The problem is that I already have the secret_key_base defined in my productions encrypted credentials file so I should not be getting this error. I also tried putting the secret_key_base as a .rbenv-vars file and still got the same error. How do I properly use a secret_key_base in a production environment with Rails and Capistrano? Thanks again!
Can you try adding to the deploy.rb file:
append :linked_files, 'config/credentials/production.key',
And copy the production.key (the one that is in charge of decrypting the production credentials) to the shared folder in your server, something like /var/www/{proyect_name}/shared/config/credentials/production.key you can leave the production.yml.enc in your GitHub.
And check that you have set the secret_key_base in your production secret keys with EDITOR=nano rails credentials:edit -e production
Added the following to config/environments/production:
config.require_master_key = true
run EDITOR=vi rails credentials:edit --environment=production
Save the production key generated to your server # app/config/credentials/production.key
Changed set :deploy_to, "/#{fetch :application}" to set :deploy_to, "~/#{fetch :application}"
Copy master.key on your remote machine at project_folder/shared/config and it should be ok.
EDIT:
wait a second, add --> append :linked_files, "config/master.key"
after set :deploy_to, "/#{fetch :application}"
Im having a problem with Capistrano 3.X
So basically my app has public folder, where some users can upload their folders. it can be public/a public/b and so on. When i set linked dirs like that
set :linked_dirs, %w{ log tmp/pids tmp/cache tmp/sockets vendor/bundle public }
I'm getting error:
I, [2016-01-23T05:09:48.343707 #27926] INFO -- : Writing /home/deploy/blabla/
releases/20160123100938/public/assets/bootstrap/glyphicons-halflings-regular-
fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2 rake
aborted! Errno::EEXIST: File exists # dir_s_mkdir -
/home/deploy/blabla/releases/20160123100938/public/assets
/home/deploy/blabla/shared/bundle/ruby/2.2.0/gems/sprockets-
3.5.2/lib/sprockets/asset.rb:163:in `write_to'
/home/deploy/blabla/shared/bundle/ruby/2.2.0/gems/sprockets-3.5.2/
lib/sprockets/manifest.rb:192:in `block (2 levels) in compile'
/home/deploy/blabla/shared/bundle/ruby/2.2.0/gems/concurrent-ruby-
1.0.0/lib/concurrent/executor/safe_task_executor.rb:24:in `call'
I tried to remove assets folder, create it manually. I don't know what to do next.
You can put users uploaded folders inside another folder like uploaded_folders and then
set :linked_dirs, %w{ log tmp/pids tmp/cache tmp/sockets vendor/bundle public/uploaded_folders public/system }
This should fix it
I have a folder public/recipes with recipes inside of this folder.
However after deployment via remote_cache this folder and recipes are removed/deleted.
I do not want that capistrano remove/delete this folder and these recipes.
How I can get it?
If you are using Capistrano 3 then just specify public/recipes directory in linked_dirs variable:
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/uploads public/recipes}
It will set link between your directory and shared/public/recipes.
For Capistrano 2 you should set link "manually" in deploy.rb use ln command i.e. use something like this:
task :configure_symlinks, :roles => :web do
run "ln -nfs #{shared_path}/public/recipes #{current_release}/public/recipes"
end
after "deploy:update_code", "configure_symlinks"
If you don't want a symlink, you will probably need something like https://github.com/capistrano/copy-files.
However, I highly recommend that you use linked dirs as ethyl.bradtke suggests. That is the best way to handle this.
I'm using Capistrano 3 for deployment with my Rails app. The problem is that every time I deploy my app to the server the ./log/production.log file is reset. I've heard it's possible to have the production.log file into the shared folder and being appended at each deployment.
I thought this was made by default by Capistrano but apparently not for me :(
Any thoughts?
Thanks!
In your config/deploy.rb you need a line similar to this:
set :linked_dirs, %w{log public/system}
This will tell capistrano to symlink log and public/system into the shared directory on deployment.
I'm using rails 3.2 with asset and carrierwave for upload some images, they store in /public/uploads/photo/.....
but when I do a cap:deploy (with capistrano) my current directory application doesn't contain the files I uploaded, because capistrano make a new version ....
=== Update ===
After all I use this :
inside :deploy namespace
task :symlink_uploads do
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
and after:
after 'deploy:update_code', 'deploy:symlink_uploads'
=== Re Update ===
The solution of #tristanm is the best way to solve this.
How about this:
# config/deploy.rb
set :shared_children, shared_children + %w{public/uploads}
:shared_children defaults to %w(public/system log tmp/pids) so we're just expanding this list.
EDIT:
Don't forget to run cap deploy:setup after changing :shared_children so that the new targets are created under shared.
EDIT Capistrano 3:
Capistrano 3 uses the linked_dirs setting and doesn't specify public/system as a default anymore.
set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads}
With Capistrano 3 and without needing to redeploy.
Like #tristanm mentioned add this to your config/deploy.rb
# config/deploy.rb
set :linked_dirs, fetch(:linked_dirs) + %w{public/uploads}
To have capistrano create shared/public/uploads
cap deploy:check:linked_dirs
Now cap can create the symlink
cap deploy:symlink:shared
Finally, if you have backups of the uploads you can put them in shared/public/uploads/ and they should work without needing to redeploy.
Capistrano creates new directory for every deploy.
There are some exceptions to it. For example, the log files are shared between the deployment directories because they are just symlinks. You have to create a symlink for public/uploads as well.
Here is the command:
run <<-CMD
rm -rf #{latest_release}/public/uploads &&
ln -s #{shared_path}/uploads #{latest_release}/public/uploads
CMD
Go to your app server shared folder and create an uploads directory.
mkdir uploads
In your deploy.rb file insert these codes under deploy namespace
task :symlink_uploads do
run "rm -rf #{latest_release}/public/uploads && ln -nfs #{shared_path}/uploads #{latest_release}/public/uploads"
end
after 'deploy:update_code', 'deploy:symlink_uploads'
Now delete the old files present already as they won't work. Upload a new file and cap deploy your app again. It should work now.
Using Capistrano 3, I just added this line to my config/deploy.rb
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
Then, run:
$ cap production deploy