HowTo Automate repository creation

Version 24 (Etienne Massip, 2012-01-04 11:39)

1 1 Nicolas Chuche
h1. Automating repository creation
2 1 Nicolas Chuche
3 1 Nicolas Chuche
{{>TOC}}
4 1 Nicolas Chuche
5 4 Jean-Philippe Lang
h2. Overview
6 1 Nicolas Chuche
7 2 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/. 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.
8 1 Nicolas Chuche
9 8 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 -> Repository » and check *Enable WS for repository management*.
10 1 Nicolas Chuche
11 7 Eric Davis
Before going further, we need to choose some names, I will use @my.redmine.host@ as the redmine hostname and @my.svn.server@ as the svn server... You must create the directory where you want to put all your repositories, the owner must be root with your apache user as the group (e.g. @www-data@ on Debian/Ubuntu). I will use @/var/svn@ :
12 2 Nicolas Chuche
<pre>
13 2 Nicolas Chuche
mkdir /var/svn
14 7 Eric Davis
chown root:www-data /var/svn
15 2 Nicolas Chuche
chmod 0750 /var/svn
16 2 Nicolas Chuche
</pre>
17 1 Nicolas Chuche
18 2 Nicolas Chuche
We must also choose the directory apache will use to serve repositories to users, I choose @/svn@, so repository URL will look like http://my.svn.server/svn/PROJECTID/ and a last one, the directory apache will use for Redmine browsing, I will use @/svn-private/@.
19 1 Nicolas Chuche
20 2 Nicolas Chuche
And eventually, you need to know the name of apache user, as it's @www-data@ on debian/ubuntu. I will use this one.
21 2 Nicolas Chuche
22 4 Jean-Philippe Lang
h2. Warnings
23 2 Nicolas Chuche
24 10 Eric Davis
Notice that reposman.rb before re. 916 has a problem. You don't need to update redmine but just use the latest reposman.rb located in @extra/svn@.
25 2 Nicolas Chuche
26 2 Nicolas Chuche
The Perl reposman version is deprecated for new installation as it can't register and set the owner.
27 2 Nicolas Chuche
28 4 Jean-Philippe Lang
h2. Command line arguments
29 1 Nicolas Chuche
30 18 Felix Schäfer
It takes 3 mandatory arguments:
31 1 Nicolas Chuche
32 1 Nicolas Chuche
    * @svn-dir@: path to the directory where your svn repositories are located
33 1 Nicolas Chuche
    * @redmine-host@: host name of your Redmine install
34 18 Felix Schäfer
    * @key@: The key generated from GUI when enabling Repository management WS option. (Version 0.9 onwards)
35 1 Nicolas Chuche
36 1 Nicolas Chuche
And two optional arguments (added in re. 860):
37 1 Nicolas Chuche
38 2 Nicolas Chuche
    * @owner@: the owner of repositories
39 1 Nicolas Chuche
    * @url@: the base url Redmine will use to access your
40 1 Nicolas Chuche
             repositories. With this option, reposman will register the new
41 1 Nicolas Chuche
             repositories so that you will have nothing to do
42 1 Nicolas Chuche
    
43 2 Nicolas Chuche
The Perl reposman version is deprecated for new installation as it
44 2 Nicolas Chuche
can't register and set the owner.
45 1 Nicolas Chuche
46 1 Nicolas Chuche
h2. Question you should answer before going further
47 1 Nicolas Chuche
48 18 Felix Schäfer
If Redmine and your svn repositories are on the same server, you may use the file:/// protocol of svn to browse them, but even if it seems a good idea, if you later want to move repositories on another server, you will have a problem because you can't change repository path in redmine.
49 1 Nicolas Chuche
50 18 Felix Schäfer
The best approach to take is to set it up as if the repositories and redmine are already on two different servers and using network subversion to allow Redmine browsing.
51 1 Nicolas Chuche
52 1 Nicolas Chuche
If you want to use local browsing (the file:/// protocol), use @--url file:///var/svn/@ instead of.
53 2 Nicolas Chuche
54 5 Jean-Philippe Lang
h2. Automating repository creation to authenticate with apache/webdav and mod_perl
55 1 Nicolas Chuche
56 18 Felix Schäfer
Before going further, we will check that reposman can find the Redmine Web Service. *Do this as an unprivileged user* that can't write in /var/svn :
57 1 Nicolas Chuche
58 1 Nicolas Chuche
<pre>
59 20 Carl Perkins
ruby reposman.rb --redmine my.redmine.host --svn-dir /var/svn --owner www-data --url http://my.svn.server/svn-private/ --key=my_api_key --verbose
60 1 Nicolas Chuche
querying Redmine for projects...
61 1 Nicolas Chuche
retrieved 2 projects
62 1 Nicolas Chuche
treating project myproject
63 1 Nicolas Chuche
svnadmin: Repository creation failed
64 1 Nicolas Chuche
...
65 1 Nicolas Chuche
</pre>
66 1 Nicolas Chuche
67 18 Felix Schäfer
It's normal that the creation failed, you have no account rights, but the point is that reposman can find the Web Service and projects.
68 1 Nicolas Chuche
69 18 Felix Schäfer
If this doesn't work, make sure you have checked the *Enable WS for repository management* option.
70 1 Nicolas Chuche
71 6 Thomas Lecavelier
Now that you know everything is ok, you just need to invoke reposman.rb as root with the right options :
72 1 Nicolas Chuche
73 1 Nicolas Chuche
<pre>
74 2 Nicolas Chuche
  reposman.rb --redmine my.redmine.host --svn-dir /var/svn --owner www-data --url http://svn.server/svn-private/
75 2 Nicolas Chuche
</pre>
76 2 Nicolas Chuche
77 18 Felix Schäfer
Be careful with the @--url@ option, you can't change it if you later change your mind.
78 1 Nicolas Chuche
79 2 Nicolas Chuche
You can now add this line in your crontab :
80 2 Nicolas Chuche
81 1 Nicolas Chuche
<pre>
82 1 Nicolas Chuche
cat /etc/cron.d/redmine
83 2 Nicolas Chuche
10 * * * * root ruby reposman.rb --redmine my.redmine.host --svn-dir /var/svn --owner www-data --url http://my.svn.server/svn-private/ >> /var/log/reposman.log
84 1 Nicolas Chuche
</pre>
85 2 Nicolas Chuche
86 18 Felix Schäfer
It's allmost done.
87 1 Nicolas Chuche
88 1 Nicolas Chuche
h2. Web Service and Security
89 1 Nicolas Chuche
90 18 Felix Schäfer
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, you'll have to do your homework...) with the Location apache directive like this :
91 18 Felix Schäfer
92 1 Nicolas Chuche
<pre>
93 1 Nicolas Chuche
   <Location /sys>
94 12 Lars Scheithauer
      Order deny,allow
95 1 Nicolas Chuche
      Allow from ip.of.my.svn.server
96 12 Lars Scheithauer
      Deny from all
97 1 Nicolas Chuche
   </Location>
98 1 Nicolas Chuche
</pre>
99 1 Nicolas Chuche
100 1 Nicolas Chuche
So if you are using apache and mongrel, you will have something like that :
101 1 Nicolas Chuche
102 1 Nicolas Chuche
<pre>
103 1 Nicolas Chuche
<VirtualHost *:80>
104 1 Nicolas Chuche
   ServerName redmine.my.domain
105 1 Nicolas Chuche
   ServerAdmin webmaster@localhost
106 1 Nicolas Chuche
107 1 Nicolas Chuche
   <Location /sys>
108 11 Lars Scheithauer
      Order deny,allow
109 1 Nicolas Chuche
      Allow from ip.of.my.svn.server
110 11 Lars Scheithauer
      Deny from all
111 1 Nicolas Chuche
   </Location>
112 1 Nicolas Chuche
113 1 Nicolas Chuche
   ProxyPass / http://localhost:3000/
114 1 Nicolas Chuche
   ProxyPassReverse / http://localhost:3000/
115 1 Nicolas Chuche
</VirtualHost>
116 1 Nicolas Chuche
</pre>
117 9 Nicolas Chuche
118 9 Nicolas Chuche
You can now go to [[Repositories_access_control_with_apache_mod_dav_svn_and_mod_perl]] to enable apache access for your users
119 21 Andriy Lesyuk
120 24 Etienne Massip
See also "Subversion repository creator":http://www.redmine.org/plugins/redmine_svn plugin.