How to deploy rails sqlite3 database with capistrano - ruby-on-rails

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.

Related

Delayed Job in Rails 4 with Capistrano

I cant figure how to start Delayed Jobs on a dedicated Ubuntu server.
It works fine on my localhost but when I run on my server
sudo RAILS_ENV=production bin/delayed_job restart
I get
sudo: bin/delayed_job: command not found
On top of that, if I run the "rake jobs:work RAILS_ENV=production" command Im getting the following error:
PG::FeatureNotSupported: ERROR: SELECT FOR UPDATE/SHARE is not allowed in subqueries
Apparently theres an issue with my psql version.
Is there any way I can get the script to work? Any effective Capistrano recipes available? All ive found on the web are old recipes for Rails 3 and older versions of capistrano.
Thanks in advance.
EDIT:
I have already bundled install the daemons gem and generated "delayed_job:active_record" on my local machine, then proceded to cap deploy which bundle installed and migrated in the production server.
The bin/delayed_job file exists in the server yet it fails with command not found.
And add this to config/environment.rb:
ENV['RAILS_ENV'] ||= 'production'
Then at your production server:
RAILS_ENV=production rake db:migrate
RAILS_ENV=test production generate delayed_job:active_record && RAILS_ENV=production rake db:migrate
Now after you do that:
RAILS_ENV=production script/delayed_job start
As for Capistrano error you are facing, please try to add the command like:
run "cd #{current_path}; #{sudo} RACK_ENV=production bundle exec #{current_path}/bin/delayed_job start"
You must run this on target server:
bundle exec rails generate delayed_job

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 get Elastic Beanstalk to server compiled assets?

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.

rbenv in production triggering mongodb connection error

I've switched to rbenv in production (staging to be correct) and most of the switch seemed to work just fine. I've followed the guidelines outlined here: http://blog.danielpietzsch.com/post/14005159872/running-a-rails-app-in-production-using-rbenv-apache
However, running rake assets:precompile throws this Failed to connect to a master node at localhost:27017. My guess is that this is a symptom of something else missing or being astray.
which rake
root#staging1:/var/www/staging# which rake
/usr/local/rbenv/shims/rake
rbenv version
root#staging1:/var/www/staging# rbenv version
1.9.3-p125 (set by /usr/local/rbenv/version)
mongod is running on localhost:27017
root#staging1:/var/www/staging# mongo --port 27017 --host localhost
MongoDB shell version: 1.8.0
connecting to: localhost:27017/test
> exit
bye
rake task that triggers the error
root#staging1:/var/www/staging# rake assets:precompile
/usr/local/rbenv/versions/1.9.3-p125/bin/ruby /usr/local/rbenv/versions/1.9.3-p125/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Failed to connect to a master node at localhost:27017 <--------------- ERROR
Tasks: TOP => environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/usr/local/rbenv/versions/1.9.3-p125/bin/r...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Here is the rake task with --trace: http://pastie.org/private/ww9wm0wlm6le6wbtmq89ia
I've found a few others with the same problem on heroku, but in that case it seem to be because mongo really isn't running: http://blog.noizeramp.com/2011/10/14/rails-3-asset-pipeline-on-heroku-when-using-mongoid/
I'd be happy to provide more details if needed. Just let me know and I'll update the question with more details.
Turns out I was using this in my mongoid.yml:
defaults: &defaults
use_utc: true
host: localhost
allow_dynamic_fields: false
...
and in /etc/mongodb.conf:
bind_ip = 127.0.0.1
This doesn't work, for some reason. Changing to 127.0.0.1 solved the problem.

deploy rails app on heroku

Hey
I'm afraid I should ask a rookie question :
After push my app to heroku. I got error of no database
This is the command I use
heroku rake db:migrate
My app can run locally with no problem, but I notice the database file only in development.
and my test evironment only use rails server and localhost:3000
anyone tell me how to make the database in production mode in heroku.
Thanks
here's the heroku log file:
here's the logs
Started GET "/drummers/1" for
221.9.247.14 at Sat Dec 18 06:17:40 -0800 2010 Processing by DrummersController#show as HTML
Parameters: {"id"=>"1"} Completed in
167ms
ActiveRecord::RecordNotFound (Couldn't
find Drummer with ID=1):
app/controllers/drummers_controller.rb:11:in
`show'
I think it may due to the datebase,config file, become I use sqlite3 in local test, and all the migration file is development prefix,
It's not telling you that you have no Database.
It's telling you that it can't find a specific record
(Couldn't find Drummer with ID=1):
It's likely that you have code that's doing Drummer.find(1) and that doesn't exist on your production environment.
Recommend you either:
create a seeds file (heroku rake db:seed) rails cast
push your entire database to heroku (heroku db:push) [make sure you understand this will wipe out your production database]
Heroku creates a database for each application deployed to it (no need to run heroku rake db:create. Here are the commands you should be using to deploy a Rails application to Heroku:
git init
git add .
git commit -m "initial import"
heroku create
git push heroku master
heroku rake db:migrate
heroku open
I believe Heroku creates a new database.yml for you on deploy if you have no production according to the Docs.

Resources