Full Rails Stack Part Three: Project and Subversion

If you've finished part two let's continue. In this part of the series I'm going to assume you have a working installation of MySQL on your local client machine that we will only need for testing purposes. If you've got a Mac you might look at installing MacPorts and using it to install MySQL for you. First we'll create a test rails project. I'm going to use the latest rails 2 sugar in setting up this simple test site. Open up terminal or iTerm and find a directory you want to use to create the test project. Here we go:

CODE:
  1. rails --d=mysql factory
  2. cd factory
  3. rake db:create
  4. script/generate scaffold widget name:string description:text
  5. rake db:migrate

Now let's test our site to make sure everything is working correctly:

CODE:
  1. script/server

Open up your browser and try the site out using http://localhost:3000/widgets.

Then stop the web server using CTRL_C. Now let's go ahead and remove the index.html file:

CODE:
  1. rm -rf public/index.html

Let's add the default route for our test website so that if you type in localhost:3000 it routes to our widget controller.:

CODE:
  1. nano config/routes.rb

Paste the following before the 'end' at the bottom of the file

CODE:
  1. map.root :controller => "widgets"

Save the file and restart the server:

CODE:
  1. script/server

Try out our new route by going to http://localhost:3000. It should load our widgets list page.

Now let's install subversion:

CODE:
  1. sudo apt-get install subversion subversion-tools libsvn-dev libsvn1

Install ssh:

CODE:
  1. sudo apt-get install ssh

Create our repository:

CODE:
  1. sudo svnadmin create /var/svn/mycode
  2. sudo chown -R deploy:deploy /var/svn/mycode

Edit the svnserve config file:

CODE:
  1. sudo nano /var/svn/clickhere/conf/svnserve.conf

Modify the following lines

CODE:
  1. anon-access = none
  2. auth-access = write
  3. authz-db = /usr/local/nginx/conf/svn_access.rules
  4. realm = My Code Repository

Create the access rules file:

CODE:
  1. sudo nano /usr/local/nginx/conf/svn_access.rules

Paste in the following and save the file:

CODE:
  1. [groups]
  2. developers = deploy
  3. qc = deploy
  4. pm = deploy
  5. [/]
  6.  
  7. @developers = rw
  8. @qc = r
  9. @pm = r

Create a svnserve startup file:

CODE:
  1. sudo nano /etc/init.d/svnserve

Paste in the following:

CODE:
  1. #!/bin/sh
  2.  
  3. # Use the following variables to customize user, group, and paths.
  4. SVNSERVE=`which svnserve`
  5. SVN_USER=deploy
  6. SVN_GROUP=deploy
  7. SVN_ROOT_PATH=/var/svn/mycode/
  8.  
  9. if [ -f /etc/rc.d/init.d/functions ]; then
  10. # RedHat style
  11. . /etc/rc.d/init.d/functions
  12. START="daemon $SVNSERVE -d --root $SVN_ROOT_PATH"
  13. STOP="killproc $SVNSERVE"
  14. else
  15. # Ubuntu LSB style
  16. . /lib/lsb/init-functions
  17. START="start-stop-daemon --start --exec $SVNSERVE -- -d --root $SVN_ROOT_PATH"
  18. STOP="start-stop-daemon --stop --exec $SVNSERVE"
  19. fi
  20.  
  21. if [ ! -x $SVNSERVE ]; then
  22. echo "Could not find ${SVNSERVE}. PATH is ${PATH}"
  23. exit 0
  24. fi
  25.  
  26. case "$1" in
  27. start)
  28. echo "Starting svnserve..."
  29. umask 002
  30. $START
  31. if [ $? ]; then
  32. echo "Started svnserve"
  33. exit 0
  34. else
  35. exit $?
  36. fi
  37. ;;
  38.  
  39. stop)
  40. echo "Stopping svnserve..."
  41. $STOP
  42. exit $?
  43. ;;
  44.  
  45. restart|force-reload)
  46. "$0" stop && "$0" start
  47. ;;
  48.  
  49. *)
  50. echo "Usage: /etc/init.d/svnserve {start|stop|restart|force-reload}"
  51. exit 1
  52. ;;
  53. esac
  54.  
  55. echo "Unhandled case while trying to start svnserve."
  56. echo "see $0"
  57. exit 3

Make it executable:

CODE:
  1. sudo chmod +x /etc/init.d/svnserve

Add it to the startup scripts:

CODE:
  1. sudo update-rc.d /etc/init.d/svnserve defaults

Start the server:

CODE:
  1. sudo /etc/init.d/svnserve start

Exit it out of our linux server. Now on our Mac we are going to edit our subversion config file

CODE:
  1. sudo nano ~/.subversion/conf

Add the following line inside the [tunnels] section

CODE:
  1. widgets = /usr/bin/ssh -p 8888 -l deploy

Save and exit nano. Now let's try everything out by creating a top level "projects" folder in our subversion repository from our Mac client:

CODE:
  1. svn mkdir svn+widgets://your_linux_box.com/var/svn/mycode/projects

If the directory got added were good to go. Now we can add our factory rails website. But before we do that lets setup a proper subversion folder structure using branches, tags, and trunk. Below is the folder structure I like (projects/[client_name]/[project_name])...feel free to change it however you'd like it to work. You could also create the folder structure manually locally on your Mac using mkdir and import it as the project.

CODE:
  1. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me
  2. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory
  3. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/branches
  4. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/branches/experiments
  5. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/branches/releases
  6. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/branches/tickets
  7. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/tags
  8. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/tags/notable_moments
  9. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/tags/releases
  10. svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/trunk

Now let's import our factory project:

CODE:
  1. svn import -m "Creating factory project for me" . svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/trunk

Now we should be able to list the folders using svn:

CODE:
  1. svn list svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/trunk

Now let's check out a copy of our factory project from our subversion server. First we'll create a new directory to hold our code called factorysvn:

CODE:
  1. mkdir factorysvn
  2. cd factorysvn
  3. svn co svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/trunk/ .

Now you can edit your rails project and commit your changes using subversion. That's it for today. Next we will setup our rails project to use Capistrano and deploy it to our server!

0 Responses to “Full Rails Stack Part Three: Project and Subversion”


  1. No Comments

Leave a Reply





March 2008
M T W T F S S
« Feb    
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Categories


Random Photos

  • IMG_2014.JPG
    Sunrise on the way to work
    IMG_2035.JPG
    IMG_0038.JPG


Now Reading

Planned books:

None

Current books:

  • The Consequences of Ideas: Understanding the Concepts that Shaped Our World

    The Consequences of Ideas: Understanding the Concepts that Shaped Our World by R. C. Sproul

  • Born Standing Up

    Born Standing Up by Steve Martin

Recent books:

View full Library