From 4325a3d964d1d8cd8cd9736848f148c440e22829 Mon Sep 17 00:00:00 2001 From: nold Date: Fri, 5 Jul 2019 13:57:35 +0200 Subject: [PATCH] Add: Clone git repo with SSH public keys into SSH_KEY_DIR --- Dockerfile | 2 +- data/run.sh | 20 +++++++++++++++----- docker-compose.yml | 7 +++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30f7021..5da2d2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ VOLUME /backup ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get -y --no-install-recommends install \ - borgbackup openssh-server && apt-get clean && \ + borgbackup openssh-server git ca-certificates && apt-get clean && \ useradd -s /bin/bash -m borg && \ mkdir /home/borg/.ssh && \ chmod 700 /home/borg/.ssh && \ diff --git a/data/run.sh b/data/run.sh index 17046e9..caa2364 100755 --- a/data/run.sh +++ b/data/run.sh @@ -1,12 +1,12 @@ #!/bin/bash # Start Script for docker-borgserver +#set -x -BORG_DATA_DIR=/backup -SSH_KEY_DIR=/sshkeys -BORG_CMD='cd ${BORG_DATA_DIR}/${client_name}; borg serve --restrict-to-path ${BORG_DATA_DIR}/${client_name} ${BORG_SERVE_ARGS}' - -# Append only mode? +#BORG_SERVE_ARGS=${BORG_SERVE_ARGS:=""} BORG_APPEND_ONLY=${BORG_APPEND_ONLY:=no} +BORG_DATA_DIR="${BORG_DATA_DIR:=/backup}" +SSH_KEY_DIR="${SSH_KEY_DIR:=/sshkeys}" +BORG_CMD='cd ${BORG_DATA_DIR}/${client_name}; borg serve --restrict-to-path ${BORG_DATA_DIR}/${client_name} ${BORG_SERVE_ARGS}' echo "########################################################" echo -n " * Docker BorgServer powered by " @@ -18,6 +18,16 @@ if [ "${BORG_APPEND_ONLY}" == "yes" ] && [ -z "${BORG_ADMIN}" ] ; then echo "WARNING: BORG_APPEND_ONLY is active, but no BORG_ADMIN was specified!" fi +if [ ! -z "${SSH_KEY_GIT}" ] ; then + echo "SSH_KEY_GIT set, cloning '${SSH_KEY_GIT}' into '${SSH_KEY_DIR}/clients'" + if [ ! -d "${SSH_KEY_DIR}/clients/.git" ] ; then + # FIXME: Should the container die here, in case of error? + git clone "${SSH_KEY_GIT}" "${SSH_KEY_DIR}/clients" + else + git -C "${SSH_KEY_DIR}/clients" pull + fi +fi + # Precheck directories & client ssh-keys for dir in BORG_DATA_DIR SSH_KEY_DIR ; do dirpath=$(eval echo '$'${dir}) diff --git a/docker-compose.yml b/docker-compose.yml index aabaf84..7a68057 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,8 @@ version: '3' services: borgserver: - image: nold360/borgserver - #build: . + #image: nold360/borgserver + build: . volumes: - ./backup:/backup - ./sshkeys:/sshkeys @@ -17,4 +17,7 @@ services: # Hostname of Admin's SSH-Key BORG_ADMIN: "" + + # Client Pubkeys in git: + SSH_KEY_GIT: "https://github.com//.git" restart: unless-stopped