-1

This question is in reference to the solution posted in the following the link:

Paperclip, set path outside of rails root folder

The answer provided mentions creating a virtual folder, but there's no explanation on how to do it. I have a Rails app via Dokku, and I have a mounted digital ocean block storage located in a folder on the root. "/mnt/volume-sgp1-01/".

So the questions is how to make this "virtual folder" that points to that specific directory which is outside of the rails app?

Also, how to configure a custom GET that will make all the files within it accessible via xyz.com/mnt/volume-sgp1-01/...etc.

UPDATE: I am referring to a "virtual folder" i.e. a folder that is not a real folder, but recognized as one in a Rails app, that points to an existing folder outside of Rails root folder.

As for the purpose of the folder, it is to provide a location in the server for permanent storage that is not affected by anything in the Rails root folder, as whenever I redeploy rails, the files in the Rails folder are replaced.

[Note: I cannot use Amazon AWS as China often blocks their servers. So, I am using Digital Ocean Block Storage as my solution.]

Community
  • 1
  • 1
  • What do you try to achieve, why do you need that folder? I think the name *virtual* folder in the answer is misleading. There is nothing special about the folder, it is a normal simple folder (in that case outside of the application folder). Just create a ordinary folder on your server. – spickermann May 08 '17 at 06:00
  • I am referring to a "virtual folder" i.e. a folder that is not a real folder, but recognized as one in a Rails app, that points to an existing folder outside of Rails root folder. It is referenced in the solution given in the link provided, and from your comment, it seems clear you did not click on the link to see what I was talking about. – user7978648 May 10 '17 at 05:13

2 Answers2

0

You can use dokku's persistent-storage plugin in order to mount the volume into the docker container.

Jose Diaz-Gonzalez
  • 2,066
  • 1
  • 15
  • 19
0

I have not used the paperclip gem but I used the carrierwave gem and I encountered the problem of needing a persistent storage as well. So I think maybe my solution can be applied to yours as well. I also assumed that you are using Digital Ocean droplet but I think it should work for any server as well. As Jose Diaz-Gonzalez have mentioned, you need to make use of dokku's persistent-storage plugin.

First you have to select a folder you want to store your files in. Dokku documentation recommends the folder /var/lib/dokku/data/storage/. So you can SSH into your Droplet, use mkdir to create a folder. Then run chown to give the dokku user permission to write to that folder. The path to the folder should be on the left hand side of the command.

cd /var/lib/dokku/data/storage
mkdir paperclip_storage
chown -R 32767:32767 paperclip_storage

When you deploy your rails app to dokku, the ruby build pack that dokku uses will place your application in a /app folder. So lets say for my gem CarrierWave, the file upload location is to uploads/photos/, the full path of the upload in my dokku container will be /app/public/uploads/photos. This path should be on the right hand side of the command.

!!Replace /app/public/paper/clip/upload with the proper folder to your paperclip upload.!!

dokku storage:mount album /var/lib/dokku/data/storage/paperclip_storage:/app/public/paper/clip/upload

After that you need to rebuild your application

dokku ps:rebuild app-name

Now you can ssh into your upload folder, /var/lib/dokku/data/storage/paperclip_storage and try uploading a file using your paperclip gem. If the link was successful, the files should be shown immediately when you check with the ls command.

cd /var/lib/dokku/data/storage/paperclip_storage
ls