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:
[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:
If using ssh (or not) do this in deploy.rb:
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:
And this in your deploy.rb for loading the remote git, instead of uploading everything all the time:
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:
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:
But it did not work, so I commented it out again, and found this solution for your deploy.rb file:
[edit: this works smoother:
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:
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:
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:
- Deploying Rails 3 Apps with Git, Capistrano and Passenger
- Deploying the application remotely using Capistrano
- life saving second post: rails 3.1 assets:precompile deployment
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]
[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:
- I did a set :deploy_via, :copy
- then set :deploy_via, :remote_cache
- I cloned my local repo into a local bare repo
git clone --bare . remote_bare_repo_name.git - that file I upload via scp
scp -r remote_repo_name.git remoteuser@domain.com:~/git/remote_repo_name.git - now my bare repo on the server is up to date again
- git add .
- git commit -m "bla bla bla"
- git push
- and make sure these settings are there
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
Kommentare
Kommentar veröffentlichen