Browse Source

[FEATURE] Initial version

Mickaël Perrin 8 years ago
parent
commit
0cb04fef5f
3 changed files with 108 additions and 0 deletions
  1. 24 0
      Dockerfile
  2. 62 0
      docker-entrypoint.sh
  3. 22 0
      rsyncd.tpl.conf

+ 24 - 0
Dockerfile

@@ -0,0 +1,24 @@
+FROM alpine
+MAINTAINER Mickaël PERRIN <[email protected]>
+
+# tzdata for time syncing
+# bash for entrypoint script
+RUN apk add --no-cache rsync bash tzdata
+
+# Create entrypoint script
+ADD docker-entrypoint.sh /
+RUN chmod +x /docker-entrypoint.sh
+RUN mkdir -p /docker-entrypoint.d
+
+# SSH Server configuration file
+ADD /rsyncd.tpl.conf /
+
+# Default environment variables
+ENV TZ="Europe/Paris" \
+    LANG="C.UTF-8"
+
+EXPOSE 873
+ENTRYPOINT [ "/docker-entrypoint.sh" ]
+
+# RUN rsync in no daemon and expose errors to stdout
+CMD [ "/usr/bin/rsync", "--no-detach", "--daemon", "--log-file=/dev/stdout" ]

+ 62 - 0
docker-entrypoint.sh

@@ -0,0 +1,62 @@
+#!/bin/bash
+set -e
+
+# Allow to run complementary processes or to enter the container without
+# running this init script.
+if [ "$1" == '/usr/bin/rsync' ]; then
+
+  # Ensure time is in sync with host
+  # see https://wiki.alpinelinux.org/wiki/Setting_the_timezone
+  if [ -n ${TZ} ] && [ -f /usr/share/zoneinfo/${TZ} ]; then
+    ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
+    echo ${TZ} > /etc/timezone
+  fi
+
+  # Defaults
+  VOLUME_PATH=${VOLUME_PATH:-/docker}
+  HOSTS_ALLOW=${HOSTS_ALLOW:-0.0.0.0/0}
+  READ_ONLY=${READ_ONLY:-false}
+  CHROOT=${CHROOT:-no}
+  VOLUME_NAME=${VOLUME_NAME:-volume}
+  USERNAME=${USERNAME:-rsyncuser}
+
+  # Ensure VOLUME PATH exists
+  if [ ! -e $VOLUME_PATH ]; then
+    mkdir -p /$VOLUME_PATH
+  fi
+
+  # Grab UID of owner of the volume directory
+  if [ -z $OWNER_ID ]; then
+    OWNER_ID=$(stat -c '%u' $VOLUME_PATH)
+  else
+    echo "OWNER_ID is set forced to: $OWNER_ID"
+  fi
+  if [ -z $GROUP_ID ]; then
+    GROUP_ID=$(stat -c '%g' $VOLUME_PATH)
+  else
+    echo "GROUP_ID is set forced to: $GROUP_ID"
+  fi
+
+  # Generate password file
+  if [ ! -z $PASSWORD ]; then
+    echo "$USERNAME:$PASSWORD" >  /etc/rsyncd.secrets
+    chmod 600 /etc/rsyncd.secrets
+  fi
+
+  # Generate configuration
+  eval "echo \"$(cat /rsyncd.tpl.conf)\"" > /etc/rsyncd.conf
+
+  # Check if a script is available in /docker-entrypoint.d and source it
+  # You can use it for example to create additional sftp users
+  for f in /docker-entrypoint.d/*; do
+    case "$f" in
+      *.sh)  echo "$0: running $f"; . "$f" ;;
+      *)     echo "$0: ignoring $f" ;;
+    esac
+  done
+
+fi
+
+exec "$@"
+
+

+ 22 - 0
rsyncd.tpl.conf

@@ -0,0 +1,22 @@
+# /etc/rsyncd.conf
+
+# Minimal configuration file for rsync daemon
+# See rsync(1) and rsyncd.conf(5) man pages for help
+
+# This line is required by the /etc/init.d/rsyncd script
+pid file = /var/run/rsyncd.pid
+
+uid = ${OWNER_ID}
+gid = ${GROUP_ID}
+use chroot = ${CHROOT}
+reverse lookup = no
+[${VOLUME_NAME}]
+    hosts deny = *
+    hosts allow = ${HOSTS_ALLOW}
+    read only = ${READ_ONLY}
+    path = ${VOLUME_PATH}
+    auth users = , ${USERNAME}:rw
+    secrets file = /etc/rsyncd.secrets
+    timeout = 600
+    transfer logging = true
+