Add rsync Dockerfile

This commit is contained in:
zema1 2017-12-01 13:58:37 +08:00
parent 0f6fa71657
commit e6834fa6f7
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,8 @@
FROM alpine:3.6
RUN apk add --update --no-cache rsync
ADD ./run.sh /tmp/run.sh
ADD ./rsyncd.conf /etc/rsyncd.conf
CMD /bin/sh /tmp/run.sh

View File

@ -0,0 +1,24 @@
version: "3"
services:
oj-rsync-master:
image: oj_rsync
container_name: oj-rsync
volumes:
- $PWD/data/backend/test_case:/test_case:ro
- $PWD/data/rsync_master:/log
environment:
- RSYNC_MODE=master
- RSYNC_USER=ojrsync
- RSYNC_PASSWORD=CHANGE_THIS_PASSWORD
ports:
- "0.0.0.0:873:873"
oj-rsync-slave:
image: oj-rsync
volumes:
- $PWD/test_case:/test_case
- $PWD/rsync_slave:/log
environment:
- RSYNC_MODE=slave
- RSYNC_USER=ojrsync
- RSYNC_PASSWORD=CHANGE_THIS_PASSWORD

View File

@ -0,0 +1,12 @@
port = 873
uid = root
gid = root
use chroot = yes
read only = yes
log file = /log/rsyncd.log
[testcase]
path = /test_case/
list = yes
auth users = ojrsync
secrets file = /etc/rsyncd.passwd

View File

@ -0,0 +1,33 @@
#!/usr/bin/env sh
slave_runner()
{
while true
do
rsync -avzP --delete --progress --password-file=/etc/rsync_slave.passwd $RSYNC_USER@$RSYNC_MASTER_ADDR::testcase /test_case >> /log/rsync_slave.log
sleep 5
done
}
master_runner()
{
rsync --daemon --config=/etc/rsyncd.conf
while true
do
sleep 60
done
}
if [ "$RSYNC_MODE" = "master" ]; then
if [ ! -f "/etc/rsyncd.passwd" ]; then
echo "$RSYNC_USER:$RSYNC_PASSWORD" > /etc/rsyncd.passwd
fi
chmod 600 /etc/rsyncd.passwd
master_runner
else
if [ ! -f "/etc/rsync_slave.passwd" ]; then
echo "$RSYNC_PASSWORD" > /etc/rsync_slave.passwd
fi
chmod 600 /etc/rsync_slave.passwd
slave_runner
fi