HowTo Automate repository creation

Version 1 (Nicolas Chuche, 2007-11-18 20:13)

1 1 Nicolas Chuche
h1. Automating repository creation
2 1 Nicolas Chuche
3 1 Nicolas Chuche
{{>TOC}}
4 1 Nicolas Chuche
5 1 Nicolas Chuche
h2. overview
6 1 Nicolas Chuche
7 1 Nicolas Chuche
As of version 0.5.0, Redmine is able to handle Subversion repository creation. This is done by reposman.rb a script found in extra/svn/.
8 1 Nicolas Chuche
9 1 Nicolas Chuche
Projects are retrieved from Redmine using a SOAP web service. This web service is disabled by default in Redmine.  To enable it, go to « Administration -> Settings » and check *Enable WS for repository management*.
10 1 Nicolas Chuche
11 1 Nicolas Chuche
With a recent version of Redmine (0.6.0 or re. 860 and later), reposman.rb can register the new repository in Redmine for you and set the owner of repository to who you want. If you have an older version, you will have to register repositories by yourself.
12 1 Nicolas Chuche
13 1 Nicolas Chuche
Notice that reposman.rb before re 916 has a right problem. You don't need to update redmine, just "reposman.rb":http://redmine.rubyforge.org/svn/trunk/extra/svn/reposman.rb
14 1 Nicolas Chuche
15 1 Nicolas Chuche
h2. command line arguments
16 1 Nicolas Chuche
17 1 Nicolas Chuche
It takes 2 mandatory arguments:
18 1 Nicolas Chuche
19 1 Nicolas Chuche
    * @svn-dir@: path to the directory where your svn repositories are located
20 1 Nicolas Chuche
    * @redmine-host@: host name of your Redmine install
21 1 Nicolas Chuche
22 1 Nicolas Chuche
And two optional arguments (added in re. 860):
23 1 Nicolas Chuche
24 1 Nicolas Chuche
    * @owner@: the files owner
25 1 Nicolas Chuche
    * @url@: the base url Redmine will use to access your
26 1 Nicolas Chuche
             repositories. With this option, reposman will register the new
27 1 Nicolas Chuche
             repositories so that you will have nothing to do
28 1 Nicolas Chuche
    
29 1 Nicolas Chuche
The Perl reposman version is deprecated for new installation as it can't register and set the owner.
30 1 Nicolas Chuche
31 1 Nicolas Chuche
h2. question you should answer before going further
32 1 Nicolas Chuche
33 1 Nicolas Chuche
If Redmine and your svn repositories are on the same server, you can use the file:/// protocol of svn to browse them, but even if it seems a good idea, if later you want to move repositories on another server, you will have a problem because you can't change repository path in redmine for now.
34 1 Nicolas Chuche
35 1 Nicolas Chuche
The best way I can think of now is to do as if repositories and redmine are already on two different servers and using network subversion to allow Redmine browsing.
36 1 Nicolas Chuche
37 1 Nicolas Chuche
h2. automating repository creation to authenticate with apache/webdav and mod_perl
38 1 Nicolas Chuche
39 1 Nicolas Chuche
You need a reposman.rb re. 916 or later. If you have an older one, you just need to update "reposman.rb":http://redmine.rubyforge.org/svn/trunk/extra/svn/reposman.rb not Redmine.
40 1 Nicolas Chuche
41 1 Nicolas Chuche
You just need to invoke resposman.rb with the righ options :
42 1 Nicolas Chuche
43 1 Nicolas Chuche
<pre>
44 1 Nicolas Chuche
  reposman.rb --redmine my.redmine.host --svn-dir /var/svn --owner www-data --url http://svn.server/svn-private/
45 1 Nicolas Chuche
</pre>
46 1 Nicolas Chuche
47 1 Nicolas Chuche
FIXME go to ...
48 1 Nicolas Chuche
49 1 Nicolas Chuche
h2. testing and debugging
50 1 Nicolas Chuche
51 1 Nicolas Chuche
You can launch the script by hand with the @--verbose@ option with a user *that can't write* in the repository directory, you should have something like this :
52 1 Nicolas Chuche
53 1 Nicolas Chuche
<pre>
54 1 Nicolas Chuche
ruby reposman.rb --redmine my.redmine.host --svn-dir /var/svn --owner www-data --url http://svn.my.domain/svn/ --verbose
55 1 Nicolas Chuche
querying Redmine for projects...
56 1 Nicolas Chuche
retrieved 2 projects
57 1 Nicolas Chuche
treating project myproject
58 1 Nicolas Chuche
svnadmin: Repository creation failed
59 1 Nicolas Chuche
...
60 1 Nicolas Chuche
</pre>
61 1 Nicolas Chuche
62 1 Nicolas Chuche
It's normal the creation failed, you have no right, but the good point is that reposman find the Web Service and projects.
63 1 Nicolas Chuche
64 1 Nicolas Chuche
If this doesn't work, make sure you have check the *Enable WS for repository management* option.
65 1 Nicolas Chuche
66 1 Nicolas Chuche
You can now add it in your crontab :
67 1 Nicolas Chuche
68 1 Nicolas Chuche
<pre>
69 1 Nicolas Chuche
cat /etc/cron.d/redmine
70 1 Nicolas Chuche
10 * * * * root ruby reposman.rb --redmine my.redmine.host --svn-dir /var/svn --owner www-data --url http://svn.my.domain/svn/ >> /var/log/reposman.log
71 1 Nicolas Chuche
</pre>
72 1 Nicolas Chuche
73 1 Nicolas Chuche
h2. Web Service and Security
74 1 Nicolas Chuche
75 1 Nicolas Chuche
For the moment, the WS is open to everybody once actived and you surely don't want that someone register repository's project for you. You can block access to the WS with apache (if you don't use apache, I let you do your homework...) with the Location apache directive like this :
76 1 Nicolas Chuche
77 1 Nicolas Chuche
<pre>
78 1 Nicolas Chuche
   <Location /sys>
79 1 Nicolas Chuche
      Order allow,deny
80 1 Nicolas Chuche
      Allow from ip.of.my.svn.server
81 1 Nicolas Chuche
   </Location>
82 1 Nicolas Chuche
</pre>
83 1 Nicolas Chuche
84 1 Nicolas Chuche
So if you are using apache and mongrel, you will have something like that :
85 1 Nicolas Chuche
86 1 Nicolas Chuche
<pre>
87 1 Nicolas Chuche
<VirtualHost *:80>
88 1 Nicolas Chuche
   ServerName redmine.my.domain
89 1 Nicolas Chuche
   ServerAdmin webmaster@localhost
90 1 Nicolas Chuche
91 1 Nicolas Chuche
   <Location /sys>
92 1 Nicolas Chuche
      Order allow,deny
93 1 Nicolas Chuche
      Allow from ip.of.my.svn.server
94 1 Nicolas Chuche
   </Location>
95 1 Nicolas Chuche
96 1 Nicolas Chuche
   ProxyPass / http://localhost:3000/
97 1 Nicolas Chuche
   ProxyPassReverse / http://localhost:3000/
98 1 Nicolas Chuche
</VirtualHost>
99 1 Nicolas Chuche
</pre>