Capistrano how can i use two deploy.rb files - ruby-on-rails

I'm working with project on local machine where internet connection is so slowly. For best testing i have another server in other place with fast internet connection. To test my projects i'm use capistrano with puma.
But my client use production environment on his server on capistrano with unicorn.
Question:
How can i divide my puma_deploy.rb and (unicorn_)deploy.rb for work with both capistrano deployments?
P.S. when i push repo to client, i add puma_deploy.rb to .gitignore, to prevent confuse with clients administrators, which makes deploy from own repo to own server.

It sounds like you could use the Capistrano Multistage extensions to manage your deployments in different environments.
You could set up your environment (the one you use for testing) as a "staging" environment.
However, I think it might be a better idea to just use the same thing for both your testing/staging environment as production. If there is a problem with the webserver or its configuration, you might not know until it goes to production, then it is sad faces all around trying to track down the issue.

Related

Using capistrano to deploy same project from different machines

We have a team of 2 people writing Rails application. We use DigitalOcean as of VPS and capistrano to deploy it.
But the capistrano deployment scripts are only on one of our two machines.
Is it possible to set up capistrano on the second machine to deploy same project also from it? If yes, how this looks like?
P.S. This might be very easy like adding some SSH keys and running cap production deploy from second machine as the remote VPS has whole infrastructure set up. But we can't take the risk on production system.
There are a couple ways of doing this:
Commit your Cap scripts to the repository alongside your code (this is how I tend to do it; it works well with Ruby on Rails, the config structure matches). Anyone who wants to deploy just needs their SSH key set up on the server.
Create another repository with the deploy scripts; similarly to above, you need SSH keys.
Use a CI server to deploy.
Come up with something else more esoteric. Capistrano is pretty flexible.
Where I work, we generally just add Capistrano to a Rails app's Gemfile, and anyone who checks it out can deploy it to any server to which they have access. Developer SSH keys are added to the servers for this purpose.
Good luck!

Deploying on Heroku with Capistrano?

I'm still getting used to the Rails development ecosystem. Recently I learned how to use capistrano for deploying to my servers using apache and passenger, and I love how I can put a rather complex set of deployment instructions into my deploy.rb so that they are executed with a single "cap deploy" call, with an automatic rollback if anything goes wrong.
Now I'm looking into deploying my project on Heroku, and I expected to be able to use capistrano for my deployments there. But I've been unable to find any documentation on how to do this. Is it possible? Are there capistrano tasks that let me automate deployments on Heroku?
Does this even make sense? After all capistrano works in a specific way (ssh into the server) and assumes a specific directory structure (public/releases/shared etc). Both of these are not possible with Heroku as far as I know. But still I would like to have the convenience of capistrano. I know I can put the steps necessary for my deployment (git push/migrate/restart resque workers...) into a single rake task, and I would have the convenience of deploying with a call to a single command; but I would not have the benefit of capistrano transactions and rollbacks, which are very important in my mind.
I'm probably missing something very basic about how these technologies fit together. It surprises me a bit I haven't been able to find any discussion on this subject anywhere. Can anyone share their experiences?
Heroku uses Git for deployment, and is not capistrano friendly. In fact, the philosophy itself is different - Heroku does not have 'servers' where you can SSH to, or customize server to your need.
Heroku uses Dynos, which are predefined instances, with specific deployment architecture which covers majority of Rails deployment needs. You can do actions like Rollbacks, backups, migrations etc with Heroku, in some cases, more sophisticated than normal capistrano scripts.
Unless your setup is quite different, you can safely use Heroku for Rails (with only Git, of course) . If not, AWS is better bet.

deploy a rails app with capistrano without a rails environment

I've been working on a rails project for a client that isn't technical. However, they want me to send over a deployment script, which their networks guys will use to deploy the application.
I've been using capistrano. But the problem is, cap is heavily dependent on the app itself. What i need is a script, that'd use the cap and config/deploy.rb but needs minimal setup on their local systems. The repo in the backbone is git based.
If this cant be achieved by capistrano, anyone knows of any other deployment utilities, that'd allow me stuff cap does and works independently? .. (i create symlinks and run some rake tasks in my :after_update block).
Thanks,
Hassan
If setting up a ruby environment to run cap deploy is not something that the "network guys" will be willing to do, then you're in for quite an uphill battle. Some suggestions to help alleviate this:
Have them use the railsready script to set up their environment
Give them a virtual machine (maybe a Vagrant box?) that can be used to deploy the instance
If you're doing a git-based deploy, you'll either have to set up a deployer key (and give this to them) or add them to your github project (assuming you're using github)
Consider bundling up the entire project and delivering as a tarball (or putting it into an rpm) and having them deploy this way (a quick&dirty way to do this is to deploy to a machine running the same distro as production, and tarring up the deployment directory)
Consider using a stack that more aligns with their network stack, like JRuby and warbler for deploying to Tomcat
Do some pair programming or at least screen sharing for the initial install. Sometimes the difference between loving and hating a platform comes down to the availability of help when problems arise.
Mina is like Capistrano but doesn't rely on being inside the rails application directory.
One option could be to setup something like Jenkins that will use capistrano to deploy. And your client can curl the jenkins build url to trigger a deploy.

How can I improve our current deployment workflow (with Capistrano)?

Our team works on a high-traffic site where we use Capistrano to deploy our Rails apps running on Ubuntu/Apache/Passenger. We have load balancing setup, so our current procedure to minimize downtime and avoid having customers see Rails' 500 page is as follows (assuming only 2 production servers, just for this example):
Turn Apache off on production_1 (Load balancing now send all requests to production_2)
Deploy to 1st server: cap production_1 deploy (turns Apache on at the end of deploy)
Do some basic tests to ensure nothing went funky
If something went wrong, turn Apache off and rollback
Then, I follow that procedure for the production_2 server.
As you can see, this is painful, so I'm looking for a better way. Not to mention the fact that we have more servers and will be adding even more soon.
What alternatives are available?
Thanks!
yes, you can have different environments called "production_0", "production_1" and use capistrano-ext to provide multistage deployment. the run them as following:
cap production_0 deploy
cap production_1 deploy
please take a look at Github pages howto setup multistage deployment

How do you deploy your Rails application?

Do you upload your rail application to your host via FTP first?
I'm currently using Passenger and Capistrano. If I do "cap deploy" in my local machine then I think Capistrano should upload my rail application to my host, right?
Someone from my host is saying that I need to run "cap deploy" in server. I think it doesn't make sense.
You should be able to run cap deloy on your local machine and that should get the current version of your software to the server. However, you need to set up first how this is supposed to happen. I for example use Git to manage my code and also use it to get my software on the server. However, you could also use SVN or FTP if you prefer that. If you google for Capistrano together with the Software youbeant to transfer the code with and maybe even your hosting providers name, you probably will find a decent step by step explanation. For me John Numemaker's post on deploying with Capistrano and Git on Dreamhost really helped: http://railstips.org/blog/archives/2008/12/14/deploying-rails-on-dreamhost-with-passenger/
As an alternative you also might want to check out heroku.com. Their smallest offer is free and enough for most projects. The deployment process is so easy a monkey could deploy a Rails app on their platform. I generally can only recommend heroku.

Resources