Capistrano deployment on Windows machine - ruby-on-rails

I have been trying to deploy a rails application using capistrano. However I am not able to reach the end of deployment and there is no way to figure out why. The script returns an error code 256 and stops at the following line in the deploy script
Command bundle exec rake assets:clean && EXECJS_RUNTIME='Node' JRUBY_OPTS='-J-d32 -X-C' bundle exec rake assets:precompile returned status code 256
There is no more explanation to it. Has anybody faced the similar issue while deploying on windows?

You should provide more information on the context of your situation. For instance, show the relevant code from your deploy.db file. That could tell us more about a possible problem source.
As a tip, when facing capistano deploying bugs, use the debugging flag to get more verbose output, and step through the process.
cap deploy:cold -d
Anywho... I was facing a similar problem, while optimizing my capistrano deploying times. In case you only want to modify your assets:precompile task, to include your EXECJS_RUNTIME and JRUBY_OPTS custom values, you could try doing this.
set :jruby_opts, "-X-C"
set :asset_env, "RAILS_GROUPS=assets EXECJS_RUNTIME='Node'"

Related

Google App Engine: Ruby on Rails - Execute migrations automatically

I was wondering if it was possible to run migrations automatically during deployment with Google App Engine. I have been using AWS Elasticbeanstalk for a while and they were ran automatically but now I am considering moving to the Google App Engine for my future projects.
Right now, I must run this command manually:
bundle exec rake appengine:exec -- bundle exec rake db:migrate GAE_CONFIG=app.yml
Thank you
WARNING: As discussed in comments, there is a race condition in migrations if deployment is done on multiple containers in parallel, because it will try to run migration on all containers. Solution is being discussed in comments, i will update this answer when we land on something.
Disclaimer: This answer is not exactly what was asked for, but it solves same problem and it works. And from what i can tell from question, doing it with some appengine config is not a requirement, rather he just want the migrations to run automatically.
I will expand on my comment on question, here is something i tried and it works. I am strong believer of KISS(keep it simple and stupid). So instead of trying to figure out appengine(which i have never used anyway) if i were you, i would take a generic approach. Which is, to plug into rails server booting process and trigger migrations. For this we have multiple approaches.
With my understanding of appengine and suggested by this official doc link appengine has a app.yaml file, this file has an entry something like:
entrypoint: rails server
So we will use this entry point to plug in our code to run migrations before starting server. For this i did this:
Make a new file in bin directory, i named it
rails_with_migrations.sh you can name it whatever you like.
Give it execute permissions with chmod +x bin/rails_with_migrations.sh
Put this code inside it:
#!/bin/bash
bundle exec rake db:migrate
bundle exec rails $#
Of course you can give whatever RAILS_ENV you want to give these.
Now in app.yaml on the entrypoint section, instead of rails server give it bin/rails_with_migrations.sh server and it should be it. It worked on local, should work everywhere.
NOTE: In entrypoint: i have bin/rails_with_migrations.sh server here, server is rails command parameter, you can pass as much parameters as you like these all will be passed to rails server command with $#'s magic. It is there to allow you to pass port and any other parameters you may need to provide for your environment. Also it allows you to run rails console locally with bin/rails_with_migrations.sh console which will also cause migrations to get triggered.
UPDATE1: As per comment, i checked what happens if migration fails, and it starts server even if migration fail. We can alter this behavior of-course in our sh file.
UPDATE2: The shell-script with migration error code handling will look something like:
#!/bin/bash
bundle exec rake db:migrate
if [ $? -eq 0 ]
then
bundle exec rails $#
else
echo "Failure: migrations failed, please check application logs for more details." >&2
exit 1
fi
This update will prevent server from starting and causing a non zero exit code from the script, which should indicate that this command failed.

Why manually deployment on Heroku dashboard didn't "rake db:migrate" automatically?

I didn't use Heroku for a while. I found Heroku change something so want to give it another try.
But after I click the "Deploy Branch" button, my app is still not working.
So I check the build log and realize Heroku seems not do the db:migrate command.
But it did do the asset:compile command. And I don't found anywhere to click to do the db:migrate thing.
So I have to do it with command line tools, right?
This is a well known limitation of Heroku. It won't run your migrations out of the box. However, you can automate it in couple of ways:
You can write a simple script that will first push new code to Heroku git repository and then run migrations. The problem is that you need to run this script locally on your machine
You can add this buildpack and then set environmental variable DEPLOY_TASKS to db:migrate. You can do this via UI, command line heroku config:set DEPLOY_TASKS='db:migrate' or you can add everything to app.json so it should work out of the box with deploy button.
You can use release phase by adding release: rake db:migrate to your Procfile.
Please keep in mind that there are many issues related to migrating your database during deployment. You can read about it in the docs for release phase.

IntelliJ Idea/Rubymine push to Heroku running db:migrate

I'm using IntelliJ Idea with the Rubymine plugin, and Heroku plugin, and I'm a bit stumped when it comes to pushing an app to Heroku. I can set it up and actually push the app: off it goes, and launches successfully. But even before I did that I was expecting it to fail because I couldn't find anyway of getting it to do a db:migrate. And so it proved: the app is launched but of course it fails pretty much immediately because there's no DB.
I've looked on the forums, google etc but nothing. Is this something that can only be done from the command line? I would have expected an IDE to be what it says on the tin: Integrated. So I feel I'm missing something. The Run configuration works as I've said, and the Heroku log has no errors, but I need a way to tell it to run the db:migrate before launching.
Any ideas?
The answer is that it is something that it doesn't do - confirmed by IntelliJ. So in this case, one needs to push the app to Heroku, drop to the command line and run the migration there: heroku run rake db:migrate.
I raised a feature request so this may be something that can be added in the future.
I haven't figured out how to do this automatically as part of the RubyMine/JetBrains Heroku Plugin. But you can cobble this together from other sources.
Start with this gist that creates rake tasks for Heroku operations provided by this answer to a similar question:
Then create a new run configurations for each Rake task that you will be using at some point. You will need at minimum push and migrate. But the other tasks might interest you.
Then create a new compound run configuration calling the Rake tasks you created in step 2 in the correct order.
Step 2 and 3 can be consolidated by creating one rake task for migration, and adding a before rake task to push. But that's kind of counter intuitive.
Note: that this approach does require you to have the Heroku CLI installed and configured with valid credentials.

Rails can't execute rake task

Rails won't fire off a rake command from my controller because it can't find rake. I know this because I experienced this in my dev environment and fixed it by giving it the absolute path to rake. However this solution isn't working my production environment.
Things I know:
I can run the rake task rom cli
I can run it through irb with a: system "rake ..."
I can't find any errors!
Rakes:
/usr/lib/ruby/1.9.1/rake
/usr/lib/ruby/gems/1.9.1/bin/rake
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2/bin/rake
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake
/usr/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake
/usr/bin/rake
/var/lib/gems/1.8/bin/rake
/var/lib/gems/1.8/doc/rake-0.9.2.2/rdoc/lib/rake
/var/lib/gems/1.8/gems/rake-0.9.2.2/lib/rake
/var/lib/gems/1.8/gems/rake-0.9.2.2/bin/rake
/var/lib/gems/1.8/gems/rake-0.8.7/lib/rake
/var/lib/gems/1.8/gems/rake-0.8.7/bin/rake
/var/lib/gems/1.8/gems/sprockets-2.3.1/lib/rake
How in the heck do I go about troubleshooting this???
The rake task I was calling in production was failing because of my attempt to dump it's contents into a log with logger disabled.
system "rake invite INVITE_ID=5 RAILS_ENV=production >> /root/log/rake.log &"
Thanks for all your help...sorry for being so vague. I was just looking for quick responses hoping I was doing something stupid. Which I was. I SWEAR I tried it without the log entry...probably moving too fast like I always do.
Also, just to answer a couple questions. The rake task I'm using is an internal tool I use myself for some maintenance and want to simply offload that task to my coworker who uses an app I've built. There's no need to industrialize it with a scheduler, etc...

Capistrano deploy but manually run migrations

I'm using Capistrano to deploy a Rails application. I'm thinking of a situation where there were database changes, so I can't simply cap deploy because the migrations need to run before the code is updated. I realize there's a cap deploy:migrations, but that's a little more automatic than I'd like. I'd like to:
Push the new code to the releases directory, but not update the symlink or restart the application.
ssh into the server, run rake:db_abort_if_pending_migrations to confirm that the migrations I want to run are the only pending ones, then run rake db:migrate manually.
Complete the deploy, updating the symlink and restarting the application.
Is there any easy way to do this with the built-in Capistrano tasks, or would I need to write my own deployment steps to accomplish this?
I should mention too that I'm thinking of cases (like adding columns) where the migration can be run on a live database. For more destructive changes I realize I'd need to bring down the site with a maintenance page during the deploy.
Try:
cap deploy:update_code
Do what you described loging in to the server manually or via cap
shell
cap deploy:symlink deploy:restart
See cap -e deploy:update_code deploy:symlink deploy:restart deploy:shell for more information.
I hope this will be helpful to You.

Resources