1, Brief description
1. Basic environment
- Debian GNU/Linux 9.9 (stretch)
- Docker version 19.03.4
In fact, using other Linux distributions is the same. I use Alibaba cloud's Debian 9.9 server when operating. As for what is SVN, there will be no cumbersome explanation here. Here is just a demonstration of how to build an SVN service based on the third image
2. Open a simple container instance
In this installation, we do not write a Dockerfile to build an image, but directly use a popular image on Dockerhub: elleflorio / SVN server. For details, please refer to this link: https://hub.docker.com/r/elleflorio/svn-server
Create a simple svn service using the following command
docker run -d --name svn-server -p 3690:3690 elleflorio/svn-server
You can also optionally map the local directory to the svn warehouse directory of the container, as shown in the following parameters
-v <hostpath>:/home/svn
2, Actual operation process
Suppose: there is a need to develop a PHP project and create a base code warehouse on the server. All developers can pull the code from the server to the PC for development, and then upload it to the server for automatic deployment. Next, we complete this process based on Docker.
1. Download the image and create the container
# Download Image docker pull elleflorio/svn-server # Create the svn warehouse directory and enter the svn warehouse directory mkdir -p /var/svn # Create an svn service container, map the svn warehouse in the container to the local machine, and map port 3690 docker run -d --name svn-server -p 3690:3690 -v "$PWD":/home/svn -v /var/www/html:/var/www/html elleflorio/svn-server
In the above example code, in order to manage the local project directory in the SVN container, assume that the local project directory is / var/www/html. In addition to mapping the SVN warehouse directory, we also map the local / var/www/html to the / var/www/html directory in the svn container.
2. Create a code warehouse on the server
# Create code warehouse docker exec -t svn-server svnadmin create /home/svn/test
In the above code, create a code warehouse in the / home/svn/test directory in the container and synchronize it to the / var/svn directory of the local machine. Let's configure the svn warehouse first.
The configuration directory conf in the SVN library has three files:
- authz is a permission control file
- passwd is the account password file
- svnserve.conf is the SVN service comprehensive configuration file
Configure permission profile authz
Edit authz as follows:
Example code: / var/svn/test/conf/authz
[groups] #User group admin = master,master #Directory corresponding to user group [/] #Library directory permissions @admin = rw #User group permissions *=r
Configure account password file passwd
Edit passwd as follows:
Example code: / var/svn/test/conf/passwd
[users] # harry = harryssecret # sally = sallyssecret master = master admin = admin
Configure SVN service comprehensive configuration file svnserve conf
Edit svnserve Conf, refer to the following:
Example code: / var / SVN / test / conf / svnserve conf
[general] # force-username-case = none # The permissions for anonymous access can be read, write, none, and the default is read anon-access = none #Enable authorized users to write auth-access = write #Path to password database password-db = passwd #Access control file authz-db = authz #The authentication namespace and SVN will be displayed in the authentication prompt and used as the keyword of the credential cache realm = /var/svn/test [sasl]
After completing the above configuration, we need to synchronize the server code with the local code, as shown in the following figure:

Next, after we push the local computer code to the SVN warehouse, the server synchronizes the code to the project directory.
3. Synchronize the code to the server project directory
(1) Upload the code to SVN warehouse on PC (SVN must be installed on PC)
# pull the code in the warehouse locally. The following 123.123.123.123 represents the server IP address. You may need to enter the svn account and password in the following process svn checkout svn://123.123.123.123/test # Enter code directory cd test # Create sample file echo "hello" >> test.txt # Submit code to SVN warehouse svn add test.txt svn commit test.txt -m 'test'
(2) Server synchronization code
# Synchronize code to project directory docker exec -t svn-server svn checkout svn://127.0.0.1/test /var/www/html/test --username master --password master --force --no-auth-cache
(3) Auto sync code
In fact, if the PC we use for development submits code to the server every time, the server needs to manually execute the synchronization command, and the local code will be synchronized to the project directory of the server. It must be very troublesome, so we can use the hook provided by SVN to realize automatic code update.
# Enter the hook configuration file directory cd /var/svn/test/hooks # Copy hook file cp post-commit.tmpl post-commit
We will post-commit The suffix of tmpl hook file can be removed to take effect, so we copy it. Next, we edit the post commit file and comment out the code for sending the email. Then add two lines of code below, as follows:
REPOS="$1" REV="$2" TXN_NAME="$3" #mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf # Set encoding export LANG="en_US.UTF-8" # Update code to project directory svn update --username master --password master /var/www/html/test
After editing the configuration file, we just need to save it and it will take effect automatically. At this time, modify the project content on the PC and submit it to the code warehouse again. The server will automatically synchronize to the project directory of the server. You no longer need to manually execute the svn checkout command
3, Summary
This time mainly demonstrates some basic processes in the construction of SVN server. In order to reduce the dependence of server related software libraries, we use the third-party Docker image to build SVN container services. In fact, the effect is the same as that of manually compiling and installing directly on the operating system or installing from the software library. The container can better reduce server related dependencies and better isolate the operating system environment. If we don't need the SVN service, just remove the corresponding container.
In fact, if we have to configure a lot every time we create an SVN warehouse, it will be a waste of time. Developers should not spend too much time and energy "building wheels repeatedly", but should spend more time and energy thinking about more valuable things! Limited to space, this tutorial is over. The next section will demonstrate how to use Shell script to quickly build SVN warehouse. After the script is compiled, you can use one command to complete the above complex contents.