3

Deployed rails app with Cloud 66, to digitalocean.com. Everything works fine, except some permission errors when trying to upload images.

 Errno::EACCES (Permission denied - /var/deploy/anabol/web_head/releases/20130608104347/public/uploads/tmp): 

image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base
...
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
...
end

There is a description, how to solve the problem here: https://www.cloud66.com/help/permission_denied_errors

I changed the store_dir path to:

  def store_dir
    "#{Rails.root}/tmp/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

But it didn't help. I still get this error:

 » 13:49:25.696 Errno::EACCES (Permission denied - /var/deploy/anabol/web_head/releases/20130608114659/public/uploads/tmp): 

Am I missing something?

Edit:

Upload works with this part in image_uploader.rb:

  def cache_dir
    # should return path to cache dir
    Rails.root.join 'tmp/uploads/cache'
  end

  def store_dir
    "#{Rails.root}/tmp/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

But now I get:

ActionController::RoutingError (No route matches [GET] "/var/deploy/anabol/web_head/releases/20130608164223/tmp/uploads/profile/image/3/thumb_Screenshot_from_2013-06-05_17_27_54.png"):

On the view, only the images path is displayed.

John Beynon
  • 37,398
  • 8
  • 88
  • 97
Barna Kovacs
  • 1,226
  • 1
  • 14
  • 35

2 Answers2

7

There are ways to get this working, on hosts where you can upload files. Two ways are described here, but had some errors, which are now corrected.: https://www.cloud66.com/help/permission_denied_errors

A working example for a deploy hook, using carrierwave for image-upload:

#! /bin/bash
#load environment variables
source /var/.cloud66_env
#assign desired permissions
sudo chmod 0777 -R $RAILS_STACK_PATH/public/uploads

And the best solution

(this way you will don't loose the images when redeploy): use this in your xy_uploader.rb:

  def store_dir
    "system/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
Barna Kovacs
  • 1,226
  • 1
  • 14
  • 35
  • If anyone needs it, this is what my deploy_hooks.yml file command looks like for permissions management: `command: chown -R nginx:app_writers $RAILS_STACK_PATH/public/uploads && chmod -R 775 $RAILS_STACK_PATH/public/uploads && sudo chmod -R g+s $RAILS_STACK_PATH/public/uploads` – mindtonic Jan 12 '17 at 20:43
1

I checked out Cloud66:

This user (nginx) does not have elevated permissions, and does not have write access to your filesystem (except explicitly to the /tmp and the $RAILS_STACK_PATH/tmp folders)

This means you can't upload files to be used later to Cloud66 -- you'll want to configure Fog to upload to S3 (or any of fog's cloud file providers).

This is pretty standard among cloud providers. Tutorials:

Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • 2
    I use digitalocean.com, with 30gb ssd, I'm sure I can upload. Cloud66 only deploys my app there, and their deployment config prevents me to upload, I think. What do you think? – Barna Kovacs Jun 08 '13 at 13:08