rails-latex gem: ActionView::Template::Error (rails-latex failed ...) with Heroku - ruby-on-rails

Rails Version: Rails 6.0.2.1
Ruby Version: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
When I try to generate a PDF with the gem rails-latex in Heroku, I get the following error: ActionView::Template::Error rails-latex failed (Full error message below).
This error does not arise locally.
What I tried
There is already a stackoverflow-question with the same problem: Debugging rails-latex gem on Heroku | ActionView::Template::Error rails-latex failed
#blackbrokkoli writes:
If you have a similar problem, I recommend deleting all tex
dependencies, get a MWE and then slowly add them back in to identify
the evildoers.
But I don't know what he means with "MWE" and I doubt that I am able to "identify the evildoers" by myself.
There is a thread called "Deploying on Heroku" suggesting that one needs to install a buildpack.
I tried to follow the instructions for the "Multipacks"-option.
The command cat .buildpacks returns
cat: .buildpacks: No such file or directory
The command heroku config:add BUILDPACK_URL=git://github.com/ddollar/heroku-buildpack-multi.git returns:
Setting BUILDPACK_URL and restarting
BUILDPACK_URL: git://github.com/ddollar/heroku-buildpack-multi.git
But after that, I don't know how to proceed further.
I tried to figure out how to add buildpacks with Heroku with the heroku buildpacks:add command. But I couldn't figure out, how I can add a third-party buildpack with this command.
Does anyone have any suggestions on how to fix this error?
Error message in heroku logs
2020-02-07T05:50:55.909360+00:00 app[web.1]: I, [2020-02-07T05:50:55.909264 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Started GET "/articles/2.pdf" for 87.245.109.31 at 2020-
02-07 05:50:55 +0000
2020-02-07T05:50:55.910207+00:00 app[web.1]: I, [2020-02-07T05:50:55.910130 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Processing by ArticlesController#show as PDF
2020-02-07T05:50:55.910257+00:00 app[web.1]: I, [2020-02-07T05:50:55.910202 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Parameters: {"id"=>"2"}
2020-02-07T05:50:55.913042+00:00 app[web.1]: D, [2020-02-07T05:50:55.912964 #4] DEBUG -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Article Load (1.1ms) SELECT "articles".* FROM "articl
es" WHERE "articles"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
2020-02-07T05:50:55.914866+00:00 app[web.1]: I, [2020-02-07T05:50:55.914789 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Rendering articles/show.pdf.erb within layouts/applica
tion
2020-02-07T05:50:55.915357+00:00 app[web.1]: I, [2020-02-07T05:50:55.915290 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Rendered articles/show.pdf.erb within layouts/applicat
ion (Duration: 0.4ms | Allocations: 101)
2020-02-07T05:50:55.916214+00:00 app[web.1]: I, [2020-02-07T05:50:55.916141 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Running 'pdflatex -halt-on-error -shell-escape -interact
ion=batchmode input' in /app/tmp/rails-latex/4-521112460259582216 1 times...
2020-02-07T05:50:55.923855+00:00 app[web.1]: I, [2020-02-07T05:50:55.923739 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Running 'bibtex input' in /app/tmp/rails-latex/4-5211124
60259582216 1 times...
2020-02-07T05:50:55.929983+00:00 app[web.1]: I, [2020-02-07T05:50:55.929846 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Running 'pdflatex -halt-on-error -shell-escape -interact
ion=batchmode input' in /app/tmp/rails-latex/4-521112460259582216 2 times...
2020-02-07T05:50:55.936216+00:00 app[web.1]: I, [2020-02-07T05:50:55.936104 #4] INFO -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] Completed 500 Internal Server Error in 26ms (ActiveRecor
d: 1.1ms | Allocations: 1610)
2020-02-07T05:50:55.937843+00:00 app[web.1]: F, [2020-02-07T05:50:55.937756 #4] FATAL -- : [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3]
2020-02-07T05:50:55.937845+00:00 app[web.1]: [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] ActionView::Template::Error (rails-latex failed: See /app/tmp/rails-latex/4-521112460259582216/input.l
og for details):
2020-02-07T05:50:55.937845+00:00 app[web.1]: [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] 15:
2020-02-07T05:50:55.937846+00:00 app[web.1]: [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] 16: \end{document}
2020-02-07T05:50:55.937846+00:00 app[web.1]: [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3]
2020-02-07T05:50:55.937847+00:00 app[web.1]: [1c4e2355-293c-4cb1-b591-b97e4ba4ecf3] app/views/layouts/application.pdf.erbtex:18
#Syed Asim Hashmi suggested to use this command to install a third-party buildpack:
heroku buildpacks:add git://github.com/Thermondo/heroku-buildpack-tex.git#VERSION_NUMBER
This is what I get:
heroku buildpacks:add git://github.com/Thermondo/heroku-buildpack-te
x.git#VERSION_NUMBER
› Error: Could not find the buildpack:
› git://github.com/Thermondo/heroku-buildpack-tex.git#VERSION_NUMB
› ER. To specify a buildpack, please format it like the following:
› namespace/name (e.g. heroku/ruby). Also names can only contain
› letters, numbers, '_', and '-'.
I tried to add the buildpack via the settings on the heroku website:
I restarted heroku with heroku restart
but I receive the same error message.

rails-latex uses third-party buildpack
https://github.com/Thermondo/heroku-buildpack-tex
You can install it by running this command:
heroku buildpacks:add git://github.com/Thermondo/heroku-buildpack-tex.git#VERSION_NUMBER
Alternatively you can also add the above git repository into your buildpacks by going to your dyno settings.
One thing to keep in mind is that The Heroku filesystem is ephemeral -
that means that any changes to the filesystem whilst the dyno is
running only last until that dyno is shut down or restarted
You can find more information regarding third party buildpacks here
More information regarding heroku filesystem here
Hope it helps.

Related

Rails/net-ssh - ssh to remote server with private key in Heroku

I'm trying to ssh to a remote server using a private key through Heroku.
I'm using this gem https://github.com/net-ssh/net-ssh to complete the request and have everything working fine locally.
The reason why everything works fine locally is because I have the private key saved with the passphrase entered. When I deploy to Heroku, I'm unable to use the agent like I have it on my PC and so the connection fails.
I have changed the settings on the connection using net-ssh to not use the agent but still can't get it functioning.
Worst case I will have to create a separate API call in php hosted elsewhere to complete this connection but I'm hoping I can make it work through my rails app in Heroku.
This is what I'm currently doing:
options = {}
options[:key_data] = ENV['LANDING_PAGE_SSH_KEY']
options[:keys_only] = true
options[:use_agent] = false
options[:verbose] = :debug
options[:port] = '18765'
options[:passphrase] = ENV['SSH_KEY_PASSPHRASE']
Net::SSH.start(ENV['SERVER_HOSTNAME'], ENV['SERVER_USERNAME'], options) do |ssh|
end
I've entered the private key in a global variable and everything else that I would need. This also works locally without using the agent but fails on Heroku with this message:
[2017-07-21T19:20:35.506794 #4] DEBUG -- socket[383b2bc]: read 52 bytes
2017-07-21T19:20:35.507070+00:00 app[web.1]: D, [2017-07-21T19:20:35.507016 #4] DEBUG -- socket[383b2bc]: received packet nr 3 type 6 len 28
2017-07-21T19:20:35.507262+00:00 app[web.1]: D, [2017-07-21T19:20:35.507210 #4] DEBUG -- net.ssh.authentication.session[3fd3f610f914]: trying none
2017-07-21T19:20:35.507477+00:00 app[web.1]: D, [2017-07-21T19:20:35.507412 #4] DEBUG -- socket[383b2bc]: queueing packet nr 4 type 50 len 44
2017-07-21T19:20:35.507603+00:00 app[web.1]: D, [2017-07-21T19:20:35.507553 #4] DEBUG -- socket[383b2bc]: sent 68 bytes
2017-07-21T19:20:35.536336+00:00 app[web.1]: D, [2017-07-21T19:20:35.536194 #4] DEBUG -- socket[383b2bc]: read 52 bytes
2017-07-21T19:20:35.536472+00:00 app[web.1]: D, [2017-07-21T19:20:35.536422 #4] DEBUG -- socket[383b2bc]: received packet nr 4 type 51 len 28
2017-07-21T19:20:35.536573+00:00 app[web.1]: D, [2017-07-21T19:20:35.536526 #4] DEBUG -- net.ssh.authentication.session[3fd3f610f914]: allowed methods: publickey
2017-07-21T19:20:35.536657+00:00 app[web.1]: D, [2017-07-21T19:20:35.536612 #4] DEBUG -- net.ssh.authentication.methods.none[3fd3f6103e84]: none failed
2017-07-21T19:20:35.536749+00:00 app[web.1]: D, [2017-07-21T19:20:35.536703 #4] DEBUG -- net.ssh.authentication.session[3fd3f610f914]: trying publickey
2017-07-21T19:20:35.537566+00:00 app[web.1]: Enter passphrase for <key in memory>:Completed 500 Internal Server Error in 337ms (ActiveRecord: 1.4ms)
2017-07-21T19:20:35.538404+00:00 app[web.1]:
2017-07-21T19:20:35.538406+00:00 app[web.1]: Errno::ENOTTY (Inappropriate ioctl for device):
Any suggestions?
In my case I needed to add the private key to the server's ssh setup
ssh-add ~/.ssh/path-to-private-key
and it started working.

Heroku devise/facebook oauth glitch with identical source code

I try to solve problems myself, but this one has got the best of me and I'm on the verge of head-butting my desk.
Here's what I do:
I test the production oAuth, all works perfectly as it has for months
I use heroku git:clone -a myapp to get the source code locally
I make no changes whatsoever, I simply re-commit and push back up to Heroku
I test the production oAuth again, it doesn't work
I keep having to use heroku rollback, so that I can go back to the working version. I thought that since the source code is identical, maybe a gem I'm using has updated and broken something. But I checked the oAuth gems and none of them have changed for a while.
Here's my log when it doesn't work:
2015-10-25T15:20:47.802222+00:00 app[web.1]: Started GET "/humans/auth/facebook?ip=123&loc=8&mac=123&var=11" for 162.158.38.218 at 2015-10-25 15:20:47 +0000
2015-10-25T15:20:47.804207+00:00 app[web.1]: I, [2015-10-25T15:20:47.804128 #3] INFO -- omniauth: (facebook) Request phase initiated.
2015-10-25T15:20:47.871762+00:00 heroku[router]: at=info method=GET path="/humans/auth/facebook?ip=123&loc=8&mac=123&var=11" host=yourhotspot.net request_id=9804b0a9-a190-4881-a64f-ff222aa216e3 fwd="82.34.163.154,162.158.38.218" dyno=web.1 connect=0ms service=75ms status=302 bytes=1916
2015-10-25T15:20:48.181538+00:00 app[web.1]: Started GET "/humans/auth/facebook/callback?ip=123&loc=8&mac=123&var=11&code=AQCqfCPHQUM_YzgXPJSUniVKumx6ii2fsQtgEw9Bc3B9MFwNyKmnRtdqZxCRWSl1bDxdZKIAgU_M_-DQGVedt7FRYsm8DxA7gPA8bky86H-jlaCaFQa1Gc2BRLxtuzEUPKtu3UPRmKjUpXBuJI0nHOmG4IF3WWjwRk1jtfvWvgHmEH5Q-h-JjoEgiTC5uqK6XN2E48hKqxYcqBVs-pDMLMp74WRmRCXN_R_R_RuAjyyj_9-GdNHhZ6uajuri_41AN5V8W9UqWPmtPHznL7ztNLzS9dDj7S9e25bINXUMneHVVNHwGpp5PWZULsN_hwJueUU4SFZlNgzrnupacHAXF9kU&state=1e8f5be4b10b96baedd6aab3cd2eb125b150e100c5a2c7bb" for 162.158.38.218 at 2015-10-25 15:20:48 +0000
2015-10-25T15:20:48.183305+00:00 app[web.1]: I, [2015-10-25T15:20:48.183218 #3] INFO -- omniauth: (facebook) Callback phase initiated.
2015-10-25T15:20:48.733053+00:00 app[web.1]: {"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100,"fbtrace_id":"B8bmqcG7i6M"}}
2015-10-25T15:20:48.733049+00:00 app[web.1]: E, [2015-10-25T15:20:48.732948 #3] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials: OAuth2::Error, :
2015-10-25T15:20:48.735557+00:00 app[web.1]: Parameters: {"ip"=>"123", "loc"=>"8", "mac"=>"123", "var"=>"11", "code"=>"AQCqfCPHQUM_YzgXPJSUniVKumx6ii2fsQtgEw9Bc3B9MFwNyKmnRtdqZxCRWSl1bDxdZKIAgU_M_-DQGVedt7FRYsm8DxA7gPA8bky86H-jlaCaFQa1Gc2BRLxtuzEUPKtu3UPRmKjUpXBuJI0nHOmG4IF3WWjwRk1jtfvWvgHmEH5Q-h-JjoEgiTC5uqK6XN2E48hKqxYcqBVs-pDMLMp74WRmRCXN_R_R_RuAjyyj_9-GdNHhZ6uajuri_41AN5V8W9UqWPmtPHznL7ztNLzS9dDj7S9e25bINXUMneHVVNHwGpp5PWZULsN_hwJueUU4SFZlNgzrnupacHAXF9kU", "state"=>"1e8f5be4b10b96baedd6aab3cd2eb125b150e100c5a2c7bb"}
2015-10-25T15:20:48.735493+00:00 app[web.1]: Processing by Humans::OmniauthCallbacksController#failure as HTML
And when it does:
2015-10-25T15:56:56.726873+00:00 heroku[router]: at=info method=GET path="/humans/auth/facebook?ip=123&loc=8&mac=123&var=11" host=yourhotspot.net request_id=1c01da5f-1bea-4dbb-9a1b-a80dcc442539 fwd="82.34.163.154,162.158.38.211" dyno=web.1 connect=1ms service=18ms status=302 bytes=1828
2015-10-25T15:56:56.714754+00:00 app[web.1]: I, [2015-10-25T15:56:56.714674 #3] INFO -- omniauth: (facebook) Request phase initiated.
2015-10-25T15:56:56.920771+00:00 app[web.1]: I, [2015-10-25T15:56:56.920692 #3] INFO -- omniauth: (facebook) Callback phase initiated.
2015-10-25T15:56:56.712897+00:00 app[web.1]: Started GET "/humans/auth/facebook?ip=123&loc=8&mac=123&var=11" for 162.158.38.211 at 2015-10-25 15:56:56 +0000
2015-10-25T15:56:56.919315+00:00 app[web.1]: Started GET "/humans/auth/facebook/callback?code=AQC7jHL3hk8TSP5F9lsDjzkyXlAIbk-Kf3027g3bU-9x0etBoOxUvHd6ofEIZjEolh-UajkUCS4WZ3z40q7tgrIYi8ZIy6fuhjRJwyqLhXBPfOnmL1LqCDlPFVIdizrHPUomZ5WZ-VLmFc7A1UsEUVpyW907LgoaL8S90Gukh9oGvykIcpc1tmHqpc-WaayJNCkTUPxaRtlEmuD5FTVUDoRAzFnVDYCURhNAZMs9eTk-O40_leapHbTX0Uz6sFC6RHn-qgien_diOJst2DlRvtKWCcfxXuoBZPFPa5BtRYg2_eP4K8zUxRtDeazwYsxJt7o1i9V93np56EABMMrfBmIK&state=952e4d3cbe773056b12f56d76b0a54c5ea841f51e61d5041" for 162.158.38.211 at 2015-10-25 15:56:56 +0000
2015-10-25T15:56:57.897756+00:00 app[web.1]: Processing by Humans::OmniauthCallbacksController#facebook as HTML
I just cannot wrap my head around what's going on here. The fact that my code, environments, config vars and app settings are identical is hurting my head.
If anyone can shed some light on what might be going wrong, I'd be very appreciative.
EDIT: (Commands used)
heroku git:clone -a myapp (At this point of cloning, I had already rolled back to v410, so this clone should be of that working copy)
(cd into new app directory, make a line
change so that I can re-commit)
git add .
git commit . -m "msg"
git push heroku master
(realise it's not working as expected)
heroku
rollback v410
Command logs gave no errors and the commands worked as expected. Yet something is changing oauth.
What definitely could change on deployment is a physical server ('dyno'). I would check following things: 1) does your app cache any authentication tokens issued by facebook, e.g. in configuration? 2) how possible is that such tokens are bound to the server's IP address?

ActiveRecord::StatementInvalid (Could not find table)

I've got a rails application on DigitalOcean. I'm using the Comfortable Mexican Sofa CMS. I added the gem and ran rails generate comfy:cms and rake db:migrate but when I navigate to example.com/admin, I get a 500 error and my application isn't able to find the necessary tables. Here's the error I get in the logs.
I, [2014-06-24T21:51:18.397255 #18789] INFO -- : Started GET "/" for 173.10.20.190 at 2014-06-24 21:51:18 +0000
I, [2014-06-24T21:51:18.425183 #18789] INFO -- : Processing by HomeController#index as HTML
I, [2014-06-24T21:51:18.442366 #18789] INFO -- : Rendered home/index.html.erb within layouts/application (1.2ms)
I, [2014-06-24T21:51:18.445116 #18789] INFO -- : Completed 200 OK in 20ms (Views: 9.5ms | ActiveRecord: 0.0ms)
I, [2014-06-24T21:51:18.599085 #18786] INFO -- : Started GET "/assets/rails.png" for 173.10.20.190 at 2014-06-24 21:51:18 +0000
I, [2014-06-24T21:51:23.516755 #18789] INFO -- : Started GET "/admin" for 173.10.20.190 at 2014-06-24 21:51:23 +0000
I, [2014-06-24T21:51:23.522184 #18789] INFO -- : Processing by Comfy::Admin::Cms::BaseController#jump as HTML
I, [2014-06-24T21:51:23.526053 #18789] INFO -- : Completed 500 Internal Server Error in 4ms
F, [2014-06-24T21:51:23.532357 #18789] FATAL -- :
ActiveRecord::StatementInvalid (Could not find table 'comfy_cms_sites'):
What seems strange to me is that when I run rails c and ActiveRecord::Base.connection.tables, the tables show up and 'comfy_cms_sites' is there.
Make sure you've run your migrations on your production db with
rake db:migrate RAILS_ENV=production

Rails 3.2, Ruby 1.9 and Unicorn - The First Request is Very Slow - How to debug?

I've got a large 2.3 Rails app running on Unicorn. I'm using Unicorn, so that I can have zero downtime deployments. However, I've noticed that the first request after a restart is very slow.
First request:
Completed 304 Not Modified in 2771.8ms (ActiveRecord: 98.6ms)
Second request:
Completed 304 Not Modified in 94.4ms (ActiveRecord: 26.9ms)
I do have preload_app true and I am re-establishing the db-connection in the after-fork.
I have no idea how to explain the 2600ms divergence between these two values.
Does anyone have any thoughts? Really, what I am looking for are ways to debug this issue.
UPDATE
Here is my unicorn.log after a restart:
I, [2014-05-16T13:46:26.529305 #11637] INFO -- : executing ["/data/app/current/ey_bundler_binstubs/unicorn", "-E", "staging", "-c", "/data/app/shared/config/custom_unicorn.rb", "-D", "/data/app/current/config.ru", {12=>#<Kgio::UNIXServer:fd 12>}] (in /data/app/releases/20140516184210)
I, [2014-05-16T13:46:27.566115 #11637] INFO -- : inherited addr=/var/run/engineyard/unicorn_afar.sock fd=12
I, [2014-05-16T13:46:27.566551 #11637] INFO -- : Refreshing Gem list
I, [2014-05-16T13:47:13.036963 #8247] INFO -- : reaped #<Process::Status: pid 8681 exit 0> worker=3
I, [2014-05-16T13:47:14.093196 #8247] INFO -- : reaped #<Process::Status: pid 8670 exit 0> worker=2
I, [2014-05-16T13:47:14.100269 #12047] INFO -- : worker=0 ready
I, [2014-05-16T13:47:15.105249 #12063] INFO -- : worker=1 ready
I, [2014-05-16T13:47:15.114038 #8247] INFO -- : reaped #<Process::Status: pid 8655 exit 0> worker=1
I, [2014-05-16T13:47:15.957970 #8247] INFO -- : reaped #<Process::Status: pid 8638 exit 0> worker=0
I, [2014-05-16T13:47:15.958159 #8247] INFO -- : master complete
I, [2014-05-16T13:47:16.087761 #12082] INFO -- : worker=2 ready
I, [2014-05-16T13:47:16.876129 #11637] INFO -- : master process ready
I, [2014-05-16T13:47:17.102994 #12095] INFO -- : worker=3 ready
And here is the first request on my rails logs:
Started GET "/" for 70.XX.XXX.XXX at 2014-05-16 13:47:51 -0700
Processing by HomeController#index as HTML
(1.1ms) SELECT ..... <regular controller/ActiveRecord queries>
Completed 304 Not Modified in 2724.8ms (ActiveRecord: 98.9ms)
First request to Rails app is very slow may be relevant.
Maybe there is a dependency that is loading / running on the first page load?
Some ideas:
Check the rails log to see if there's anything funky going on
Is this just happening for Unicorn or with other servers too?
Add log statements with time stamps to get a sense for what part of the app is taking a long time
Try using ruby prof

Logger Issues - Rails Heroku / Foreman in Dev

I seem to have a very odd issue.... I am trying to develop a Rails app to be deployed on Heroku using Unicorn - as such I'm using Foreman in my local development environment to try to replicate production as closely as possible.
As you'd expect, my web/worker processes output to the development.log file in path/to/app/log. If I navigate to the file, it contains everything you would expect.
However if I use the command
tail -f log/development.log
(from the app path), I get log output from HEROKU!! How is this possible? (e.g.):
app[web.1]: [Worker(host:xxxx-xxx-xxx pid:5)] Starting job worker
heroku[web.1]: Idling
heroku[web.1]: Stopping process with SIGTERM
app[web.1]: I, [2012-02-19xxx-xxx-xxx #1] INFO -- : reaped #<Process::Status: pid 7 exit 0> worker=0
app[web.1]: I, [2012-02-19xxx-xxx-xxx #1] INFO -- : reaped #<Process::Status: pid 11 exit 0> worker=1
app[web.1]: I, [2012-02-19xxx-xxx-xxx #1] INFO -- : reaped #<Process::Status: pid 14 exit 0> worker=2
app[web.1]: I, [2012-02-19xxx-xxx-xxx #1] INFO -- : master complete
heroku[web.1]: Process exited with status 0
heroku[web.1]: State changed from up to down
heroku[slugc]: Slug compilation started
heroku[api]: Release v22 created by brandon#example.com
heroku[api]: Deploy xxxx by randon#example.com
heroku[slugc]: Slug compilation finished
This is really annoying as I can't properly see my development log... help would be appreciated!
This isn't something that Foreman's doing.
What happens if you just look at log/development.log? Is it the same?
Do you have any wacky aliases setup that might be causing this?

Resources