Monday, 18 September 2006

Getting Started with Subversion - Subversion + Apache

Subversion无痛起步 --- Subversion 1.4 + Apache 2.0

前一篇中,谈到了如何在日常的编码工作中,利用TortoiseSVN进行版本控制。,TortoiseSVN作为客户端程序,无疑是非常实用的,同时它也提供了基本的SVN Admin的功能。这对于个人应用来讲,基本够用了。如果开发项目需要多人合作,就需要建立Subversion Server。Subversion自带有一个svnserve作为Server,而目前比较流行的做法是,将SVN和Apache Web Server进行整合。这就是本篇所要介绍的内容。

首先是软件下载与安装。

0. Install Apache 2.0.59 into Windows, and make sure it works;
1. Download svn-1.4.0-setup.exe from here;
2. Install it into C:\Program Files\Subversion;
3. Add this folder, C:\Program Files\Subversion\bin, into the system
PATH;

安装好之后,要能够在CMD下,执行svn命令。

官方发行的Subversion for Windows,提供了和Apache 2.0服务器进行整合的modules。复制这两个模块到Apache 2的模块目录中;

4. Copy the two module files, mod_authz_svn.so and mod_dav_svn.so, from
C:\Program Files\Subversion\bin into the modules folder of Apache 2
(C:\...\Apache2\modules);

在CMD下,使用Subversion命令建立两个项目;

5. CMD, mkdir C:\svnroot\demosvn, C:\svnroot\foo;
6. CMD, cd C:\svnroot;
7. CMD, create two subversion repositories;
svnadmin create demosvn
svnadmin create foo

现在,修改Apache 2的配置文件,设置Load模块和svn路径。然后重启Apache 2;

8. Open the httpd.conf of Apache2, append the following two lines to it;
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
9. Add the following into the httpd.conf
<Location /svn>
DAV svn

# any "/svn/foo" URL will map to a repository C:\svnroot\foo
SVNParentPath C:/svnroot

</Location>
10. Restart Apache 2;

访问整合后的地址,http://localhost/svn/demosvn/。可以看到Subversion代码库的原始零状态;

11. In FireFox, access http://localhost/svn/demosvn/ to make sure you
get the message;
Revision 0: /

使用Subversion命令,建立项目的初始化目录结构。

12. CMD, mkdir C:\svntemp\branches\, C:\svntemp\tags\ and C:\svntemp
\trunk\;
13. Import the folders into the svnrepos. CMD, type the command as
below;
C:\svnroot>svn import -m "Initial the folders structure." c:\svntemp
http://localhost/svn/demosvn/
Adding C:\svntemp\trunk
Adding C:\svntemp\branches
Adding C:\svntemp\tags

Committed revision 1.

再次访问项目地址,现在可以看到项目初始化之后的状态。

14. Access http://localhost/svn/demosvn/ again in FireFox. Now, it will
be:
Revision 1: /

* branches/
* tags/
* trunk/

利用Apache 2提供的工具,产生用户和用户密码数据;

15. Generate the authenticated user and the password;
C:\svnroot>C:\...\Apache2\bin\htpasswd.exe -cm svn-auth.dat admin
New password: ******
Re-type new password: ******
Adding password for user admin

C:\svnroot>C:\...\Apache2\bin\htpasswd.exe -m svn-auth.dat onez
New password: *******
Re-type new password: *******
Adding password for user onez

C:\svnroot>C:\...\Apache2\bin\htpasswd.exe -m svn-auth.dat demouser
New password: ********
Re-type new password: ********
Adding password for user demouser

这里,建立了一个密码数据文件,包含了三个用户,adminonezdemouser,及各自的密码。

修改httpd.conf,重起Apache 2。现在只有授权用户可以访问svn项目。

16. Modify the httpd.conf like this;
<Location /svn>
DAV svn

# any "/svn/foo" URL will map to a repository C:\svnroot\foo
SVNParentPath C:/svnroot

# Authentication setting
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile C:/svnroot/svn-auth.dat

# only authenticated users may access the repository
Require valid-user

</Location>
17. Restart Apache 2 and access http://localhost/svn/demosvn/ again in
FireFox. Now, you will be asked to enter your user name and pass-
word.

设置对部分操作的访问限制,部分开放。

18. Modify the httpd.conf again;
<Location /svn>
DAV svn

# any "/svn/foo" URL will map to a repository C:\svnroot\foo
SVNParentPath C:/svnroot

# Authentication setting
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile C:/svnroot/svn-auth.dat

# For any operations other than these, require the authentication.
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>

</Location>
19. Restart Apache 2 and access http://localhost/svn/demosvn/ again. All
authenticated users has the 'write' right!!!

这里的设置,对所有的授权用户,赋予了相同的读写权限。对于小规模的合作项目,是合适的。

随着项目规模和人员数量的增加,就需要更加精细的权限控制。这就需要加入权限控制模块,和所需要的用户权限配置文件。

20. Set up more finer-grained permissions. Modify the httpd.conf, then
restart Apache 2
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

<Location /svn>
DAV svn

# any "/svn/foo" URL will map to a repository C:\svnroot\foo
SVNParentPath C:/svnroot

# Authentication setting
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile C:/svnroot/svn-auth.dat

# our access control policy
AuthzSVNAccessFile C:/svnroot/svn-access.dat

# try anonymous access first, resort to real
# authentication if necessary.
Satisfy Any
Require valid-user

</Location>
21. Create the access permissions file;
#
# Subversion Repository Access Permissions
#

[/]
* = r

[demosvn:/]
admin = rw
onez = rw
demouser = r
* =

[foo:/]
admin = rw
onez = rw
demouser = rw
* = r
22. Use the group setting;
#
# Subversion Repository Access Limitation
#

[groups]
demo-developers = admin, onez
foo-developers = admin, onez
everyone = demouser, @demo-developers, @foo-developers

[/]
* = r

[demosvn:/]
@demo-developers = rw
demouser = r
* =

[foo:/]
#@foo-developers = rw
everyone = rw
* = r

在权限配置文件中,可以将用户进行分组管理;针对不同项目的不同目录,进行相应的权限控制。

配置显示模板;

23. Download svnindex.xsl and svnindex.css and put into
C:\...\Apache2\htdocs;
24. Update the httpd.conf;
<Location /svn>
DAV svn

# any "/svn/foo" URL will map to a repository C:\svnroot\foo
SVNParentPath C:/svnroot
SVNIndexXSLT "/svnindex.xsl"

...

</Location>

显示模板,其实也只是在样式上好看了一点点,最终还是只能显示最后一个版本的内容。Subversion和Apache 2.0整合的最大用处,是利用Apache 2的dav模块,提供开发人员一个方便存取源代码的途径。

单看Web Page,这种整合实在不怎么样!如果Web Display很重要的话,可以进一步考虑使用ViewCVS这样的专门软件,那又是另外一个话题了。当然,Subversion无痛起步,最终要呈现的是...

0 Comments:

Post a Comment

<< Home