2005년 7월 22일 금요일

CVS 커밋 발생시점에 소스 export 하기

지금 개발 하고 있는 환경이 주로 PHP를 이용한 개발 이라 CVS에서 소스를 가져와서 수정하고 SFTP로 테스트 서버에 전송 확인한 후에
CVS에 커밋을 하는 작업이 발생한다.

이제껏 자바 개발의 경우 소스를 CVS에 커밋 한다고 해도 매번 컴파일작업이 발생하기 때문에 개발 효율은 그리 높지 않았다.
PHP의 생산성은 자바와는 비교가 되지 않을 정도 이지만 위에서 언급한 CVS커밋 작업과 서버에전송작업이 업무 효율을 떨어뜨리는 원인이 되고 있었다.

PHP의 경우 commit한 것을 wep page를 통해 확인 하기 때문에 CVS 와 아파치 DocumentRoot를 연결해 두면 작업한 소스를 CVS 에 커밋 하는 것만으로 확인이 가능해 진다.

이하는 이를 위한 설정 이다.

CVSROOT위치 /home/cvs/
모듈명 bin
아파치 DocumentRoot /home/apache/doc

bin모듈에 소스를 커밋 하면 /home/apache/doc/bin 에 변경한 것이 반영되도록 한다.

[root@xxxx root]# cd /home/cvs
[root@xxxx cvs]# ls
bin CVSROOT cvstest test

만들어 주어야 하는 파일
auto_update.pl
binUpdate.sh

[root@xxxx CVSROOT]# view auto_update.pl
#!/usr/bin/perl
#cvs path
$cvs = '/usr/bin/cvs';
$usage = "usage: auto_update.pl WORKDIR [MODE]";
# process arguments
die $usage, "
" unless $workdir = $ARGV[0];
$chmod = $ARGV[1] ? "; chmod -R $ARGV[1]" : "";
# main update process which must be executed in background.
$cmd = "(cd $workdir; $cvs -q update $chmod) &";
system($cmd);
# last message.
$date = `date`; chomp($date);
$mesg = "$workdir automatically updated at $date";
print "$mesg
";

[root@xxxx CVSROOT]# view binUpdate.sh
#!/bin/sh
/home/cvs/CVSROOT/auto_update.pl /home/apache/doc


수정해 주어야 하는 파일
loginfo에 이하의 내용을 추가해 주면 된다.

bin /home/cvs/CVSROOT/binUpdate.sh bin


[root@xxxx CVSROOT]# view loginfo
# The "loginfo" file controls where "cvs commit" log information
# is sent. The first entry on a line is a regular expression which must match
# the directory that the change is being made to, relative to the
# $CVSROOT. If a match is found, then the remainder of the line is a filter
# program that should expect log information on its standard input.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name ALL appears as a regular expression it is always used
# in addition to the first matching regex or DEFAULT.
#
# You may specify a format string as part of the
# filter. The string is composed of a `%' followed
# by a single format character, or followed by a set of format
# characters surrounded by `{' and `}' as separators. The format
# characters are:
#
# s = file name
# V = old version number (pre-checkin)
# v = new version number (post-checkin)
# t = tag or branch name
#
# For example:
#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
# or
#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog

bin /home/cvs/CVSROOT/binUpdate.sh bin


---------주의 사항---------
퍼미션 관련 에러에 조심하기만 하면 아무 문제 없이
커밋한 소스를 아파치DocumentRoot 에 밀어주게 된다.

아파치 DocumentRoot의 유저 가 xxx라면
cvs의 그룹에 xxx를 등록해 주면 된다.

[root@xxx CVSROOT]# vi /etc/group
xxx:x:502:cvs사용유저1 ,cvs사용유저1,cvs사용유저2
cvs:x:503:cvs사용유저1,cvs사용유저1,cvs사용유저2,xxx


/home/apache/doc/에서
cvs checkout bin을 먼저 실행해 bin을 체크 아웃 해두는 것도 잊지 말아야 한다.
checkout시 bin 에 lock관련 정보를 write할수 없다는 에러가 발생하면 chgrp -R bin해주면 되겠죠...

댓글 없음: