views:

413

answers:

2

I have a Gallery-style app that has been already deployed. My local version has many photos that I use only for local testing, and I absolutely do NOT want them to overwrite my real photos which are online.

I also have a git repository which only tracks my code and ignore photos.

When I type cap deploy:migrations does it use my git repository or not? i.e. does Capistrano will overwrite my online photos with local ones, or it will ignore them because git ignore them?

+6  A: 

Simply put your photos in capistrano's shared folder and symlink it. To automate it, write a capistrano recipe like:

namespace :deploy do

  after "deploy:setup", "deploy:pictures:setup"
  after "deploy:symlink", "deploy:pictures:symlink"

  namespace :pictures do
    desc "Create the pictures dir in shared path."
    task :setup do
      run "cd #{shared_path}; mkdir pictures"
    end

    desc "Link pictures from shared to common."
    task :symlink do
      run "cd #{current_path}/public; rm -rf pictures; ln -s #{shared_path}/pictures ."
    end

  end
end

This recipe will create a pictures folder in capistranos shared folder on 'cap deploy:setup' and symlink it on each 'cap deploy'.

So if you already have created the pictures folder on the server and added some pictures, you may migrate it before run the command:

cd yourapp
mv current/public/pictures shared
ln -s shared/pictures current/public/pictures

I use another recipe for sync the contents of shared folders over several machines, you can get it from GitHub

Netzpirat
So you are saying that Capistrano will use local files instead of Git master to update my live application?
collimarco
Exactly, but it doesn't matter if there are already some files within the git repo for the shared folder. This folder will be removed on deploy and symlinked with the shared one. Depending on the usage of the shared folder, I often keep some example files checked in that will be removed on deploy.
Netzpirat
Thanks! But you should have said "No, it is the opposite" instead of "exactly" ;) In fact you said that it uses Git and NOT local files...
collimarco
+1  A: 

When deploying, capistrano will checkout a fresh copy from your Version Control System of choice. It does not care about your local files.

tliff