Rails make public,tmp and log folders outside the Root Folder - ruby-on-rails

Everytime that the carrierwave save a file, go to app/public folder, and the tmp and log folder get bigger overtime, so, is possible to make these folder outside the RailsApp?
change the Rails.root.join("") on the application.rb is the only way to do it?
on mina deploy is possible to create shared_path if created ouside have to symlink the path?

If you are deploying on a *nix box then symlinks are the way to go. I haven't used Mina, but if you deploy with Capistrano then you can script re-creation of whatever symlinks are needed fairly easily.
Just looking at the Mina page, you should be able to write a task to re-create your symlinks on deploy:
writing_your_own_tasks

Related

Folder contents are automatically deleted every time I deploy my Rails app

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.
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.
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 :) ..
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

How do I prevent mina from removing images uploaded on production server?

Im using mina to deploy my rails 4 app. When ever I mina deploy it clears out all the images that have been uploaded to my app. How do I stop this from happening? Thanks.
You need to ensure your uploaded assets end up in the shared directory, similar to the way your database.yml is done.
For example, our assets are all stored in public/system, so we have a line that looks like this:
set :shared_paths, %w[
files
log
private
public/system
tmp
]
Then, when you run invoke :'deploy:link_shared_paths' those directories will be linked to the root of your current directory, if they exist in the shared directory (you can create/populate them if they do not).

Capistrano ignore a file in /bin

After setup Delayed_job in development, here is the file delayed_job in /bin directory. When I deploy project to server, the file delayed_job just disappears.
Since you've found that the bin folder is sym-linked to a shared/bin folder (on deploy?) you'd need to scp your delayed_job executable into the shared/bin folder on server at this point. Or you may be able to do this on deploy just before the point in the cap deploy files where the symbolic link is made. Or perhaps just do it once now (and again in the future as needed) and then add the bin folder to your .gitignore. In fact I'd recommend this latter approach in case you start using spring with binstubs in development (as you wouldn't want these special executables being copied up to your server for production mode).

What is the importance of creating symlink & how to create it in EngineYard

My rails app is on engineyard server.
I need to create symlink for public folder.
How to create symlink on engineyard server?
I have no experience in deployment so i am very eager to know what is the importance of the symlink & for which folder it should be created?
Also currently i am using my staging environment what should i write in code or create a file so that it should create a symlink automatically when i deploy same code on production.
Thanks!
The proper way to create a symlink on EngineYard is to add deploy hooks. You want to add a /deploy directory to your project and add a before_symlink.rb file.
For example, if I put a configuration file in the shared directory (/data/my_app/shared/config), I can add a deploy hook to symlink this file in.
The contents of your file would look like this:
run "ln -nfs #{shared_path}/config/some_config.yml #{release_path}/config/some_config.yml"
The #{shared_path} variable points to your apps shared directory and #{release_path} is the current release being created as part of the deploy.
More info can be found at: http://docs.engineyard.com/use-deploy-hooks-with-engine-yard-cloud.html
The symlink should get automatically created whenever you deploy. Its purpose is to maintain the same path to your application across multiple deployments. When you deploy your application, you should create a symlink to the latest release, like this (on a Unix machine):
ln -s /application/releases/10102011011029/public /application/current
The first path is the REAL file or directory. The second path is the path and name of the symlink. Now when you point something to /application/current, it will be in the latest release.
If you use Capistrano, all of this is taken care of for you automatically whenever you deploy.

Keeping static files in server when deploying with Capistrano

I'm uploading files to my public/files folder of a Rails application on a constant basis through a web interface.
I don't want to keep these in source control since they go for almost 2 GBs, so every time I do a cap deploy it will save those files away in releases/ and replace the directory with the pristine copy stored in the repository.
I'm wondering what's the best way to keep those files in the server, in the current directory. Some of my ideas are:
Remove the directory from source control and replace it with a link to an external directory that's not managed by Capistrano.
Create a Capistrano task to copy the directory to /tmp before deploying and then copying it back to /public after it's done deploying.
Is there standard way to do this?
For the future record, this is the task I used to do it with a 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
You could make files a symlink to another directory on your machine, for examples the /shared directory at the same level as /current and /releases.
Check out capistrano manages the /log and /tmp directories.
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.

Resources