Files not being created on Heroku - ruby

I host my Jekyll-based blog (github code) on a Heroku cedar stack.
I build the jekyll files through my Rakefile:
namespace :assets do
desc 'Precompile assets'
task :precompile do
sh "bundle exec sass --update _scss:_css --style compressed"
sh "bundle exec jekyll"
end
end
This outputs the files into a _site directory, which is where Rack will serve the files from.
This has been working for over a year, and is working fine on the currently live version of my blog (released a fortnight ago):
$ heroku run ls _site
Running `ls _site` attached to terminal... up, run.9360
2012 404 apple-touch-icon.png back-end css front-end index.html politics public-domain.txt rss.xml
2013 410 assets config favicon.ico go.sh personal postsbytag robots.txt sitemap.xml
However, whenever I try to release anything now, or release the same version of the code to a new app, the _site directory doesn't seem to be created:
$ git push git push git#heroku.com:robinwinslow-dev.git
...
http://robinwinslow-dev.herokuapp.com deployed to Heroku
...
$ heroku run ls _site --app robinwinslow-dev
Running `ls _site` attached to terminal... up, run.2577
ls: cannot access _site: No such file or directory
And the site shows:
Internal Server Error
No such file or directory - _site/404/index.html
Does anyone know why this would have changed? Has anything changed in Heroku? Or have I suddenly done something stupid?

I don't know why this ever worked in the first place, because Heroku has a read-only file system. The solution would be to compile your site including all assets locally, check them into Git and then push the complete _site directory to Heroku.

Related

Getting PDFTK installed on Heroku 18 for use in my Laravel app

I have added this pdftk buildpack to my free app on Heroku: https://github.com/fxtentacle/heroku-pdftk-buildpack.git.
I am unable to deploy my application to Heroku:
Preparing runtime environment...
-----> Checking for additional extensions to install...
-----> heroku-pdftk-buildpack app detected
cp: cannot stat 'binaries-heroku-18/*': No such file or directory
! Push rejected, failed to compile heroku-pdftk-buildpack app.
! Push failed
Also, I have added heroku/php and set the index of this buildpack to 1. When I go to my app's temporary URL, Laravel runs, but for some reasons, pdftk doesn't seem to run. Has anybody faced the same issue?
That buildpack hasn't been updated for the heroku-18 stack. Its compile script tries to copy precompiled binaries from binaries-$STACK/ into /app/bin/, but only contains binary directories for cedar-14 and heroku-16.
You could roll your app back to heroku-16, which will be supported until April, 2021, but of course this will also change other package versions:
heroku apps:stacks:set heroku-16 --app myapp
This would be very similar to going from Ubuntu 18.04 to Ubuntu 16.04, but it's likely to be your simplest solution.
Alternatively, you could fork the pdftk buildpack you found and update it for Ubuntu 18.04, but that isn't likely to be straightforward.
pdftk was removed from Ubuntu's official repositories because it depends on a deprecated library called gcj. The buildpack you're trying to use includes libgcj for cedar-14 and heroku-16 in their respective binary directories. You'll have to include that as well if you want to update the buildpack.
Also, I have added heroku/php and set the index of this buildpack to 1. When I go to my app's temporary URL, Laravel runs, but for some reasons, pdftk doesn't seem to run. Has anybody faced the same issue?
The error you're seeing is preventing your application from being deployed. You're not seeing a new version of the application with pdftk, but whatever was last deployed successfully. You'll have to resolve the build issue before you can use pdftk.
I followed this article (http://derekbarber.ca/blog/2014/11/20/using-pdftk-with-rails-on-heroku/) and got PDFTK working on Heroku-18, though on a Rails app.
Code excerpted below, HT #derek-barber.
mkdir -p [my_project]/vendor/pdftk/lib [my_project]vendor/pdftk/bin
cd /tmp
git clone https://github.com/millie/pdftk-source.git
cd pdftk-source
tar xzvf pdftk.tar.gz
mv bin/pdftk [my_project]/vendor/pdftk/bin/
mv lib/libgcj.so.12 [my_project]/vendor/pdftk/lib/
cd [my_project]
git add -f vendor/pdftk/
git commit -m "Add pdftk dependencies"
git push heroku master
heroku config:set LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/vendor/pdftk/lib
heroku config:set PATH=/app/.heroku/python/bin:/usr/local/bin:/usr/bin:/bin:/app/vendor/p
Once this PR is merged: https://github.com/fxtentacle/heroku-pdftk-buildpack/pull/9 then the buildpack should work with heroku-18 stack.
Maybe leave a comment to the repo owner asking them to merge?
For now, you could use the forked & updated version: https://github.com/Aesthetikx/heroku-pdftk-buildpack which works with heroku-18 stack.
If you are using an app.json file, then point the pdftk buildpack to the forked version:
"buildpacks": [
...,
{
"url": "https://github.com/fxtentacle/heroku-pdftk-buildpack.git"
}
]

Rails console not working on server

When I run bundle exec rails console production or rails console production via SSH on the server in the Current folder of the Capistrano deploy I get:
Usage:
rails new APP_PATH [options]
Options:
(...)
with an explanation to start a new app. Locally it works. Why can't I start a console remotely?
I'm assuming that you updated to rails 4 from version 3 and your app can't find the executables in the bin directory. Run this to see your rails version:
$ rails -v
If your rails version is 4 or above, try running this:
$ rake rails:update:bin
Source: Rails 4 Release Notes
6.1 Notable changes
Your app's executables now live in the bin/ dir. Run rake rails:update:bin to get bin/bundle, bin/rails, and bin/rake.
I am using capistrano to deploy, including the capistrano/bundler gem. Since the ./bin directory is version controlled in Rails 4, we need to prevent Capistrano from linking it on deployments by removing bin from set :linked_dirs.
Now in order to prevent bundler from overwriting the version controlled binstubs, we can add the line set :bundle_binstubs, nil which will prevent capistrano-bundler from setting the --binstubs option when running bundle install.
My config/deploy.rb file now has these lines:
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :bundle_binstubs, nil
Note the lack of the bin directory in the :linked_dirs line.
I have the same problem, and turns out when you deploy through cap shared/bin is symlink to current/bin.
Here's what works for me:
rm current/bin
mkdir current/bin
rake rails:update:bin
This should help, but it is somewhat a temporary solution, I'm trying to find out how to make cap not auto symlink-ing current/bin.
In case of Rails 5.2
I had to remove bin directory by running below command in project root directory.
rm -rf bin
and then I ran another command in project root directory:
rake app:update:bin
It will show you output like below:
create bin
create bin/bundle
create bin/rails
create bin/rake
create bin/setup
create bin/update
create bin/yarn
That's it.
It's been a little while since this was answered.
In my case I needed to run:
rake app:update:bin
Note- app rather than rails.
I was missing the bin directory all-together in my Rails 5.1 App
I faced this issue on my production server when I updated my application from Rails 5.2 to 6.0.4. Simply follow these steps:
cd to_your_project_dir
rm -r bin
rake app:update:bin

Font Awesome working locally, but not on Heroku

So I Installed the font-awesome gem and everything looks good, using the latest version etc.
Also included in my application.css:
*= require font awesome
When I view from local it turns out fine and the glyph-icons show up. When I upload it to heroku, the icons do not show up. I originally had the block squares show up but managed to fix it as I had some messy code in my stylesheets.
What am I doing wrong or what am I missing?
Had the same issue and resolved it (in Rails 4) using info from the following two sources: Rails Asset Pipeline and Rails Asset Pipeline for Heroku
"With the asset pipeline, the preferred location for these assets is now the app/assets directory". Move the fonts folder for font-awesome into app/assets and the font awesome js and css files into vendor/assets or app/assets appropriate javascripts and stylesheets folders.
Now you need to compile the assets for production, run:
$ rake assets:precompile
$ RAILS_ENV=production bundle exec rake assets:precompile
$ git add public/assets
$ git commit -m "vendor compiled assets"
Then push to heroku
$ git push heroku master
Hopefully this helps someone else who stumbles upon this question.

Heroku doesnt precompile assets for rails4

The documentation here says that heroku with pre-compile assets during deployement in Rails4.
However ,
I dont see the precompile assets message.
Using thin (1.6.1)
Using twitter-bootstrap-rails (2.2.8)
Using uglifier (2.3.1)
Using will_paginate (3.0.4)
Your bundle is complete! It was installed into ./vendor/bundle
Bundle completed (1.37s)
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
Detected manifest file, assuming assets were compiled locally
-----> Discovering process types
Procfile declares types -> (none)
Default types for Ruby -> console, rake, web, worker
I am facing issues with bootstrap in my app, where the nav bar wont load properly + some other nuances and I think its the asset precompile issue.
I am using Rails4, Ruby2.0
I have assets enabled in application.rb
config.assets.enabled = true
Precompiling manually did not help
heroku run rake assets:precompile
Had this same problem. I had precompiled locally for some reason and then pushed to Heroku.
Saw Heroku give the line "Detected manifest file, assuming assets were compiled locally" which made me realize it wasn't precompiling all the things.
When I did a "git add ." and committed, I saw that it was adding a bunch of public files. Pushing that to Heroku got it to work. So I had to precompile and git add everytime, basically doing Heroku's work for it and making a mess in my public folder. It got the job done, but was a poor fix.
I looked for the "manifest" that heroku mentioned and eventually found a ".sprockets-manifest..." file in the public directory.
Deleted that and Heroku was once again my friend.
Found this question as part of my research so I thought I'd share what I found in case anyone else sees this, or has any elaborational thoughts.
Now I have to go and see if .sprockets-manifest was important to anything else ....
I struggled with the asset pipeline for a while. There seems to be a bit of confusion as to how the asset pipeline works among newer Rubyists. In my experience, this is my workflow to the asset pipeline for Heroku.
Make sure that assets work locally on localhost (required for Heroku)
Delete the public/assets folder in the Rails directory with rm -rf ./public/assets
Make a new assets directory with mkdir public/assets
Run the rake assets:precompile command
You should see a list of assets being precompiled in your command line
Once assets are precompiled, you should commit the changes via the following commands: git add -A then git commit -am "commit message goes here"
Finally, push to heroku via git push heroku master
NOTE: This bears repeating -- make sure your assets work normally on localhost before pushing to Heroku.
Deleting the public/assets folder helped. Also I ran heroku run rake assets:clean.
After that I could see:
----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
The navbar loads fine now !
The message Detected manifest file, assuming assets were compiled locally is shown if there is .sprockets-manifest-*.json or manifest-*.json in public assets. So either removing individual file or whole public/assets works.
The source code for buildpack is here

Upgrading to Rails 3.1 Asset Pipeline proving problematic

I'm trying to upgrade an app that's already deployed to Heroku to use the asset pipeline in Rails 3.1. I followed all the necessary steps in RailsCasts #282 and my app runs fine locally. However, when I push to Heroku and try to access the root path, I'm getting errors of the sort "foobarbaz.png" is not precompiled. If I remove the first image from the page, I get the same error for the next one down, and so on. All the images have been pushed to Heroku, so there's no case of trying to reference images that aren't there.
I noticed that when I pushed the app to Heroku, I did/do not see the following output:
-----> Preparing Rails asset pipeline
Running: rake assets:precompile
I've tried running rake assets:precompile locally and keep getting the following error:
rake aborted!
production database is not configured
There's no production configuration in my database.yml file due to using Heroku. When I try to run heroku run rake assets:precompile, I get the following error:
rake aborted!
Application has been already initialized.
I've added the necessary lines to application.rb and my environment files, and I just can't seem to get it working!
That problem happened to me as well, and in my case it was because I had the following line on my config/application.rb
config.assets.initialize_on_precompile = false
It seems to be needed in some versions of Rails according to Heroku (https://devcenter.heroku.com/articles/rails-asset-pipeline),
While precompiling assets, in Rails 3.x, you can prevent initializing
your application and connecting to the database by ensuring that the
following line is in your config/application.rb:
config.assets.initialize_on_precompile = false
but in my case it was throwing the 'Application already initialized' exception, and that went away after I've removed it
Since Heroku logs weren't really helpful when deploying, the way I've tested it was to run the assets precompile rake task on my heroku instance:
heroku run rake assets:precompile
Heroku assumes you are doing your own precompiling (which you are having a problem with) if the file manifest.yml is present.
REMOVE manifest.yml from your public or public/assets folder.
Push the changes to heroku. Example below.
$ git rm public/assets/manifest.yml
$ git commit -m "remove precompile manifest"
$ git push -f heroku master
Run assets:precompile on heroku server. Enter:
$ heroku run rake assets:precompile

Resources