Project

General

Profile

HowTo Automate repository creation » History » Version 17

David Fahmy, 2010-10-19 09:54

1 1 Nicolas Chuche
h1. Automating repository creation
2
3
{{>TOC}}
4
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
mkdir /var/svn
14 7 Eric Davis
chown root:www-data /var/svn
15 2 Nicolas Chuche
chmod 0750 /var/svn
16
</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
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
The Perl reposman version is deprecated for new installation as it can't register and set the owner.
27
28 4 Jean-Philippe Lang
h2. Command line arguments
29 1 Nicolas Chuche
30 17 David Fahmy
It takes 2 mandatory arguments:
31 1 Nicolas Chuche
32
    * @svn-dir@: path to the directory where your svn repositories are located
33 15 Enterux Solutions
    * @redmine-host@: host name of your Redmine install
34 1 Nicolas Chuche
35
And two optional arguments (added in re. 860):
36
37 2 Nicolas Chuche
    * @owner@: the owner of repositories
38 1 Nicolas Chuche
    * @url@: the base url Redmine will use to access your
39
             repositories. With this option, reposman will register the new
40
             repositories so that you will have nothing to do
41
    
42 2 Nicolas Chuche
The Perl reposman version is deprecated for new installation as it
43
can't register and set the owner.
44 1 Nicolas Chuche
45
h2. Question you should answer before going further
46
47 17 David Fahmy
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 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.
48 1 Nicolas Chuche
49 17 David Fahmy
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.
50 1 Nicolas Chuche
51
If you want to use local browsing (the file:/// protocol), use @--url file:///var/svn/@ instead of.
52 2 Nicolas Chuche
53 5 Jean-Philippe Lang
h2. Automating repository creation to authenticate with apache/webdav and mod_perl
54 1 Nicolas Chuche
55 17 David Fahmy
Before going further, we will check that reposman find the Redmine Web Service. *Do this as an unprivileged user* that can't write in /var/svn :
56 1 Nicolas Chuche
57
<pre>
58 2 Nicolas Chuche
ruby reposman.rb --redmine my.redmine.host --svn-dir /var/svn --owner www-data --url http://my.svn.server/svn-private/ --verbose
59 1 Nicolas Chuche
querying Redmine for projects...
60
retrieved 2 projects
61
treating project myproject
62
svnadmin: Repository creation failed
63
...
64
</pre>
65
66 17 David Fahmy
It's normal the creation failed, you have no right, but the good point is that reposman find the Web Service and projects.
67 1 Nicolas Chuche
68 17 David Fahmy
If this doesn't work, make sure you have check the *Enable WS for repository management* option.
69 1 Nicolas Chuche
70 6 Thomas Lecavelier
Now that you know everything is ok, you just need to invoke reposman.rb as root with the right options :
71 1 Nicolas Chuche
72
<pre>
73 2 Nicolas Chuche
  reposman.rb --redmine my.redmine.host --svn-dir /var/svn --owner www-data --url http://svn.server/svn-private/
74
</pre>
75
76 17 David Fahmy
Be careful with the @--url@ option, you can't change it if you change your thought after.
77 1 Nicolas Chuche
78 2 Nicolas Chuche
You can now add this line in your crontab :
79
80 1 Nicolas Chuche
<pre>
81
cat /etc/cron.d/redmine
82 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
83 1 Nicolas Chuche
</pre>
84 2 Nicolas Chuche
85 17 David Fahmy
It's allmost done for this part.
86 1 Nicolas Chuche
87
h2. Web Service and Security
88
89 17 David Fahmy
For the moment, the WS is open to everybody once actived and you surely don't want that someone register repository's "term paper":http://www.besttermpaper.com/ 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 :
90
"term papers":http://www.ghostpapers.com/
91 1 Nicolas Chuche
<pre>
92
   <Location /sys>
93 12 Lars Scheithauer
      Order deny,allow
94 1 Nicolas Chuche
      Allow from ip.of.my.svn.server
95 12 Lars Scheithauer
      Deny from all
96 1 Nicolas Chuche
   </Location>
97
</pre>
98
99
So if you are using apache and mongrel, you will have something like that :
100
101
<pre>
102
<VirtualHost *:80>
103
   ServerName redmine.my.domain
104
   ServerAdmin webmaster@localhost
105
106
   <Location /sys>
107 11 Lars Scheithauer
      Order deny,allow
108 1 Nicolas Chuche
      Allow from ip.of.my.svn.server
109 11 Lars Scheithauer
      Deny from all
110 1 Nicolas Chuche
   </Location>
111
112
   ProxyPass / http://localhost:3000/
113
   ProxyPassReverse / http://localhost:3000/
114
</VirtualHost>
115
</pre>
116 9 Nicolas Chuche
117
You can now go to [[Repositories_access_control_with_apache_mod_dav_svn_and_mod_perl]] to enable apache access for your users