Sitemap generation does not save file to storage - ruby-on-rails

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?

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.

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.

Related

rails 4: Errno::ENOENT (No such file or directory # rb_sysopen - /assets/

I've just deployed my app to heroku and I'm having a lot of trouble trying to read some assets.
I am trying to dynamically load some css from multiple files, then recompile them with some changes later. The line that keeps breaking is the first file load:
#css_asset_bootstrap = File.open(ActionController::Base.helpers.asset_path('bootstrap.css'), "r").read
which generates this error:
2015-04-07T23:30:50.098831+00:00 app[web.1]: Errno::ENOENT (No such file or directory # rb_sysopen - /assets/bootstrap-2d25733981c30e34bd9aa0fb75388f08.css):
I've tried a lot of things, including moving all my assets to aws cloudfront. Is there a way to get around this? Works perfectly in development environment.
Just to confirm a few things. I've successfully precompiled and uploaded the file. The file definately exists as I can see it in
heroku run bash
cd /public/assets/
I can also see it when I moved the assets to cloudfront.
Thanks.
edit 1:
Not sure if this is important information, but with the file on cloudfront, I can run heroku run bash to start a shell session on heroku. Then I can:
curl http://xxx.cloudfront.net/assets/bootstrap-2d25733981c30e34bd9aa0fb75388f08.css
And get the file ok. I was thinking maybe it was a permissions error but everything is set to public and it all seems to work from heroku to the aws server.
You're asking for the file from a relative path, which might not always work. Try absolute:
#css_asset_bootstrap = File.open(Rails.root + ActionController::Base.helpers.asset_path('bootstrap.css'), "r").read
Another possibly bigger problem is that Heroku has an ephemeral filesystem, and so any changes you write to it can be obliterated at any time when the dyno is culled.
In my case, using a virtual machine Rails.root give me this: '/home/vagrant/projects/.../my-nice-app' what is totally uncool.
I use instead request.url with give me: 'http://localhost:3000/' what it is exactly what I want.

Access or send a local file to Heroku

I've got a local .csv file with updated user data that I want to run a simple one-time script on in production (on Heroku, Rails 4 app). It's open source, so I can't just include the file in the repo without exposing the data. I'd like to be able to do it from the CLI but can't seem to figure it out.
There's probably a better solution, but I've been trying unsuccessfully to set the contents of the file (which isn't huge) to an environment variable on Heroku. My Bash skills are weak...
$ heroku config:set MY_CSV=<./my_local_csv_path.csv
didn't work -- it will not set anything. (running $ heroku config shows the env variable blank -- MY_CSV:).
Is there a better way to make this .csv file accessible to a script on Heroku? I suspect it's a similar problem to just accessing the local filesystem from the Heroku console.
I just did something similar to what you are doing where the user uploads a CSV for processing in my app. I am also hosting on heroku. Check out...
http://railscasts.com/episodes/396-importing-csv-and-excel
Basically let your model doing your processing for you that way you don't have to store any files on heroku.
I was able to do this with the heroku cli -e flag. It has to be a relatively small file. (all arguments combined are limited to 32kb)
It goes something like this:
# gzip and base64 encode the file
# (without the encoding, the gzip characters break this argument)
FILE_CONTENTS=$(cat /path/to/file.csv | gzip -fc | base64)
# Pass the variable from above to the dyno above.
heroku run -a APP_NAME -e "FILE_CONTENTS=\"$FILE_CONTENTS\"" rails c
Then in your console, you can get the csv by running:
csv_contents = ActiveSupport::Gzip.decompress(
Base64.decode64(
ENV['FILE_CONTENTS']
)
)

Rubber not starting rails server

I used complete_passenger_mysql recipe and successfully deployed the app.
Last command I saw was, '* 2013-11-10 03:36:59 executingcleanup''`, and then it automatically ended the session, without any error.
So, I guess, deployment was successful.
Now, when I try to browse my app, it just lists files/directories of my app's public directory ( 404.html, 422.html, 500.html , assets folder etc.)
So, I think apache is working fine. But rails server is not live. Do I need to do anything special for that ? I just did cap deploy to deploy the app.
please check the log file on server
deployed_path/current/log/production.log
or you can try this in console of the server
$ RAILS_ENV=production rails c
The db config will make issue if it's wrong.
config/database.yml

Sitemap_generator produces sitemap at unknown URL

I'm using the sitemap_generator gem to produce sitemaps for my site.
Producing a sitemap locally works fine, and I can access the sitemap at http://localhost:3000/sitemap1.xml.gz.
After deploying to Heroku and running
heroku run rake sitemap:refresh --app myapp-prod
I get this:
In /app/public/
+ sitemap1.xml.gz 254 links / 4.74 KB
+ sitemap_index.xml.gz 1 sitemaps / 231 Bytes
Sitemap stats: 254 links / 1 sitemaps / 0m06s
So far so good - however, when trying to access my sitemap at https://myapp.com/sitemap1.xml.gz, I get a 404 error. I've tried the following ways to resolve this but none have worked:
Call git add for the two locally generated xml files, push them to Heroku, and call heroku run rake sitemap:refresh --app myapp-prod to update the locally generated URLs with my production URLs. However the file is not being refreshed, it stays exactly the same as generated locally, even though the same message as above is being returned.
Producing the sitemap into a custom path, e.g. public/shared/. But the error persists when accessing https://myapp.com/shared/sitemap1.xml.gz.
All possible and impossible URL combinations, like https://myapp.com/public/sitemap1.xml.gz (which of course were never going to work, but wanted to leave no stone unturned)
Any ideas as to what could cause this behaviour, and where the sitemap might be stored?
After some further research I finally figured out what the issue was.
Since Heroku uses a read-only filesystem, the sitemaps can't be generated to the public directory. This is explained in more detail here:
https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
The solution that worked for me in the end was generating the sitemaps into my Amazon S3 storage, as described here.
What did you do about uploading your sitemap to Google Web Master tools because by default it wants the sitemap to live at http://www.yoursite.com/.....
I have my sitemap hosted in Amazon S3 and it's referenced in my robots.txt file but I need to tell Google Web Master Tools where to find it.
Any advice?

How to Move A Ruby On Rails Website To New Server

I have a Ruby on Rails website which I have successfully tar the apps directory which included the current folder ect. Which I Wget to transfer the files over. The server I have moved to is setup to run Ruby on Rails but is there anything else I need todo to get it running?
Any commands via SSH?
My new server setups is Ubuntu 11.04 running ISPConfig 3 as the server admin.
Current the file are in the correct location with the correct permissions and owners. But all I'm getting is the default ISPConfig page.
(This is the default index page of your website.
This file may be deleted or overwritten without any difficulty. This is produced by the file index.html in the web directory.)
If anyone can point me in the right direction that would be great.
Have you tried creating a symbolic link on the server to the application something like
cd ~/public_html;
ln -s ~/rails-test-application/public rails3
http://www.site5.com/blog/programming/ruby-rails/how-to-deploy-phusion-passenger-to-a-subdirectory-routing-errors-and-restarting/20090414/

Resources