Monday, December 29, 2008

Plone deployment using buildout

Prerequisites
* python2.4
* python-devel
* python-imaging - Python Imaging Library
* python-setuptools - setuptools

Under Ubuntu use:
$ sudo apt-get install python2.4 build-essential python2.4-dev python-imaging python-setuptools

Under openSUSE use:
$ sudo zypper in python-2.4 python-2.4-devel python-2.4-imaging python-2.4-xml

If you're using Linux and your distribution doesn't provide a package for setuptools, download ez_setup.py and run it with:
$ python2.4 ez_setup.py

Note: I got error here saying that directory structure doesn't exists. In that case just create it with mkdir command and try again:
mkdir -p /usr/local/lib64/python2.4/site-packages

This will download and install setuptools and the easy_install script. Watch the console output to understand where easy_install is installed. If this is not in your system PATH, you should add this directory to the path as well by adding following to lines to the end of $HOME/.bash_profile for one user, /etc/profile for all users except root, and /root/.bash_profile for root user.
PATH=$PATH:/path/to/easy_install
export PATH

Installation
$ sudo easy_install-2.4 -U ZopeSkel
$ cd /home/'your_username'
$ paster create --list-templates
$ paster create -t plone3_buildout myPloneProject
-----------------------------------------------------------------------------------
Enter zope2_install (Path to Zope 2 installation; leave blank to fetch one) ['']:
Enter plone_products_install (Path to directory containing Plone products; leave blank to fetch one) ['']:
Enter zope_user (Zope root admin user) ['admin']:
Enter zope_password (Zope root admin password) ['']: passwd
Enter http_port (HTTP port) [8080]:
Enter debug_mode (Should debug mode be "on" or "off"?) ['off']: on
Enter verbose_security (Should verbose security be "on" or "off"?) ['off']: on
-----------------------------------------------------------------------------------

Enter directory with created template:
$ cd myPloneProject

Create base directory structure, including scripts and latest version of the zc.buildout egg, for created template:
$ python2.4 bootstrap.py

Next step is time-consuming so after typing next command go for coffee. If you have some download running in background, stop it before doing online build with:
$ ./bin/buildout -v

This reads the generated buildout.cfg file and executes its various "parts", setting up Zope, creating a Zope instance, downloading and installing Plone.

You will need to run ./bin/buildout again each time you change buildout.cfg. If you do not want buildout to go online and look for updated versions of eggs or download other archives, you can run it in non-updating, offline mode, with using -o switch:
$ ./bin/buildout -o

Start your Zope instance in foreground so you can see debug info in console:
$ ./bin/instance fg

Start your Zope instance as background process in daemon mode:
$ ./bin/instance start

To run test use:
$ ./bin/instance test -s plone.portlets

Stop your instance with:
$ ./bin/instance stop

Resource:
http://plone.org/documentation/tutorial/buildout/tutorial-all-pages

Wednesday, December 17, 2008

Subversion with apache on Centos

I used Centos4 as OS on which I installed subversion with apache. It was painful three days but it was sucess at the end. Before we start with this I have to say couple of important things:
subversion 1.4.x will work with apache-2.0.x cause they relay on APR 0.9.x module, and
subversion-1.5.x will work with apache-2.2.x cause they relay on APR 1.3.x module.
APR 0.9.x and APR 1.3.x are not compatibile, and because of that, subversion 1.5.x will not work with apache-2.0.x. Same case is probably with subversion 1.4.x and apache-2.2.x combination. When installing subversion modules for apache from source you'll need to tell to configuration where are APR and APR-UTIL libraries. You can use these libraries from apache source or from subversion. I decided to use APR and APR-UTIL libraries from apache source.

Subversion uses a lot of other programs and libraries which need to be installed before using the subversion package. So to simplify things I'll try using yum as much as possible.

Update your version of apache and install subversion that fits this version of apache using yum:
yum upgrade httpd

Add repos to yum:
joe /etc/yum.repos.d/dag.repo

[dag]
Name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
gpgcheck=1
enabled=1

Then install these packages:
yum install httpd-devel
yum install subversion

Check the version of your installed apache (2.0.52 in my case) using:
yum info httpd

and download apropriate source using:
wget http://apache.blic.net/httpd/httpd-2.0.63.tar.gz

There is no source for 2.0.52 any more so I used 2.0.63 with crossed fingers.
tar xfz httpd-2.0.63.tar.gz
cd httpd-2.0.63

cd apr
./configure --prefix=/usr/local/apr
make
make install
cd ..

cd apr-util
./configure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr/
make
make install
cd ..

Check the version of your installed subversion (1.4.6 in my case) using:
yum info subversion

and download apropriate source using:
wget http://subversion.tigris.org/downloads/subversion-deps-1.4.6.tar.gz
wget http://subversion.tigris.org/downloads/subversion-1.4.6.tar.gz

tar xfz subversion-1.4.6.tar.gz
tar xfz subversion-deps-1.4.6.tar.gz
cd subversion-1.4.6

rm -f /usr/local/lib/libsvn*
rm -f /usr/local/lib/libapr*
rm -f /usr/local/lib/libexpat*
rm -f /usr/local/lib/libneon*
sh ./autogen.sh

./configure --with-apxs=/usr/sbin/apxs \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-utils/
make
make install

At this point you will have included two svn modules in httpd.conf file which is why we did compiling from source.

Make your project for first revision of repository
mkdir -v /usr/local/svn-projects
mkdir -v /usr/local/svn-projects/htdocs
joe /usr/local/svn-projects/htdocs/index.html
chown -Rv apache.apache /usr/local/svn-projects

Make your repository
mkdir -v /usr/local/subversion/
/usr/local/bin/svnadmin create --fs-type fsfs /usr/local/subversion/repository
chown -Rv apache.apache /usr/local/subversion
ls /usr/local/subversion/repository

Edit httpd.conf.
Check that there are two loaded svn modules.
LoadModule dav_svn_module /usr/lib/httpd/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/httpd/modules/mod_authz_svn.so

Add this code to apache httpd.conf:
< Location /subversion>
DAV svn
SVNPath /usr/local/subversion/repository/
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /usr/local/subversion/repository/conf/svn-auth-file
Require valid-user
</Location>

Add new users. For first user:
htpasswd -cmd /usr/local/subversion/repository/conf/svn-auth-file {user-name}

For every other user:
htpasswd -md /usr/local/subversion/repository/conf/svn-auth-file {user-name}

Prepare files for repository and import your project to repository:
mkdir -pv /tmp/subversion-layout/{branches,tags}
mv -v /usr/local/svn-projects/htdocs /tmp/subversion-layout/trunk
export SVN_EDITOR=joe
/usr/local/bin/svn import /tmp/subversion-layout/ http://127.0.0.1/subversion/

Make your working copy:
cd /usr/local/svn-projects/
/usr/local/bin/svn checkout http://127.0.0.1/subversion/trunk/ htdocs

Make post-commit hook to get fresh working copy:
cp -v /usr/local/subversion/repository/hooks/post-commit.tmpl /usr/local/subversion/repository/hooks/post-commit
chmod +x /usr/local/subversion/repository/hooks/post-commit

Edit post-commit hook by commenting two last lines and by adding one line like this:
#commit-email.pl "$REPOS" "$REV" commit-watchers@example.org
#log-commit.py --repository "$REPOS" --revision "$REV"
/usr/bin/svn update /usr/local/svn-projects/htdocs/ --username svn_user --password svn_pass --non-interactive >> /usr/local/subversion/repository/logs/post-commit.log

Make log file for created hook:
mkdir -v /usr/local/subversion/repository/logs/
touch /usr/local/subversion/repository/logs/post-commit.log
chown -Rv apache.apache /usr/local/subversion/ /usr/local/svn-projects/

Restart your apache and you'll have your first revision working:
/bin/sbin/httpd -k restart

Cheers!