From e6834fa6f7a38d1aa76ba907222d69e73658c6b4 Mon Sep 17 00:00:00 2001 From: zema1 Date: Fri, 1 Dec 2017 13:58:37 +0800 Subject: [PATCH] Add rsync Dockerfile --- deploy/test_case_rsync/Dockerfile | 8 ++++++ deploy/test_case_rsync/docker-compose.yml | 24 +++++++++++++++++ deploy/test_case_rsync/rsyncd.conf | 12 +++++++++ deploy/test_case_rsync/run.sh | 33 +++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 deploy/test_case_rsync/Dockerfile create mode 100644 deploy/test_case_rsync/docker-compose.yml create mode 100644 deploy/test_case_rsync/rsyncd.conf create mode 100644 deploy/test_case_rsync/run.sh diff --git a/deploy/test_case_rsync/Dockerfile b/deploy/test_case_rsync/Dockerfile new file mode 100644 index 00000000..e20a116e --- /dev/null +++ b/deploy/test_case_rsync/Dockerfile @@ -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 \ No newline at end of file diff --git a/deploy/test_case_rsync/docker-compose.yml b/deploy/test_case_rsync/docker-compose.yml new file mode 100644 index 00000000..105dc47a --- /dev/null +++ b/deploy/test_case_rsync/docker-compose.yml @@ -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 diff --git a/deploy/test_case_rsync/rsyncd.conf b/deploy/test_case_rsync/rsyncd.conf new file mode 100644 index 00000000..6ff66250 --- /dev/null +++ b/deploy/test_case_rsync/rsyncd.conf @@ -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 diff --git a/deploy/test_case_rsync/run.sh b/deploy/test_case_rsync/run.sh new file mode 100644 index 00000000..c86b5713 --- /dev/null +++ b/deploy/test_case_rsync/run.sh @@ -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