Search code examples
ruby-on-railsrubycapistranocapistrano3

How to set subdirectories in Capistrano?


I have a rails app and I'm using Capistrano as the deploy gem.

My deploy.rb file has this:

set :application, 'appname'
set :repo_url, '[email protected]:someone/some_app.git'
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'secrets.json')
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads', 'public/assets/')
set :rvm_ruby_version, '2.2.2@deploy'

The problem is that not all of my assets are inside the app folder, some are in the public folder since I'm using a lot of template code. Inside the public/assets folder are a lot of sub directories necessary for the app to run. Putting 'public/assets' in the linked_dirs option only symlinks that specific folder, and manually writing all sub directories inside it seems like a terrible solution. How do I tell Capistrano to include everything (even sub directories) inside a folder in the deploy?


Solution

  • Good question. I see a couple of possibilities, all ways to work around the core issue that you must define every single specific folder.

    1. Check to see whether you really need public/assets to be shared. The downside of not sharing them is that when you deploy a new version of the app with changed assets, the old assets disappear. For a public facing app, this may be a problem. If it is an internal app, or if you have an Akamai/Cloudflare style CDN in front of it caching the old files, it may not be.
    2. Move the non-autogenerated assets to a different folder, perhaps public/static_assets. Those will also be accessible.
    3. The flip side is to move the Sprockets managed assets to a different folder.
    4. Figure out how to make Sprockets actually manage this code anyway so it all ends up in public/assets.

    There are probably other ways, but hopefully this either offers a solution or gives you a starting point from which to go.