0

I am new to ruby and I want to learn more about how it works. So I have been testing a server configuration in a virtual machine to make quick Rails deployments.

I have RVM, Ruby, Rails, Git, Gitolite, PostgreSQL, Thin and Nginx running in an Ubuntu 10.04 environment.

Now I want to tie everything together. I got stuck, though, in the deployment process.

After I commit the project to the Git trunk, I want to hook a deployment action to put the application in the correct place, set to production, install the bundles, make the migrations and restart Nginx.

But I fail to find simple references on how it works. All I find in google are guides to use passenger, capistrano and others. I want to trigger the deployment on the git commit action, similar to heroku, but what would be the best tools to do that 100% server-side?

What about making some shell scripts? How do I deploy a project manually? What are the steps? Are there any guides out there that do not assume I know every details in Rails deployment?

Thanks!

Apollo
  • 1,913
  • 2
  • 19
  • 26

2 Answers2

0

The think you are probably looking for is a git post-receive hook (a tutorial could be found here: http://toroid.org/ams/git-website-howto).

By this hook you should trigger eg. a shell script which should perform all the steps you need - which are:

  1. checkout HEAD commit from the git repo (git checkout -f, see linked tutorial)
  2. run bundle install
  3. run bundle exec rake db:migrate - this assumed that you have already created your DB
  4. restart/start the Thin server cluster (no sure exactly here, if it is similar to passenger which I use this operation is just to create some restart.txt file) - I presume that you have your nginx as a reverse proxy in front of it, right?

This is the long-story short. It is little bit more complicated, eg. if you use the asset pipeline (rails >= 3.1), you would like to precompile you assets, etc. But the above is a good starting point.

Inza
  • 406
  • 4
  • 6
  • Maybe this is a related SO question... http://stackoverflow.com/questions/3838727/git-post-receive-hook-for-website-staging – Inza Oct 09 '12 at 12:10
0

Well, I managed to get it almost completely operational.

The main actions I could trace until now are:

  • User pushes to trunk, must use git hooks to trigger the next steps using a script.

The script must do the following:

  • Clone the project to the /var/www folder;
  • Insert the 'thin' gem into the Gemfile;
  • Run 'bundle' command in the application folder;
  • Precompile the assets in the application folder;
  • Migrate the database;
  • Stop nginx and thin;
  • Restart thin and nginx again.

If the application is new, we must also:

  • Create a new user that matches the database information;
  • Create the production database;
  • Insert a new nginx configuration file;
  • Export the thin configuration from the application folder, like this:

thin config -C /etc/thin/app.yml -c /var/www/app --servers 1 -e production

The sequence of actions is more or less this:

$ bundle package
$ bundle install --deployment
$ RAILS_ENV=production rake db:migrate
$ rake assets:precompile
$ thin start -C /etc/thin/app.yml

This is the basic by now. I want to make it work 100% and then I want to post a guide on the Internet.

Update

The guide I said I would do:

https://github.com/sentient06/RDH/wiki

Apollo
  • 1,913
  • 2
  • 19
  • 26