Sitemap generation does not save file to storage

1.3k views Asked by At

I'm just getting a sitemap going with the rails gem and am having trouble generating a sitemap in production.

Running the rake command: rake sitemap:refresh in development creates the sitemap.xml.gz file in the public folder. I navigate to localhost:3000/sitemap.xml.gz and get it downloads the zipped file.

When I run it in production (Heroku-like command line with Dokku on a Digital Ocean VM) I get:

+ sitemap.xml.gz                                           6 links /  450 Bytes
Sitemap stats: 6 links / 1 sitemaps / 0m00s

Pinging with URL 'https://www.myapp.com/sitemap.xml.gz':
  Successful ping of Google
  Successful ping of Bing

It appears the file has been created, so I navigate to www.myapp.com/sitemap.xml.gz and get a 404 response.

Server say:

ActionController::RoutingError (No route matches [GET] "/sitemap.xml.gz"):

It appears that this request is hitting the Rails stack when it should be served by Nginx. I just checked to see if the file exists:

FileTest.exists?("public/sitemap.xml.gz")

It returns false so it seems like the sitemap is not actually saved on file. Is there a possibility my file system is read-only right now? How could I test that?

2

There are 2 answers

0
settheline On BEST ANSWER

I believe this is a dokku related "issue". Dokku uses Heroku buildpacks, and this yields a read-only file system like on Heroku.

I'd be curious to know if there's a way to modify that behavior in Dokku (seems unlikely if using Heroku buildpacks), but that's a bit out of my league.

I think the best solution to this problem is the same as on Heroku - using Amazon S3.

The sitemap_generator gem has docs on how to set this up.

1
Daniel Leong On

With the new dokku docker-options plugin, you could append persistent storage/volume from your host machine into you container.

First create a local directory in your host machine.

mkdir <path/to/dir>

Then add the following docker-options in dokku

dokku docker-options:add <app> deploy,run -v <path/to/host/dir>:<path/to/container/public/sub/dir>:rw

On your config/sitemap.rb file, add the following lines

SitemapGenerator::Sitemap.public_path = 'public/sitemap/'
SitemapGenerator::Sitemap.sitemaps_path = 'sitemap/'

The sitemap:refresh rake task should write into the sitemap sub folder within the public folder.

This would also allow sitemap_generator to ping the search engine with the right address to your sitemap.xml.gz file.

Feel free to give this a try.