notapatch
notapatch

Reputation: 7173

Capistrano: What are the default linked_dirs in config/deploy.rb for?

When you capify a rails project you get a file config/deploy.rb which includes a commented out line which creates symlinks from the releases directory to the shared parts of the deployment.

# config/deploy.rb
#
# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"

Once uncommented what do they do?

Upvotes: 0

Views: 1622

Answers (1)

notapatch
notapatch

Reputation: 7173

TLDR: Uncomment linked_files line for faster Rails app deploys

Default Symlinks

Section written by maintainer of Capistrano (@mattbrictson)

  • public/assets – in a rolling deployment scenario, some customers may be referencing old asset versions (stylesheets, images, etc.) while other customers reference the new versions. Using a shared assets directory ensures that old versions and new versions reside in the same place and are accessible by the web server.

  • tmp/cache – The asset compilation step of deployment is really slow if it has to start from scratch. Using a shared tmp directory means the compilation step can reuse cached artifacts from past compilations, speeding up deployment.

  • tmp/{pids, sockets} – Used by Puma and Unicorn amongst others to manage server state. During a deploy, the server is pointing at an old version and then switches to the newly deployed version, potentially without a cold stop/start of the server processes. Keeping the pid, and socket files in a shared location facilitates this kind of zero downtime deployment.

  • public/system – Historically, uploaded file attachments are stored here. If this directory isn't shared, all uploaded files would effectively disappear every time a new version of the app is deployed.

    (My Edit: Mentioning Puma as it is now the default web server for rails)

Other Symlinks

What happens if you leave them commented out?

It doesn't break but it is much slower. I used my current project and ran a 'first' and then 'next' deploys. If you leave linked_dirs commented out then deploys can be as much as four times slower - the time increase due to not using cached data.

+---------------------+----------------+
|                     | Deploys (mins) |
+---------------------+----------------+
|                     | First |   Next |
+---------------------+----------------+
| Default linked_dirs |  8.10 |   0.50 |
+---------------------+----------------+
| No linked_dirs      |  8.20 |   4.30 |
+---------------------+----------------+

Summary

The default symlinks are required by most projects for a 'fast' deployment - remove the comment and Capistrano will handle the rest.


Upvotes: 2

Related Questions