I deployed a rails 6 app with webpacker on heroku.
The public/packs are sync to an s3 bucket, same as the public/assets.
Delivering assets from public/assets works. But when trying to open anything dependent on public/packs I get.
2020-06-04T05:33:03.622234+00:00 app[web.1]: [58f2d221-761b-44ec-807c-6b922342c10b] method=GET path=/teach/organizations format=html controller=OrganizationsController action=index status=500 error='ActionView::Template::Error: Webpacker can't find admin_unify_style.css in /app/public/packs/manifest.json. Possible causes:
2020-06-04T05:33:03.622242+00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2020-06-04T05:33:03.622242+00:00 app[web.1]: unless you are using the `webpack -w` or the webpack-dev-server.
2020-06-04T05:33:03.622243+00:00 app[web.1]: 2. webpack has not yet re-run to reflect updates.
2020-06-04T05:33:03.622243+00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2020-06-04T05:33:03.622244+00:00 app[web.1]: 4. Your webpack configuration is not creating a manifest.
2020-06-04T05:33:03.622244+00:00 app[web.1]: Your manifest contains:
2020-06-04T05:33:03.622245+00:00 app[web.1]: {
2020-06-04T05:33:03.622245+00:00 app[web.1]: }
How is heroku expected to find about the manifest on heroku. The manifest contains
"entrypoints": {
"admin_unify_style": {
"css": [
"/packs/css/admin_unify_style-c2ad729a.css"
],
"js": [
"/packs/js/admin_unify_style-62270c86710162620f91.js"
],
"js.map": [
"/packs/js/admin_unify_style-62270c86710162620f91.js.map"
]
Update 1:
It is working in production env outside of heroku and without assets on cloudfront
Long story short - the manifest should be on heroku, while the assets could be on s3
Here is how I got it working - Heroku, S3, Cloudfront, Webpacker, Rails 6, Sprockets.
Assets are precompiled and uploaded to s3. public/assets and public/packs are ignored from the repo.
public/assets/*
!public/assets/.sprockets-manifest*
public/packs/*
!public/packs/manifest.json*
But as you could see the manifest are not.
Cloudfront is configured for production with
config.action_controller.asset_host = "https://blabla.cloudfront.net"
public/assets and public/fonts are synced on s3 with a s3cmd command. Custom script.
After the are synced to s3 we are commiting the manifests
if git ls-files -m | grep "public/assets/.sprockets-manifest\|public/packs/manifest.json*"; then
git add --all public/assets/.sprockets-manifest* -f
git add --all public/packs/manifest.json* -f
git commit -m "Autocompiling assets from jenkins"
git push
fi
In this way we only have the two manifests in the repo with all the assets on S3.
5. Push to heroku and it works. For now, like charm
Related
I have created a golang REST API and am trying to deploy it to heroku. I've built it on windows 7.
I linked my github account to push my golang web app to heroku, but I am getting the following error:
The requested file (go1.13.7.linux-amd64.tar.gz) is unknown to the buildpack!
I am using dep to package my app. Here is the metadata i provide to heroku in my Gopkg.toml:
[metadata.heroku]
root-package = "restapitest"
go-version = "go1.13.7"
install = [ "./..." ]
My file project folder looks like this:
C:\$GOPATH\src\API\RESTAPI\
Vendor\github.com\gorilla
go-sql-driver
Gopkg.lock
Gopkg.toml
main.go
It appeared to be an issue with the version. Lowering it to 1.12.0 allowed successful deployment of the app.
I am facing asset loading issue in Rails 5 application deployed on Heroku.
App Configuration is,
ruby => ‘2.3.1’
rails => '~> 5.0.1'
When image is stored on path,
app/assets/home/image1.jpg
I am accessing it in view as,
= image_tag('/assets/home/image1.jpg’)
which is working properly in Development ENV, but not in Production ENV.
As per Heroku log,
ActionController::RoutingError (No route matches [GET]
"/assets/home/image1.jpg")
If I am moving image directly to
app/assets/image1.jpg
then its working on Production ENV.
Please guide about it.
Thanks
It looks like you assets are not compile on heroku.
Follow below code:
config/environments/production.rb
config.assets.compile = true
then run commands:
RAILS_ENV=production rake assets:precompile
then push all compiled files with menifest file to heroku.
I've cloned this repo:
https://github.com/lvillani/quickstart-jekyll-zurb
I got it working locally no problem.
I added a Procfile with the following:
web: bundle exec jekyll serve -P $PORT
Heroku accepts the bundle no problem.
But the server crashes when trying to load a page.
The first problem I had was that it was trying to render a misformated vendor page.
I fixed that by adding this to _config.yml:
exclude:
- "vendor/bundle/ruby
But now my app.scss file can't #import "foundation/settings";.
Here is the relevant portion of the Heroku logs.
"2014-10-16T19:56:05.366451+00:00 app[web.1]: Generating...
2014-10-16T19:56:05.361060+00:00 app[web.1]: Configuration file: /app/_config.yml
2014-10-16T19:56:06.277480+00:00 app[web.1]: Conversion error: There was an error converting 'asset/app.scss'.
2014-10-16T19:56:06.277526+00:00 app[web.1]: jekyll 2.1.1 | Error: File to import not found or unreadable: foundation/settings.
2014-10-16T19:56:06.277529+00:00 app[web.1]: Load path: /app/_vendor/foundation/scss
Everything works fine locally, so I assume this is a Heroku configuration issue but I don't know enough about Heroku to begin to know where to look.
thanks!
Maybe you forgot to run a make setup.
Note that your jekyll is 2.1.1 and current version is 2.4.
I've just loaded up a static app to Heroku using this tutorial and everything works quite well, except my images aren't showing up. When the same site is hosted on my own server as a plain static site (not through Heroku), all of the assets load up without a problem.
Currently, I have a Gemfile, Gemfile.lock, app.rb, config.ru and public (static site directory) in my repository that I'm loading to Heroku through git push heroku master to push to Heroku.
My images are in public/img and even the assets directly referenced from html aren't showing up. When I use firebug lite in Chrome to check the asset directory, it seems as though the image files are there, but they don't seem to have the image data (from what I could tell).
I do not have any further ruby/rails files. Should I have a production.rb file somewhere? Am I missing out on something?
Currently, my setup on Heroku is the free package. Will I need to upgrade to a paid package to see my assets (I only have 2MB of assets)? I've tried creating an "assets" directory inside the "public" directory and placing the img directory in there, but still no luck.
Here is my config.ru
use Rack::Static,
:urls => ["/img", "/js", "/css"],
:root => "public"
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
To diagnose issues like this where you believe the file contents on your dyno don't match the ones in your source, use heroku run bash to login into a remote, on-off dyno. This will drop you into a bash shell where you can explore the file system as seen by your dyno (although the dyno your shell is attached to is not the one actively serving your requests it will have the same filesystem contents).
$ heroku run bash
Running `bash` attached to terminal... up, run.4065
~ $ ls
pubic Gemfile Gemfile.lock app.rb config.ru
~ $ cd public/img
~/public/img $ ls -l
total 40
-rw------- 1 u36831 36831 2743 2013-02-15 18:54 facebook-1652d049.png
-rw------- 1 u36831 36831 2291 2013-02-15 18:54 feed-e8d78a2f.png
From here you should be able to see:
If the image files even exist on the dyno
If their contents are what you expect (do the file sizes match what you see in your local env?)
I'm attempting to upload a simple one page web page using Heroku.
I was previously using the Play! Framework but it seems overkill for a single page with some javascript.
+ project/
+ public/
+ css/
...
+ img/
...
+ js/
...
index.html
How do I upload a basic set of static files to Heroku? There seems to be no documentation on their website on how to do this.
It is not the purpose of Heroku to host static websites. However, you still can do it but you have to create either a Ruby on Rails, Play, etc. project, add the HTML in the folders.
Heroku doesn't really support static web pages, it supports Apps. However, a static web page can trivially be 'enhanced' to be a PHP application by adding a dummy index.php.
So if you want to host a file foo.html as a Heroku app Foo, then:
1. Create Foo on Heroku.
2. [Clone empty repository to local directory] git clone git#heroku.com:Foo.git -o heroku
3. touch index.php
4. [add foo.html]
5. git add .
6. git commit -m 'test'
7. git push heroku master
Heroku has a guide to doing this with Rack: https://devcenter.heroku.com/articles/static-sites-ruby
Basically, create a simple Rack app with a config.ru file:
use Rack::Static,
:urls => ["/images", "/js", "/css"],
:root => "public"
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
a Gemfile:
source "https://rubygems.org"
gem 'rack'
and a public folder with an index.html file and folders for other assets, structured like this:
my_site/config.ru
my_site/Gemfile
my_site/public/index.html
my_site/public/css
my_site/public/images
my_site/public/js
And someone has made a site that will generate all the necessary files for you: http://herokustaticmagico.herokuapp.com/