Why can't I write a sitemap to a temporary directory on a Heroku stack that has a read-only file system?

StackOverflow https://stackoverflow.com/questions/19656323

Question

I'm generating a sitemap for my website and temporarily saving it to the tmp folder to be then uploaded to my Amazon AWS account. I'm using the sitemap generator and fog gems to help me. So far I have this...

# In sitemap.rb

# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "http://mycoolapp.com/"

# pick a place safe to write the files
#SitemapGenerator::Sitemap.public_path = 'tmp/'

# store on S3 using Fog
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new

# inform the map cross-linking where to find the other maps
SitemapGenerator::Sitemap.sitemaps_host = "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com/"

# pick a namespace within your bucket to organize your maps
SitemapGenerator::Sitemap.sitemaps_path = '/'

SitemapGenerator::Sitemap.create do
  # Put links creation logic here.
  #

  add '/home'

  add '/about'

  add '/contact'
end

Whenever I run heroku run rake sitemap:create I receive the following error...

In '/app/tmp/':
511
rake aborted!
Read-only file system - /sitemap.xml.gz

I'm really at a loss as to why it's not working. I even went as far as making sure the tmp folder is created by running Rails.root.join('tmp') as an initializer. Any help in solving this would be greatly appreciated.

Was it helpful?

Solution

Don't Write to Root of Filesystem

Rake is quite clear about the source of the error:

rake aborted!
Read-only file system - /sitemap.xml.gz

This is telling you that your rake task is attempting to write the file to the root of the filesystem.

If you aren't using a a stack with ephemeral filesystem support like Celadon Cedar, you need to ensure you're writing to #{RAILS_ROOT}/tmp rather than the root of the filesystem. I haven't tested this myself, but you may be able to fixing this issue simply by pointing sitemaps_path to a writable directory. For example:

SitemapGenerator::Sitemap.sitemaps_path = '/app/tmp'

If that doesn't work, you'll have to track down where your gem or rake task is defining the root directory as the location for writing the sitemap.xml.gz file.

OTHER TIPS

So, I encountered the same problem trying to follow the fog instructions on both Heroku and for the sitemap_generator gem. I eventually switched to carrierwave and found it to be plug and play.

Check out the documentation here and let me know if you have questions as I just did this a couple months ago and likely have encountered any hurdles you may run in to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top