How to get Elastic Beanstalk to server compiled assets? - ruby-on-rails

I am trying to get a Rails 3.2.x application to run in production but everytime I visit the deployed application it complains about assets not being compiled:
An ActionView::Template::Error occurred in home#index:
application.css isn't precompiled
vendor/bundle/gems/actionpack-3.2.11/lib/sprockets/helpers/rails_helper.rb:142:in `digest_for'
-------------------------------
Request:
-------------------------------
* URL : http://some-server.elasticbeanstalk.com/
* Parameters: {"controller"=>"home", "action"=>"index"}
* Rails root: /var/app/current
* Timestamp : 2013-01-17 17:22:55 UTC
However, when i consult the log files of my EB instance I see this as part of each deploy:
Script succeeded.
Executing script: /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh
Output from script: /usr/bin/ruby1.9 /usr/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
I can run a local instance of Passenger in production mode and the assets are served fine. Does anyone have any insight on what might be going wrong?

Try restarting your application by running the following command from your application root:
touch tmp/restart.txt
Fixed the issue for me.

Related

Rails 6 local server booting : RAILS_ENV=development environment is not defined

I just created a new Rails 6 app. Everything went fine until I tried to launch the local server with rails s, and got this error message :
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
Exiting
and
Webpacker configuration file not found /Users/remy/dev/voter/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory # rb_sysopen - /Users/remy/dev/voter/config/webpacker.yml (RuntimeError)
But when I run rails webpacker:install I still have the error.
That error usually hints at an unmet Yarn dependency. Try installing or updating Yarn before running rails webpacker:install.
Here are the Yarn Docs for quick reference just in case.

Ruby on rails project deploy to server

I have a ruby on rails project. It runs successfully on my PC with command "rails s". So I decided to deploy it to AWS using Capistrano. Server side, I am using Puma + Nginx + mysql stack. (I am following this guide: https://www.sitepoint.com/deploy-your-rails-app-to-aws/)
I got error when I run "cap production deploy":
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deploy2#111.21.5.197: rake exit status: 1
rake stdout: rake aborted!
Sass::SyntaxError: Invalid CSS after "...e bootstrap.min": expected "{", was ""
(sass):6648
I found out it was the file app/assets/stylesheets/application.css causes the error. In this file, I have only one line:
*= require bootstrap.min
I think it is correct. Because the app can run on my PC.
If I remove this line, there will be no error when I run "cap production deploy". The app can deploy to the server and run on the server. But no CSS for all the web pages. I am basically new to ruby on rails. So I don't know the details after all these files. Does anyone can suggest what should I do in order to make my app deploy to the server successfully?
Rename your stylesheet to application.scss (note the scss extension) and make sure it contains this line:
//= require bootstrap.min

rest-client request time out

I am deploying my branch on a new server using BitBucket. However, after I prepared everything, during the deployment, I am getting this error message all the time.
DEBUG [076ec2be] Command: cd /opt/webapp/holidale_dev10/releases/20160211212625 && ( export RAILS_ENV="dev10" ; /usr/local/rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG [076ec2be] rake aborted!
DEBUG [076ec2be] RestClient::RequestTimeout: Request Timeout
DEBUG [076ec2be] /opt/webapp/holidale_dev10/shared/bundle/ruby/2.3.0/gems/rest-client-1.8.0/lib/restclient/request.rb:427:in `rescue in transmit'
This is due to the timeout of one of my gem's authentication.

Precompiling assets with capistrano gives error during deployment

I am trying to deploy my rails app to a digital ocean server using the capistrano gem, and I'm getting the error :
The deploy has failed with an error: #<SSHKit::Command::Failed: RAILS_ENV= bundle exec rake assets:precompile exit status: 256
RAILS_ENV= bundle exec rake assets:precompile stdout: Nothing written
RAILS_ENV= bundle exec rake assets:precompile stderr: rake aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
Even though the local config/database.yml and shared/config/database.yml file on the server are both configured, and have production databases set.
In case I run the rake db:create command on the server, it does create the database successfully. So, can't really find the issue.
Using rails 4.0.2, ruby 2.1.0, capsitrano 3.1.0
Sorry - I don't have the rep to comment.
It's a bit short on detail about your deploy configuration, you probably need to share.
RAILS_ENV= bundle exec rake assets:precompile stdout: Nothing written
Would suggest to me that there is no RAILS_ENV set. I don't think there is an issue with the database .yml
Infact - this post might be relevant: Capistrano 3, Rails 4, database configuration does not specify adapter

How to deploy rails sqlite3 database with capistrano

I am trying deploy like this:
bundle exec cap deploy:cold
RAILS_ENV=production rake db:migrate
bundle exec cap deploy:migrate
but all the time shows error in log file:
I, [2014-04-14T14:15:14.853543 #10769] INFO -- : Started GET "/users/sign_up" for
176.192.228.14 at 2014-04-14 14:15:14 -0400
I, [2014-04-14T14:15:14.856055 #10769] INFO -- : Processing by
Devise::RegistrationsController#new as HTML
I, [2014-04-14T14:15:14.857398 #10769] INFO -- : Completed 500 Internal Server Error
in 1ms
F, [2014-04-14T14:15:14.860844 #10769] FATAL -- :
ActiveRecord::StatementInvalid (Could not find table 'users')
but in the current/db folder was created production.sqlite3 .
In the localhost:3000 it works fine.
How can i migrate db for production with capistrano?
I use nginx and unicorn and this is my repo https://github.com/EgorkZe/bh
Better yet, change up your db configuration:
production:
adapter: sqlite3
database: /absolute/path/to/shared/db/production.sqlite3 # instead of db/production.sqlite3
Working with Sqlite in production is very problematic because each time you deploy new version you entiredb is stay on the old release folder, what you can do is when you deploy add this command:
task :copy_sqlite, roles: :app do
run "cp #{current_path}/db/production.sqlite3 #{release_path}/db/"
end
just add this the before rake db:migrate and it will solve your problem.
My strong suggestion move to PostgreSQL/MySQL.

Resources