Posts mit dem Label git werden angezeigt. Alle Posts anzeigen
Posts mit dem Label git werden angezeigt. Alle Posts anzeigen

Freitag, 19. September 2008

Capistrano Deployment.

Capistrano gets the latest version of the application from a given reposity and puts it online under a specific web domain.

Install Capistrano
1. install gem >gem install capistrano
2. check that worked out >cap -h

Setup app for Capistrano
1. in root directory of the application>capify

Configure Capistrano
(don't use cap deploy:cold - which is suposed to workout the configuration - you have to do the following once)
1. in app/config - edit the deploy.rb file

set :application, "nameofapp"
#Note: This will also be the name of the directory created for the app files
set :repository, "git@git.whateverthedomainis:whateverthenameis.git
#Note: This is the location of the repository of the application
set :deploy_to, "/full/path/from/server/root/directory/to/app/directory/on/server/#{application}
#Note: This is absolute location on the server where the application root directoy will be placed after being fetched from the repository
set :scm, :git
#Note: This is the resposity type (in this case a git)
set :scm_user, "name"
#Note: This is the user_name that is needed to access the repository. note: the need for a password is normally replaced by a ssh public key

set :user, "name"
#Note: This is the ssh username for the domain i.e. >ssh username@yourdomain.com

set :use_sudo, false
#Note: Capistrano will want to make some directorys on the server, it this is set to true it will use sudo before making them. I suggest to keep this false - capistrano does not need it and less things can go wrong, especially the first time.

set :branch, "whateverbranch"
#Note: The deal here is that after capistrano has cloned the repository on the server is will checkout this branch. I could not get this to work - and so expect the last version of the master branch to be checked out (at least with git and v2.5 of capistrano)

role :app, "yourdomain" # i.e. www.whatever.com
#Note: This is the address of the server that hosts the application server (i.e. mongrel, mod_rails etc)
role :web, "yourdomain" # i.e. www.whatever.com
#Note: This is the address of the server that hosts the webserver server (i.e. apache, etc)
role :db, "yourdomain" , :primary => true # i.e. www.whatever.com
#Note: This is the address of the server that hosts the database (i.e. mysql, postresql)
#Note: The :primary tells capistrano which server to run any migrations against.

Setup publickey of your server to access the application repository.
1. Login to server with a ssh shell session (i.e. >ssh name@dominnameofserver (i.e. ssh me@happy.com)) - If you are not working with public keys, then you should be asked for the password to access - after entering it you should be it.

2. cd to home on the server >cd

3. cd to the .ssh directory > cd .ssh
#Note: check for a file id_rsa.pub if its not there, then run ssh-keygen (just enter return at prompts)

3. enter on command line >more id_rsa.pub

4. Copy the key and add it to your existing repository key
Note: github.com and assembla.com have a web interface for your to do that if your repository is hosted there.

5. Check that that works by cloning the application repository by hand on the server

Freeze Rails.

>rake rails:freeze:gems

Vendorize gems #TODO.
If you are using gems but cannot install them on a sharehost then you have the option to vendorize them.

>rake gems:install
>rake gems:unpack:dependencies
>rake gems:build

Make Spin Script.
This is a small script in app/script/ called spin.rb
This script is called by capistrano after the app has been deployed to start the app and web server

#!/bin/sh

#{deploy_to}/current/script/process/spawner \
mongrel \
--environment=production \
--instances=1 \
--address=127.0.0.1 \
--port=#{port}

(#TODO Check the above)

Update Git repository.

git add .
git commit -m 'ready to deploy'
git push origin master

Deploy Setup.

git add .
git commit -m 'ready to deploy'
git push origin master


cap deploy:setup

Check Dependencies.

cap deploy:check

Deploy the Update.

cap deploy:update

Server stuff.
open a shh session on the server

>shh name@domin.xx
>cd to your app root directy
>rake RAILS_ENV=production db:schema:load
note: If this does not work - then obviously you will have to find out why and fix it before continuing.
>script/console production
note: The production environment should load up without any errors.
>>app.get("/")
note: This should return a status code of 200, 302 or similar.

Deploy Start.
On the local machine:

>cap deploy:start
note: This should return a status code of 200, 302 or similar.

Now everthing should have fired up and be working.

Samstag, 30. August 2008

Git CheatSheet















.gitignore contains the ignore files (add *.log, .DS_Store, config/database.yml)
>git init
>git add .
>git add "file name"
>git status
>git --global user.name "name"
>git --global user.email "email"
>git --global apply.whitespace nowarn
>git commit -m "message describing this commit" or git commit -v (shows you the diffs done and lets you write your commit mesage)
>git commit -a (commit all files that have been changed)
>git commit -a -v (commit all files and show diffs that have been changed)
>git log (give ascii log with messages)
>git log --stat (ascii output graph of the file changes with + and -)
>git log --p (see the diffs of the files)
>gitk (launch a visual tool of the git log). >gitk & to run in the background
>gitk -all (all local and remote branches)

>git branch (show the current branches)
>git branch --color (shows local and remote branches in color)
>git branch "name of branch" (creates a new branch)
>git branch -a (shows all local and remote branches)
>git checkout "name of branch" (to work on the named branch)

>git rebase "name of another branch" (get current changes from another branch into my working branch)
>git diff "branch 1" "branch2" (show the diffs of 2 branches) or pipe to TextMate with git diff "branch1" "branch2" | mate
>git merge branch (merges branch into current branch)
>git reset --hard ORIG_HEAD (revert the merge)
>git stash "message" (save current status of work to a "clipboard")
>git stash list (show the contents of the clipboard)
>git stash apply (bring the status in the clipboard)
>git branch -d branchname (delete a previously merged branch)
>git branch -D branchname (delete a non merged branch)
>git stash clear (clearsout the stach clipboard)

Repositories
copy project to another machine (cp -r or scp -r)
>git clone remotemachineurl (gets a copy of the remote repository from the remote machine)
>git fetch (get a copy of all objects from the remote machine - don't merge with local machine)
>git pull (syncronizes fetches changes from the remote machine with the local machine with the branch I am currently in)
>git push (syncronize local changes back to the remote machine)
>git merge (local merging of 2 branches)
>git remote show name_of_repository (shows some info on the branches in the remote repository)

Setup New Rails Project

  1. Create a new project with: >rails name_of_project, then: >cd name_of_project
  2. Optionally if using other database than Sqlite: > rake db:create:all
  3. Install RSpec Plugin & Framework. Refer to the latest instructions.
  4. Run the RSpec generator to create framework: >ruby script/generate rspec
  5. Create latest plugin documents on local drive with: rake doc:plugins. Location of documentation is "name_of_project/doc/plugins/respec-rails/index.html. Open directly in browser with: open -a Firefox doc/plugins/rspec_on_rails/index.html. Or open index.html
  6. Install and run RSpec plugin framework if needed
  7. Create the git repository with a cd to the "name_of_project" directory and then:
>git config --global user.name "your name"
>git config --global user.email "your mail@provider"
>git config --global apply.whitespace nowarn

to check the settings see .gitconfig or: >git config --list

>git init (creates local repository and the .git directory)

create a .gitignore file and add file to ignore
*.log
database.yml
db/schema.*
.DS_Store

>git add . (add all file and contents to firstime checkin)
>git commit -m "first commit"
>git status (check the repos)

see git cheatsheet for more

Setup Rails 2.1 on Mac Leopard

A version of rails and gem is already installed on the mac so we will update and expand on this installation as follows
  1. Get and Install TextMate
  2. Get and Download MacPorts - Leopard (universal). After the download and installation, edit or add to .bash_profile file the following: export PATH="/opt/local/bin:/opt/local/sbin:$PATH" (see here for more details)
  3. Update macports from the command line terminal with: >sudo port selfupdate. NOTE: I had a problem with awk not being found during the installation. This was solved by running the installation again.
  4. Install Git and Svn integration as follows: >sudo port install git-core +doc +svn
  5. Update gems with: >sudo gem update
  6. Install Rspec gem with: > sudo gem install rspec
  7. Install Zentest with: >sudi gem install ZenTest. You don't need to install the gem if you are only using rails. Zentest enables autotesting in the background.
  8. Install Rspec TextMate bundle specifically for rails supporting development: cd to the TextMate Bundles directory, i.e. > cd ~/Library/Appliction\Support/TextMate/Bundles. Then: > git git clone git://github.com/dchelimsky/rspec-tmbundle.git RSpec.tmbundle