Does anyone know how to deploy a rails engine on heroku? The engine that I am developing is self contained so I am trying to avoid making another wrapper rails application to deploy my engine.
FIXED
I had to add config.ru and Procfile in my engine root directory to so that heroku knows that its a rails application.
Thanks,
Ajay
I guess is more dependant on how you've built your engine. If you can run it standalone locally, it'll run just fine like that on Heroku - there's nothing about Heroku which would make running your code any harder other than the normal constraints
As the edit of the question states, config.ru and Procfile are needed. I just copied config.ru from a Rails app and changed the path:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../test/dummy/config/environment', __FILE__)
run Rails.application
As for Procfile, the following will work:
web: bundle exec rackup -p $PORT
You may want to add a gem for web server, as it will default to WEBrick which is not suitable for production.
In order to get proper logs on Heroku, add the following to the Gemfile
gem 'rails_12factor', group: :production
Assets compilation won’t work unless you define the assets:precompile task (according to https://devcenter.heroku.com/articles/ruby-support#rails-4-x-applications-compile-phase).
I just added the following to engine’s Rakefile:
namespace :assets do
desc 'Precompile assets within dummy app'
task :precompile do
Dir.chdir('test/dummy') do
system('bundle exec rake assets:precompile')
end
end
end
I also disabled JS compression (or you can add uglifier gem to the Gemfile).
Related
I need to trigger a capistrano deployment from within an existing ruby scrpit.
For example, assume I want to start service that will listen to some messages, and on some messages I want to trigger a capistrano deployment of another app using cap staging deploy (which does work if I run this command directly from a shell).
~/app-to-deploy
- Gemfile #including many dependencies
- config/deploy # capistrano files
~/my-service
- Gemfile # including different dependencies than `app-to-deploy`
- my_script.rb # that wishes to call `cap app-to-deploy deploy`
I was thinking I could run the capistrano bash script from my service using something like
# my_service.rb
Dir.chdir(ENV['HOME'] + '/app-to-deploy') do
result = system('bash', '-c', "cap staging deploy")
end
If I run it with or without bundle exec this gives something like
cap aborted!
LoadError: cannot load such file -- active_support/all
/deploy/hermes/Capfile:2:in `require'
/deploy/hermes/Capfile:2:in `<top (required)>'
(See full trace by running task with --trace)
(I have ActiveSupport as a gem in my app-to-deploy but I don't have it in the Gemfile of my-service)
Seems like I have a lib dependency problem, but I'm not sure how to solve it...
Anyone has ideas or ways to go around the problem ? (or even better a way to call capistrano without using bash, assuming I may still have different dependencies ?)
(Note that app-to-deploy is an actual Rails app with many capistrano scripts that I don't want to touch if possible...)
The problem is that in unix systems environment is inherited. So when you call Capistrano from your rails app you don't have access to other gems. bash -c doesn't seem to clean env. You can with su -l probably.
One solution is to use
Bundler.with_clean_env do
Dir.chdir(ENV['HOME'] + '/app-to-deploy') do
result = system('bundle', 'exec', "cap", "staging", "deploy")
end
end
Just for reference: http://bundler.io/man/bundle-exec.1.html#Shelling-out
I´m having trouble to access the rails console in production.
I used Capistranoto deploy the app to a VPS
If I cd to deploy#myapp:~/myapp/current$and run bundle exec rails cthere I always get the option list for creating new rails project, like rails new
I've also tried bundle exec rails console --productionand rails consoleetc all with the same outcome.
the thing is I must be able to access the console because I have to create an admin user for active admin
might be worth adding that I'm using Passenger/Capistrano and Nginx on Ubuntu 16
Does anyone know what is going on here? Am I doing something wrong?
*EDIT
After running RAILS_ENV=production bundle exec rails c I get this message
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 4, your app's bin/ directory contains executables that are versioned
like any other source code, rather than stubs that are generated on demand.
Here's how to upgrade:
bundle config --delete bin # Turn off Bundler's stub generator
rake rails:update:bin # Use the new Rails 4 executables
git add bin # Add bin/ to source control
You may need to remove bin/ from your .gitignore as well.
When you install a gem whose executable you want to use in your app,
generate it and add it to source control:
bundle binstubs some-gem-name
git add bin/new-executable
Loading production environment (Rails 4.2.5)
irb(main):001:0>
You are missing executable files of bin folder in Production after Capistrano deployment.
You need to remove bin from set :linked_dirs from your Capistrano deploy.rb in order to avoid symlinking it.
You can again try cap production deploy, it would take all the executable files from bin to Production.
Now, you can access the rails console using:
RAILS_ENV=production bundle exec rails c
If you are using Capistrano 3, you can include the rails:console option which will allow you to do this from your local machine to gain access to the console on the remote host:
bundle exec cap production rails:console
https://rubygems.org/gems/capistrano-rails-console
The Rails project is deployed in /deploy/your_project_name/current on the server by default. So, you can access it via SSH or ... and run bundle exec rails c to access the Rails console. It works for me!
check if rvm and regarding gemset is suitable for the app
rvm gemset list
rvm list
and then do
bin/rails rails c -e production
I am trying to setup solr sunspot search in production mode.
I have followed the below tutorial and got success in setting up tomcat-solr server running.
http://www.arborisoft.com/how-to-install-apache-solr-4-4-on-ubuntu-12-04/
I ran
rails generate sunspot_rails:install
and configured the config/sunspot.yml file.
For development mode I used 'sunspot_solr' gem(which is not advisable for production mode) and got this command working.
bundle exec rake sunspot:solr:start
When I removed this gem
it's giving me following error
Note: This task has been moved to the sunspot_solr gem. To install, start and
stop a local Solr instance, please add sunspot_solr to your Gemfile:
group :development do
gem 'sunspot_solr'
end
I have tried adding this to Rakefile:
require 'sunspot/solr/tasks'
when I run the following command
bundle exec rake app:sunspot:solr:start
I am getting the following error
rake aborted!
cannot load such file -- sunspot/solr/tasks
I am using rails 4.
I don't know what I've missed. I have searched for the solution in and out of stackoverflow. But I couldn't get any reference. Even if I find any since I am a rails noob, I couldn't understand what they are talking about. any solution will be really helpful.
You can also change the path to solr/default in config/sunspot.yml file for production mode or any other defined modes.
These are some terminal commands which could follow to solve your problems:
ps aux | grep solr to get solr process ID
through this you can check which server id is running and which one is in your sunspot pid file.
sudo kill <ID>, <ID> is the ID you found from 1
rm -r <path/to/solr>, remove the solr directory inside your project to remove all of previous indexes
RAILS_ENV=production bundle exec rake sunspot:solr:start
Change the path to /solr/default inside config/sunspot.yml
RAILS_ENV=production bundle exec rake sunspot:solr:reindex
this link can also help in understanding problem and issues:https://github.com/sunspot/sunspot/issues/492
I have deployed a new Rails site to a Linux VM using Capistrano. I am using nginx as the front end and running my Rails app using unicorn.
If I try to run rake routes on the server, I get an error telling me that Rails is not installed, even though Rails is installed. The problem seems to be that the gem search directory is different for the app and the logged in user.
How do I load the Rails environment that my app is seeing as the logged in user?
Just use:
RAILS_ENV=production bundle exec rake routes
The RAILS_ENV part sets your environment variable so your app is loaded in full production mode, including database settings and so on.
The bundle exec part is necessary so that any commands that come after that are executed within the environment of the gems installed in your Gemfile.
I use on heroku unicorn , Procfile is already used by Heroku for unicorn server. I would like on development use gem foreman , is it possible to configure gem use different file than Procfile??
foreman start --procfile myfile
or
foreman start -f myfile
That being said, the whole idea of foreman and Procfiles is to use the same one everywhere so you can keep your development environment as close as possible to your production environment.
I would recommend looking at the docs here and making sure you really need a whole separate file for development.