skip to Main Content

I have a directory under /public folder with the use of CarrierWave I store all my PDF files under this dir. But the problem is all the time I deploy new version of my Rails app this directory gets cleaned up and the all files are missing. This directory is was set under my uploader.

I also have a directory named "private" which I created manually in order to not to serve sensitive files globally on WEB. Those files also gone after new deployment process.

How can I prevent files from deleting on deploy process?

Thanks.

3

Answers


  1. Chosen as BEST ANSWER

    This problem I am facing with is happening because of capistrano. Every time I run cap production deploy command on my server, the capistrano deployment tool syncs every file with git repo. And the files added by end-users are not stored under my git repos of course, so capistrano overwriting the empty public folder from my repo to the server. Adding the path to :linked_dirs variable under deploy.rb solved my problem.

    Another approach could be using a directory which is somewhere else than your project root path (such as /home/files) to store all your files. By doing this you will be seperating your files from project and also prevent capistrano's overwriting problem.

    Hope this information will be useful for someone or future me :) ..


  2. I assume you are using some automation for deployment. Because if you are updating your code on server instance manually then you can preserve pre uploaded file, but using manually method to update code is not a good practice.

    So in automation deployment we generally follow this kind of flow.
    Whenever you deploy that create a new deploy version and set that as current version.

    Simply that means it’s creating a new directory and placing your rails project in it. Now the files you are storing inside the project directory are there in the previous version those are not gone if you are using any linux instance.(Only if you have setup that way to preserve last few versions to restore incase of new deploy is exploded)

    Clear till now?

    Not suppose you are not keeping any previous version, your files are gone forever.

    So it’s not a good idea to store any file under project repository.

    Best practice is to use bucket system like AWS bucket or Google cloud bucket, where we store all the uploaded file. If having bucket is not in budget, you can choose a different directory on linux server instance outside of project directory. But you have to setup all those upload paths and directory system to be used as bucket.

    Login or Signup to reply.
  3. When you deploy with capistrano, a new deploy(folder) is created from the repository.

    Any files not in the repository are not carried over.

    If you want to persist files in public, you need to create a directory in your server first and then create a symlink with capistrano inside public to that folder.

    Then have your carrierwave uploads saved to that location.

    During each deployment cap will symlink to that directory and your files will be there

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search