Search code examples
deploymentcapistranoweb-deployment

Capistrano & syncing static files to remote location


As part of a Capistrano deployment I want to sync my CSS, JS and images to a remote location (Amazon S3). However, I'm worried that if the Capistrano deployment fails, this will leave me with updated CSS, JS and images.. but the main application code will still be on the previous release.

I'm wondering if there is a way with Capistrano to only trigger a task if the deployment is marked as complete and current folder is pointing at the newly deployed release folder? This would at least allow me to only update the static files once I know the main source has been updated..

Of course, I would still have the problem of - what if the sync with S3 fails? But I think this way would have the better balance in terms of points of failure.


Solution

  • Capistrano has a bunch of hooks you can use during the deploy.

    http://capistranorb.com/documentation/getting-started/flow/

    You probably want to use the 'deploy:finished' hook for your use case, for example.

    after 'deploy:finished', 'deploy:sync_assets_to_S3'
    

    Then create a cap task to perform your file uploads.