Subversion

    How to start with Subversion in Amazon EC2?

    The Subversion EC2 AMI configures a Subversion repository and Apache server to show it. The default configuration is using "svnserver" but you can use other methods (like SSH) to access your repository.

    Before starting the instance, you should take into account that the default Subversion port is 3690 so it is necessary to open this port in your security group.

    Once the instance is running, you can log in through SSH and configure the repository access. The repository configuration file is /opt/bitnami/repository/svnserve.conf. The variables anon-access  and auth-access can be set to the values none, read, or write. Setting the value to none prohibits both reading and writing; read allows read-only access to the repository, and write allows complete read/write access to the repository. For example, you can uncomment these lines:

    [general]
    anon-access = read
    auth-access = write
    password-db = passwd
    

    You can edit the "passwd" file at the same directory to manage subversion users. For example, if you uncomment these lines you create two subversion users; harry and sally.

    [users]
    harry = harryssecret
    sally = sallyssecret
    

    Then restart the Subversion server to load the changes.

    $ sudo /opt/bitnami/ctlscript.sh restart subversion
    

    Finally you can import a project directory to subversion server from your local machine and show the files in the browser.

    $ svn import /path/to/project/ svn://ec2-xx-yy-zz.compute-1.amazonaws.com/repository/ -m "first import"
    

    How to start the Subversion server: svnserver?

    By default, the "svnserver" is running in the Stacks and you can configure it. The default port is 3690.

    BitNami Cloud Hosting users have to open this port. Please check our BitNami Cloud Hosting FAQ to get more info.

    The repository's svnserve.conf file is the central mechanism for controlling authentication and authorization policies. You can edit this file in /installdir/repository/conf/svnserve.conf. If you want to create a different repository you can create it manually:

    win_platform.png On Windows: Go to BitNami Console console and run the following command:

    > svnadmin create “C:\new_repository_path”

    linux_platform.png

    On Linux andmac_platform.png OS X: 

    Go to a BitNami Console and then run the following command:

    $ svnadmin create /path/to/new/repository


    The variables anon-access  and auth-access can be set to the values none, read, or write. Setting the value to none prohibits both reading and writing; read allows read-only access to the repository, and write allows complete read/write access to the repository. For example, you can uncomment these lines:
     

    [general]
    anon-access = read
    auth-access = write
    password-db = passwd
    

    You can edit passwd file at the same directory to manage subversion users. For example, if you uncomment these lines you create two subversion users; harry and sally.

    [users]
    harry = harryssecret
    sally = sallyssecret
    

    It is necessary to restart "svnserve" to apply the changes. Finally you can import a project directory to subversion.

    $ svn import /path/to/project/ svn://localhost/repository/ -m "first import"
    

    How to configure your Subversion repository though SSH?

    This guide describes how to create a repository in your Virtual Machine or AMI to access remotely through SSH.

    First, connect to your machine via SSH and execute the following commands to create your repositories directory /installdir/repositories and your subversion repository myapp:

    $ sudo mkdir /opt/bitnami/repositories
    $ sudo chown -R bitnami:bitnami /opt/bitnami/repositories
    $ svnadmin create /opt/bitnami/repositories/myapp
    

    Assign your repository to your Redmine project. In Redmine go to your project Settings/Repository section and add the following value in the URL field (login and password are not necessary):

    file:///opt/bitnami/repositories/myapp

    Now you need to check if you have subversion binaries in the PATH even in the non-interactive SSH session. Try to execute the following command:

    ssh -l bitnami -i /path/to/bitnami-hosting.pem mymachine.bitnamiapp.com svn
    

    If you get "command not found" error, then you will need to  update your /home/bitnami/.bashrc, and move all BitNami PATH configuration from the bottom of this file to the top, above the following entry "[ -z "$PS1" ] && return"

    Checkout your repository now, start adding and commiting new files. Your repository is available remotely via the following url (please configure your Subversion client with your login: bitnami and SSH key):

    svn+ssh://mymachine.bitnamiapp.com/opt/bitnami/repositories/myapp

    To add example file to your repository execute the following commands on you local machine (Unix only):

    $ export SVN_SSH="ssh -l bitnami -i /path/to/bitnami-hosting.pem"
    $ svn checkout svn+ssh://mymachine.bitnamiapp.com/opt/bitnami/repositories/myapp
    Checked out revision 0.
    $ cd myapp
    $ echo "This is a simple test" > Readme.txt
    $ svn add Readme.txt
    A         Readme.txt
    $ svn commit -m "Adding simple readme file, closes #1"
    Adding         Readme.txt
    Transmitting file data .
    Committed revision 1.
    

    How to see the Subversion repository from the web browser?

    If you prefer you can add the following configuration to the Apache configuration file /installdir/apache2/conf/httpd.conf

    ...
    LoadModule dav_module modules/mod_dav.so
    LoadModule dav_fs_module modules/mod_dav_fs.so
    ..
    LoadModule dav_svn_module     modules/mod_dav_svn.so                                                 
    LoadModule authz_svn_module   modules/mod_authz_svn.so
    
    ...
    <Location /new_site_name>                                  
      DAV svn                                                                         
      SVNPath "/path/to/subversion/repository"                                         
    </Location>
    

    Then restart Apache:

    $ /installdir/ctlscript.sh restart apache
    
    Enabling HTTPS

    You can also access through HTTPS if you already configured the Apache SSL certificate for your server. The following error can happen when the hostname reported by the server does not the match hostname given in the SSL certificate. Make sure your server configuration uses correct value for ServerName.

    svn: OPTIONS of 'https://example.com/repository': SSL negotiation failed: SSL error code -1/1/336032856 (https://example.com)
     

    How to configure basic authentication for your repository?

    Once you are able to access your repository, it is possible to configure Apache basic authentication for different users. The configuration below allows you create a "/opt/bitnami/repository/users" file with the user credentials for the repository.

    <Location /subversion>
     DAV svn
     SVNPath "/opt/bitnami/repository"
     AuthType Basic
     AuthName "Subversion repository"
     AuthUserFile /opt/bitnami/repository/users
     require valid-user
    </Location>
     
    In order to create this file, you can run the following command:
    htpasswd -c  /opt/bitnami/repository/users newuser
    New password:

    If you want to add more users to the same file, you can remove the "-c" option to not overwrite the file and only append new users:

    htpasswd /opt/bitnami/repository/users otheruser

    Then restart the Apache server.

    How to enable post commit notifications via email for Subversion?

    In this section we will check how to configure a Subversion repository to send emails via SMTP with the commit log.

    Download the latest source code from Subversion and copy the hooks folder into the subversion folder:

    wget  http://apache.mesi.com.ar/subversion/subversion-1.8.9.tar.gz
    tar -xzvf subversion-1.8.9.tar.gz
    sudo cp -r subversion-1.8.9/tools/hook-scripts /opt/bitnami/subversion/hooks

    Then configure the SMTP mail settings in the "mailer.conf" file:

    sudo cp /opt/bitnami/subversion/hooks/mailer/mailer.conf.example /opt/bitnami/subversion/hooks/mailer/mailer.conf

    And edit the file to add the SMTP settings. In this example we are going to use the SMTP settings for a Gmail account:

    [General]
    smtp_hostname = smtp.gmail.com:587
    smtp_username = your_gmail_account
    smtp_password = your_password
    smtp_use_ssl = true
    
    ...
    
    [defaults]
    from_addr = mail@example.com
    
    # The default To: addresses for message.  One or more addresses,
    # separated by whitespace (no commas).
    # NOTE: If you want to use a different character for separating the
    #       addresses put it in front of the addresses included in square
    #       brackets '[ ]'.
    to_addr = mail@example.com
    
    # If this is set, then a Reply-To: will be inserted into the message.
    reply_to = mail@example.com

     

    If you use a Gmail account or you need to use a SSL connection for your SMTP settings, you need to modify SMTPOutput class in "mailer.py" in order to use added “smtp_use_ssl” setting. This patch was submited by Alexey Samodov:

    @@ -278,6 +278,12 @@
       def finish(self):
         server = smtplib.SMTP(self.cfg.general.smtp_hostname)
    +   # 2009-12-13 asadomov: add ssl configuration (e.g. for gmail smtp server)
    +    if self.cfg.is_set('general.smtp_use_ssl') and self.cfg.general.smtp_use_ssl.lower() == "true":
    +       server.ehlo()
    +       server.starttls()
    +       server.ehlo()
    +
         if self.cfg.is_set('general.smtp_username'):
     

    Then configure your post-commit hook script to use the "mailer.py" and "mailer.conf" files. The location of your post-commit scripts depends on the location of your repository. We will use the following path in this example "/opt/bitnami/repositories/your_repo". Edit the "/opt/bitnami/repositories/your_repo/hooks/post-commit.tmpl" file and replace the last line with the following one:

    /opt/bitnami/python/bin/python /opt/bitnami/subversion/hooks/mailer/mailer.py commit "$REPOS" "$REV" /opt/bitnami/subversion/hooks/mailer/mailer.conf
    

    In order to enable post-commits you only have to rename the post-commit script to remove the "tmpl" extension:

    sudo mv /opt/bitnami/repositories/your_repo/hooks/post-commit.tmpl /opt/bitnami/repositories/your_repo/hooks/post-commit

    Then try to do a change in any file and commit the changes. If there is any error you can see after the commit:

    $ svn commit -m "test" README.txt 
    Sending        README.txt
    Transmitting file data .
    Committed revision 742.
     

    How to configure the repository URL?

    If you do not set the prefix in the Subversion scripts, you should specify the full path to the repository, for instance svn://YOUR_IP/home/user/repository. If you do not want to specify the full path of the repository, you should add the repository path option in the following scripts:

    win_platform.png On Windows: "installdir/subversion/scripts/serviceinstall.bat"

    -d --listen-port=3690 --root "C:\path\to\repository"
    

    Then run the script to apply the changes: "serviceinstall.bat UNINSTALL" and "serviceinstall.bat INSTALL" from a command prompt as Administrator.

    linux_platform.png On Linux andmac_platform.png OS X: "installdir/subversion/scripts/ctl.sh"

    -d --listen-port=3690 --root=/path/to/repository
    

    Then restart the Subversion server.

    Comments

    You must login to post a comment.

    Attach file

    Attachments