Skip to content

Commit

Permalink
Add rsync Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
zema1 committed Dec 1, 2017
1 parent 0f6fa71 commit e6834fa
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions deploy/test_case_rsync/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions deploy/test_case_rsync/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions deploy/test_case_rsync/rsyncd.conf
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions deploy/test_case_rsync/run.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e6834fa

Please sign in to comment.