Saving static files on the server during deployment using Capistrano

I upload files to my public/files folder of the Rails application on an ongoing basis through the web interface.

I do not want to keep them in the original control, since they go almost 2 GB, so every time I do cap deploy , it saves these files in releases/ and replaces the directory with the original copy in the repository.

I am wondering what is the best way to save these files on the server in the current directory. Some of my ideas are:

  • Remove the directory from the source control and replace it with a link to an external directory that is not managed by Capistrano.
  • Create a Capistrano task to copy the directory to / tmp before deployment, and then copy it back to / public after it is deployed.

Is there a standard way to do this?

+6
ruby-on-rails release-management capistrano
source share
3 answers

You can make files symbolic links to another directory on your computer, for example, the / shared directory at the same level as / current and / releases.

Verify that capistrano manages the / log and / tmp directories.

+6
source share

For a future post, this is the task I did with the shared directory:

 task :link_shared_directories do run "ln -s #{shared_path}/files #{release_path}/public/files" end after "deploy:update_code", :link_shared_directories 
+7
source share

Now we can simply use: linked_files in deploy.rb:

 set :linked_files, %w{config/database.yml} 

In this case, the file [target_dir] /shared/config/database.yml must exist on the server.

+2
source share

All Articles