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:
-
rails --d=mysql factory
-
cd factory
-
rake db:create
-
script/generate scaffold widget name:string description:text
-
rake db:migrate
Now let's test our site to make sure everything is working correctly:
-
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:
-
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.:
-
nano config/routes.rb
Paste the following before the 'end' at the bottom of the file
-
map.root :controller => "widgets"
Save the file and restart the server:
-
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:
-
sudo apt-get install subversion subversion-tools libsvn-dev libsvn1
Install ssh:
-
sudo apt-get install ssh
Create our repository:
-
sudo svnadmin create /var/svn/mycode
-
sudo chown -R deploy:deploy /var/svn/mycode
Edit the svnserve config file:
-
sudo nano /var/svn/clickhere/conf/svnserve.conf
Modify the following lines
-
anon-access = none
-
auth-access = write
-
authz-db = /usr/local/nginx/conf/svn_access.rules
-
realm = My Code Repository
Create the access rules file:
-
sudo nano /usr/local/nginx/conf/svn_access.rules
Paste in the following and save the file:
-
[groups]
-
developers = deploy
-
qc = deploy
-
pm = deploy
-
[/]
-
-
@developers = rw
-
@qc = r
-
@pm = r
Create a svnserve startup file:
-
sudo nano /etc/init.d/svnserve
Paste in the following:
-
#!/bin/sh
-
-
# Use the following variables to customize user, group, and paths.
-
SVNSERVE=`which svnserve`
-
SVN_USER=deploy
-
SVN_GROUP=deploy
-
SVN_ROOT_PATH=/var/svn/mycode/
-
-
if [ -f /etc/rc.d/init.d/functions ]; then
-
# RedHat style
-
. /etc/rc.d/init.d/functions
-
START="daemon $SVNSERVE -d --root $SVN_ROOT_PATH"
-
STOP="killproc $SVNSERVE"
-
else
-
# Ubuntu LSB style
-
. /lib/lsb/init-functions
-
START="start-stop-daemon --start --exec $SVNSERVE -- -d --root $SVN_ROOT_PATH"
-
STOP="start-stop-daemon --stop --exec $SVNSERVE"
-
fi
-
-
if [ ! -x $SVNSERVE ]; then
-
echo "Could not find ${SVNSERVE}. PATH is ${PATH}"
-
exit 0
-
fi
-
-
case "$1" in
-
start)
-
echo "Starting svnserve..."
-
umask 002
-
$START
-
if [ $? ]; then
-
echo "Started svnserve"
-
exit 0
-
else
-
exit $?
-
fi
-
;;
-
-
stop)
-
echo "Stopping svnserve..."
-
$STOP
-
exit $?
-
;;
-
-
restart|force-reload)
-
"$0" stop && "$0" start
-
;;
-
-
*)
-
echo "Usage: /etc/init.d/svnserve {start|stop|restart|force-reload}"
-
exit 1
-
;;
-
esac
-
-
echo "Unhandled case while trying to start svnserve."
-
echo "see $0"
-
exit 3
Make it executable:
-
sudo chmod +x /etc/init.d/svnserve
Add it to the startup scripts:
-
sudo update-rc.d /etc/init.d/svnserve defaults
Start the server:
-
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
-
sudo nano ~/.subversion/conf
Add the following line inside the [tunnels] section
-
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:
-
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.
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/branches
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/branches/experiments
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/branches/releases
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/branches/tickets
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/tags
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/tags/notable_moments
-
svn mkdir -m "Creating factory project for me" svn+widgets://your_linux_box.com/var/svn/mycode/projects/me/factory/tags/releases
-
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:
-
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:
-
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:
-
mkdir factorysvn
-
cd factorysvn
-
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!
Tags: Rails, ruby on rails, setup, subversion







Leave a reply