这篇文章使用docker方式创建一个alpine的svn镜像,并创建一个repository,然后在客户端将这个repository使用svn方式checkout出来。
docker和linux版本如下所示,不过版本理论上来说基本不会造成影响。
[root@liumiaocn ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 08:47:51 2017
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 08:47:51 2017
OS/Arch: linux/amd64
Experimental: false
[root@liumiaocn ~]#
[root@liumiaocn ~]# uname -a
Linux liumiaocn 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@liumiaocn ~]#
使用当前最新的3.8的alpine稳定版本
[root@liumiaocn ~]# docker run -it alpine sh
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.8.0
PRETTY_NAME="Alpine Linux v3.8"
HOME_URL="http://alpinelinux.org"
BUG_REPORT_URL="http://bugs.alpinelinux.org"
/ #
类型 | URL | svn版本 |
---|---|---|
缺省main | http://dl-cdn.alpinelinux.org/alpine/版本号/main | subversion-1.10.0-r0 |
缺省community | http://dl-cdn.alpinelinux.org/alpine/版本号/community | - |
开发main | http://dl-cdn.alpinelinux.org/alpine/edge/main | subversion-1.10.0-r0 |
开发community | http://dl-cdn.alpinelinux.org/alpine/edge/community | - |
Edge是开发中的版本,一般版本比较新,但是有可能不是非常稳定。以下以svn版本确认为例进行说明:
/etc/apk/repositories: 用于保存搜索路径,缺省信息如下:
/ # cat /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/v3.8/main
http://dl-cdn.alpinelinux.org/alpine/v3.8/community
/ #
使用apk update更新索引之后,可以确认相关package的版本信息
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
v3.8.0-88-g3e3519a996 [http://dl-cdn.alpinelinux.org/alpine/v3.8/main]
v3.8.0-88-g3e3519a996 [http://dl-cdn.alpinelinux.org/alpine/v3.8/community]
OK: 9542 distinct packages available
/ # apk info subversion
subversion-1.10.0-r0 description:
Replacement for CVS, another versioning system (svn)
subversion-1.10.0-r0 webpage:
http://subversion.apache.org
subversion-1.10.0-r0 installed size:
954368
/ #
切换方式:将/etc/apk/repositories内容中的v3.8换成edge即可,由于版本升级可以考虑使用正则方式进行替换, 这样只要符合vn.n格式的版本的时候都可以用这种方式进行替换
/ # sed -i -e 's/v[[:digit:]]\.[[:digit:]]/edge/g' /etc/apk/repositories
/ # cat /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/edge/main
http://dl-cdn.alpinelinux.org/alpine/edge/community
/ #
更新索引,确认subversion的版本
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
v3.8.0-1501-g575c35cddd [http://dl-cdn.alpinelinux.org/alpine/edge/main]
v3.8.0-1502-ga859106885 [http://dl-cdn.alpinelinux.org/alpine/edge/community]
OK: 9636 distinct packages available
/ #
/ # apk info subversion
subversion-1.10.0-r0 description:
Replacement for CVS, another versioning system (svn)
subversion-1.10.0-r0 webpage:
http://subversion.apache.org
subversion-1.10.0-r0 installed size:
954368
/ #
可以看到目前版本都是更新到1.10.0-r0,如果希望使用apache推荐的1.10.2,使用alpine方式的话目前只能从源码编译了,这里使用1.10.0-r2
安装1.10.0-r0版本:apk add subversion==1.10.0-r0
确认svn版本信息
/ # svn --version --quiet
1.10.0
/ #
/ # svnserve --version
svnserve, version 1.10.0 (r1827917)
compiled May 8 2018, 22:50:38 on x86_64-alpine-linux-musl
Copyright (C) 2018 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/
The following repository back-end (FS) modules are available:
* fs_fs : Module for working with a plain file (FSFS) repository.
* fs_x : Module for working with an experimental (FSX) repository.
* fs_base : Module for working with a Berkeley DB repository.
Cyrus SASL authentication is available.
/ #
确认svn相关依赖信息
/ # svn --version --verbose
svn, version 1.10.0 (r1827917)
compiled May 8 2018, 22:50:38 on x86_64-alpine-linux-musl
Copyright (C) 2018 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/
The following repository access (RA) modules are available:
* ra_svn : Module for accessing a repository using the svn network protocol.
- with Cyrus SASL authentication
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme
* ra_serf : Module for accessing a repository via WebDAV protocol using serf.
- using serf 1.3.9 (compiled with 1.3.9)
- handles 'http' scheme
- handles 'https' scheme
The following authentication credential caches are available:
* Plaintext cache in /root/.subversion
* GPG-Agent
System information:
* running on x86_64-unknown-linux-gnu
- "Alpine Linux v3.8" [Linux 3.10.0-862.el7.x86_64]
* linked dependencies:
- APR 1.6.3 (compiled with 1.6.3)
- APR-Util 1.6.1 (compiled with 1.6.1)
- Expat 2.2.5 (compiled with 2.2.5)
- SQLite 3.24.0 (compiled with 3.23.1)
- Utf8proc 2.1.0 (compiled with 2.1.0)
- ZLib 1.2.11 (compiled with 1.2.11)
- LZ4 1.8.2 (compiled with 1.8.1)
/ #
启动svn使用svnserve命令,常用的参数和使用方式如下所示:
参数 | 必选/可选 | 简写方式 | 说明 |
---|---|---|---|
–daemon | 必选 | -d | daemon模式,d/i/t/X四者必选其一 |
–inetd | 必选 | -i | inetd模式,d/i/t/X四者必选其一 |
–tunnel | 必选 | -t | tunnel模式,d/i/t/X四者必选其一 |
–listen-once | 必选 | -X | listen-once模式,d/i/t/X四者必选其一 |
–root | 可选 | -r | 服务启动的根目录 |
–read-only | 可选 | -R | 以只读方式启动 |
–listen-port | 可选 | - | 设定监听端口,缺省为3690,在-t/-X模式下使用 |
–listen-host | 可选 | - | 设定服务器名或者IP地址,在-t/-X模式下使用 |
–compression | 可选 | -c | 网络传输压缩比率,取值范围0-9,0 不压缩,9最大,5为缺省值 |
–foreground | 可选 | - | 前台运行,常与-d和-X连用 |
–log-file 文件名 | 可选 | - | 设定日志文件 |
注意:Markdown文法的--
在上面都显示成了 – ,其余所有的文章也都有这个问题,基础较弱的拷贝使用的时候请注意
有了以上的基础知识,以下dockerfile的内容不再赘述。
[root@liumiaocn ~]# mkdir svn
[root@liumiaocn ~]# cd svn
[root@liumiaocn svn]# vi Dockerfile
[root@liumiaocn svn]# cat Dockerfile
FROM alpine:3.8
RUN apk update \
&& apk add --no-cache subversion==1.10.0-r0 \
&& rm -rf /var/cache/apk/*
VOLUME [ "/data/svn" ]
WORKDIR /data/svn
EXPOSE 3690
CMD [ "/usr/bin/svnserve", "--daemon", "--foreground", "--root", "/data/svn" ]
[root@liumiaocn svn]#
使用docker build创建svn镜像
[root@liumiaocn svn]# docker build -t svn:1.10 .
Sending build context to Docker daemon 2.048 kB
Step 1/6 : FROM alpine:3.8
3.8: Pulling from library/alpine
Digest: sha256:7043076348bf5040220df6ad703798fd8593a0918d06d3ce30c6c93be117e430
Status: Downloaded newer image for alpine:3.8
---> 11cd0b38bc3c
Step 2/6 : RUN apk update && apk add --no-cache subversion==1.10.0-r0 && rm -rf /var/cache/apk/*
---> Running in 35fe20eb9291
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
v3.8.0-88-g3e3519a996 [http://dl-cdn.alpinelinux.org/alpine/v3.8/main]
v3.8.0-88-g3e3519a996 [http://dl-cdn.alpinelinux.org/alpine/v3.8/community]
OK: 9542 distinct packages available
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/11) Installing libuuid (2.32-r0)
(2/11) Installing apr (1.6.3-r1)
(3/11) Installing expat (2.2.5-r0)
(4/11) Installing apr-util (1.6.1-r2)
(5/11) Installing db (5.3.28-r0)
(6/11) Installing lz4-libs (1.8.2-r0)
(7/11) Installing libsasl (2.1.26-r13)
(8/11) Installing serf (1.3.9-r4)
(9/11) Installing sqlite-libs (3.24.0-r0)
(10/11) Installing subversion-libs (1.10.0-r0)
(11/11) Installing subversion (1.10.0-r0)
Executing subversion-1.10.0-r0.pre-install
Executing busybox-1.28.4-r0.trigger
OK: 12 MiB in 24 packages
---> 11d1ce9b5896
Removing intermediate container 35fe20eb9291
Step 3/6 : VOLUME /data/svn
---> Running in 46ad9e91ad97
---> 7766290cf514
Removing intermediate container 46ad9e91ad97
Step 4/6 : WORKDIR /data/svn
---> 0c9b3069faec
Removing intermediate container 7ffc72318f44
Step 5/6 : EXPOSE 3690
---> Running in 5bf5fb9e5f41
---> 278024ab5139
Removing intermediate container 5bf5fb9e5f41
Step 6/6 : CMD /usr/bin/svnserve --daemon --foreground --root /data/svn
---> Running in de1ae3b5132e
---> 8a8cb1dad570
Removing intermediate container de1ae3b5132e
Successfully built 8a8cb1dad570
[root@liumiaocn svn]#
可以看到我们成功创建了一个12.4M的svn镜像
[root@liumiaocn svn]# docker images |grep svn |grep 1.10
svn 1.10 8a8cb1dad570 43 seconds ago 12.4 MB
[root@liumiaocn svn]#
将端口号和本地卷都暴露出来,这样启动的svn容器后面就可以从外部更容易的操作了
[root@liumiaocn svn]# mkdir -p data
[root@liumiaocn svn]# docker run -p 3690:3690 -v `pwd`/data:/data/svn --name svn-server -d svn:1.10
2e3ee00b95dbe70add8728758f4e8c5571c60402dd79694b12979c19e191f923
[root@liumiaocn svn]# docker ps |grep svn
2e3ee00b95db svn:1.10 "/usr/bin/svnserve..." 6 seconds ago Up 6 seconds 0.0.0.0:3690->3690/tcp svn-server
[root@liumiaocn svn]#
现在svn服务已经就绪,可以创建svn仓库了。而使用svnadmin create就可以很简单地创建一个仓库:
[root@liumiaocn svn]# docker exec -it svn-server sh
/data/svn # ls
/data/svn # svnadmin create demo-repo
/data/svn # ls
demo-repo
/data/svn # ls demo-repo
README.txt conf db format hooks locks
/data/svn #
本机IP为192.168.163.129, 从另外一台可以互通的机器上模拟作为客户端进行svn的checkout操作,首先需要网络是通的
[root@platform ~]# ping -w1 192.168.163.129
PING 192.168.163.129 (192.168.163.129) 56(84) bytes of data.
64 bytes from 192.168.163.129: icmp_seq=1 ttl=64 time=0.324 ms
--- 192.168.163.129 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.324/0.324/0.324/0.000 ms
[root@platform ~]#
其次,需要有svn客户端,至少可以使用svn co命令,在centos只需要yum install subversion一下就可以模拟了
[root@platform ~]# svn --version --quiet
1.7.14
[root@platform ~]#
可以看到成功进行了co操作,因为缺省状况下,匿名用户是有权限的,如何规范访问会在后面进一步展开
[root@platform ~]# svn co svn://192.168.163.129/demo-repo
Checked out revision 0.
[root@platform ~]# ls demo-repo
[root@platform ~]#
当然防火墙如果有的话也请注意,如果觉得这个比较麻烦,直接在宿主机器上执行即可
[root@liumiaocn svn]# cd /tmp
[root@liumiaocn tmp]# svn co svn://192.168.163.129/demo-repo
Checked out revision 0.
[root@liumiaocn tmp]# ls demo-repo
[root@liumiaocn tmp]#
这样客户端和服务器端的连同验证也完成了
这篇文章简单整理了如何创建一个alpine的镜像并搭建svn服务,创建一个demo的repo,并在客户端进行svn co操作
https://wiki.alpinelinux.org/wiki/