Direkt zum Hauptbereich

ruby on rails deployment with capistrano and git

Hello everybody!

I mentioned it before me trying ruby on rails. The language is pretty fast forward with its meaning. And I am already in love with the rails framework, although not having worked with it full time, not even semi-professional.

The internet is full with howtos and tutorials, but sometimes the hard thing is to seperate them, and finding you own "truths", some are:


I ran into serveral problems like:

  • no pictures remotely -> precompile locally!
  • make sure EVERY gem is noted in Gemfile
  • rake failed almost everytime, and blaimed permission rules
  • ... [until 5 hours of my live were gone]
This is my approach to easily developing webapps:


[do not just copy and paste, I dont post all the code;
and in retroperspect I should have read into it more deep too to save time]


For easy access set up ssh with keys, do it locally with ssh-keygen and copy your public one to the ~/.ssh/[FILE] on your server, where [FILE] is the RSA-file specified in your /etc/ssh/sshd.conf (or so).

Now make sure there is one appropiate user for git to have access to your remote repo as well as to your ruby/passenger webroot.

Furthermore I put that user in the "apache group" (www-data or www or...) and chown the webfolders to user:"apache group" and chmod it to 770.

The next step is to set up a remote BARE git repo as the "git user" on your server:

mkdir -p ~/git/[APPNAME].git
cd [APPNAME].git
git --bare init

If using ssh (or not) do this in deploy.rb:

ssh_options[:forward_agent] = true
#default_run_options[:pty] = true # Must be set for the password prompt from git to work

Do the local git stuff as well and prepare your cap and deploy.rb files
(see first link).

[edit: also make sure ssh-agent is running!
Locally do ssh-add, locally! Put it into your bashrc.]

Now you should be able to run the first test with git:


cd your_local_webapp_folder
git add -A
git commit -m "my first commit"
git push

And this in your deploy.rb for loading the remote git, instead of uploading everything all the time:
set :deploy_via, :remote_cache

Before doing the capistrano stuff, make sure you have a project with database and everything, otherwise capistrano might strike because a database migration is not there or so on:

cd your_local_webapp_folder
capify .
cap deploy:setup
cap deploy:check
cap deploy:migrations

The setup will set up all the folders, e.g. a /current/ between your root folder and your app, to where passenger should point as well.

You could run into problems like libv8 not found or rake aborted.
Solve this by installing x64 AND x32 on your local machine,
and make sure you echo ".bundle\n" >> .gitignore locally for not include specifications of your local machine since it goes to the server.

So I manually installed the gems for x64 and did bundle install
again (also bundle pack, also git add Gemfile.lock vendor/cache).

Some problems are just based on the differences between local and remote machine, so test every capistrano step locally also, e.g. precompile.

For me the precompiling of assets did not work. I discovered the whole topic by being happy it worked but without pictures. So I did this in Capfile:

load 'deploy/assets'

But it did not work, so I commented it out again, and found this solution for your deploy.rb file:

desc "deploy the precompiled assets"
    task :deploy_assets, :except => { :no_release => true } do
       run_locally("rake assets:clean && rake precompile")
       upload("public/assets", "#{release_path}/public/assets", :via =>
:scp, :recursive => true)
    end

[edit: this works smoother:
    run_locally("bundle exec rake assets:clean && 
bundle exec rake assets:precompile RAILS_ENV=#{rails_env}")  ]

Now your assets are precompiled locally and uploaded, and I dont care if it is bandwidth sucking, for it is the only solution other than hacking rails.

Hopefully I got/fixed all the bumbs on the road.
Now you should be able to do this and have your app deployed:

cd your_local_webapp_folder
git add .
git commit -m "next deployment"
git push
cap deploy


And dont exspect me to help you since I am a novice as well ;)

PS 7.9.2013:
if you ever have to setup a new server [folder] then:
  1. I did a set :deploy_via, :copy
  2. then set :deploy_via, :remote_cache
  3. I cloned my local repo into a local bare repo
    git clone --bare . remote_bare_repo_name.git
  4. that file I upload via scp
    scp -r remote_repo_name.git remoteuser@domain.com:~/git/remote_repo_name.git
  5. now my bare repo on the server is up to date again
  6. git add .
  7. git commit -m "bla bla bla"
  8. git push
  9. and make sure these settings are there
    ssh_options[:forward_agent] = true
    default_run_options[:pty] = true




Kommentare

Beliebte Posts aus diesem Blog

Pflanzsack aus Jute

Nachdem ich die Bücher vom Arche Noah Verein schon vorstellte, möchte ich hier eine Topfalternative zeigen, die obendrein noch dekorativ ist. Pflanzsäcke Oder "grow bags", wenn man etwas moderner daher komme möchte bzw. mehr Suchergenisse will. Dabei wollte ich wenig Geld ausgeben, und auch nicht ganz spartan bleiben und den Blumenerdesack dafür nutzen; und bestellte mir 50 kg Jutesäcke für ca. 1,20 EUR/Stück. Nimmt man den ganzen Sack, wird der Topf schon recht groß, auch wenn man etwas des Materials nach innen oder außen faltet. Also nahm ich mir die Freiheit und nähte aus einem großen vier kleine und verbrauchte den letzten Rest unserer Erde fürs Umtopfen der Habanero. Die machte nämlich nun Platz für die sibirische Hauschili und die restlichen von beiden Sorten mischte ich zusammen und stellte sie auf die Fensterbank. Der Vorteil dieser Art von Töpfen liegt auf der Hand: sie sind billig im Vergleich zum Volumen sie sind dekorativ - wirken rustikal biet

Zuhause fast "richtig" wok-en

Vor sehr vielen Jahren, ich war noch ein Jugendlicher, wuenschte ich mir einen Wok und bekam diesen dann auch. Es war ein gusseisener Wok, also eine schwere Ausfuehrung, der aber leider uneben und somit schwer zu gebrauchen war. Meine Eltern und ich gingen dann zurueck ins Geschaeft, aber ebene Woks waren mir damals zu teuer. Nun wieder viele Jahre in die Zukunft bekam ich die Idee, doch wieder den Wok-Gedanken aufzugreifen, denn wir kochen und essen viel asiatisch. Leider sind wir deutsche nicht so bevorteilt wie die Englaender, welche mit Gas kochen. Und ein Wok auf nem E-Herd ist so sexy wie Tanz in Gummistiefeln. Es stellte sich die Frage, inwieweit ich einen Gaskocher in die Wohnung bekomme und betreiben kann. Und solltest Du danach im Internet suchen, so wirst Du feststellen, dass man fuer ein richtiges Set mit mehr als 6 kW Leistung zwischen 50 und 600 EUR bezahlen kann, vom einfachen Hockerkocher bis zum Edelstahl-Hochleistungskocher. Mit Gas kochen ist einfach etwas wu

Herrlich!

Peter Rütten synchronisiert Lanz und Wowereit: