How to setup a post-commit hook with subversion (svn) for automatic deployment on myVesta

Post Reply
User avatar
isscbta
Team Member
Posts: 150
Joined: Mon Jul 19, 2021 1:41 am
Has thanked: 18 times
Been thanked: 3 times

How to setup Subversion (SVN): viewtopic.php?p=3238#p3238

Step 1: Prepare the Web Directory

Before starting, make sure that you have created myVesta user called "svn" and clear the contents of the public_html directory for the target domain.

Code: Select all

rm -rf /home/svn/web/domain.com/public_html/*
mkdir -p /home/svn/logs
chown svn:svn /home/svn/logs
Step 2: Create the Post-Commit Hook Script

Code: Select all

 mcedit /srv/svn/repos/myapp/hooks/post-commit
Paste the following script:

Code: Select all

#!/bin/sh
export LC_ALL=en_US.UTF-8

chown -R svn:svn /home/svn/web/domain.com/public_html/

/usr/bin/svn update /home/svn/web/domain.com/public_html
--username svnadmin
--password testpass123
--non-interactive
--accept theirs-full
--force
>> /home/svn/logs/subversion_log 2>&1

chown -R svn:svn /home/svn/web/domain.com/public_html/
chmod -R 775 /home/svn/web/domain.com/public_html/
Step 3: Set Permissions for the Hook Script

Code: Select all

 chown svn:svn /srv/svn/repos/myapp/hooks/post-commit
 chmod +x /srv/svn/repos/myapp/hooks/post-commit
Step 4: Checkout the Repository to the Web Directory

This command initializes the web directory with the repository’s content:

Code: Select all

svn checkout svn://domain.com/myapp
/home/svn/web/domain.com/public_html
--username svnadmin
--password testpass123
--non-interactive
Step 5: Test the Setup from Your Local Machine

On your local machine (for example, from a Debian system):

Code: Select all

mkdir ~/myapp-import
echo "<p>This is a test file for SVN import</p>" > ~/myapp-import/test.html

svn import ~/myapp-import svn://domain.com/myapp
--username testuser
--password testuserpass
-m "Initial import of test file"
Step 6: Verify the Result

Open your website (https://domain.com) and check if test.html is present in the public_html directory.

Confirm that the post-commit hook is working as expected.

Final Notes:
  • Replace testpass123 and testuserpass with your actual credentials.
  • The post-commit script ensures that changes from the SVN repository are automatically updated in the website directory after each commit.
  • Monitor the /home/svn/logs/subversion_log for any update errors.
Post Reply