├── container_scripts ├── startup.sh ├── install_tini.sh ├── upgradeCompatibilityChecks.sh ├── missionreport.sh ├── prelaunch.sh └── configure.sh ├── .github └── workflows │ └── ci-pipeline.yml ├── dev_scripts ├── test ├── bootstrap └── cibuild ├── docker-testenvironment-compose.yml ├── Dockerfile ├── CHANGELOG.md ├── LICENSE └── README.md /container_scripts/startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -f "/root/gravity-sync/gravity-sync.conf" ]; 4 | then 5 | /usr/local/bin/configure.sh || exit 1 6 | fi 7 | 8 | /usr/sbin/crond -f -l 8 9 | -------------------------------------------------------------------------------- /.github/workflows/ci-pipeline.yml: -------------------------------------------------------------------------------- 1 | name: CI Pipeline 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v2 13 | 14 | - name: Bootstrap 15 | run: dev_scripts/bootstrap 16 | 17 | - name: Run Test 18 | run: dev_scripts/test 19 | 20 | - name: Run Cross Build 21 | run: dev_scripts/cibuild --version 1.2.3 22 | -------------------------------------------------------------------------------- /container_scripts/install_tini.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ARCH="$(uname -m)" 4 | 5 | if [ ${ARCH} = "x86_64" ]; 6 | then 7 | wget https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static -O /tini 8 | elif [ ${ARCH} = "aarch64" ]; 9 | then 10 | wget https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-arm64 -O /tini 11 | elif [ ${ARCH} = "armv7l" ]; 12 | then 13 | wget https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-armhf -O /tini 14 | else 15 | echo "The architecture ${ARCH} is not supported" 16 | exit 1 17 | fi 18 | 19 | chmod +x /tini 20 | -------------------------------------------------------------------------------- /container_scripts/upgradeCompatibilityChecks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mustexit=0 4 | 5 | check3_0_0() 6 | { 7 | if [[ -f /root/gravity-sync/gravity-sync.log ]]; 8 | then 9 | mustexit=1 10 | echo "Please change the mount point of your log file as below:" 11 | echo "From:" 12 | echo " /root/gravitysync/gravity-sync.log" 13 | echo "To:" 14 | echo " /root/gravitysync/logs/gravity-sync.log" 15 | exit 1 16 | fi 17 | 18 | if [[ -f /root/gravity-sync/gravity-sync.cron ]]; 19 | then 20 | mustexit=1 21 | echo "Please change the mount point of your cron log file as below:" 22 | echo "From:" 23 | echo " /root/gravitysync/gravity-sync.cron" 24 | echo "To:" 25 | echo " /root/gravitysync/logs/gravity-sync.cron" 26 | exit 1 27 | fi 28 | } 29 | 30 | check3_0_0 31 | 32 | if [[ "${mustexit}" != "0" ]]; 33 | then 34 | exit 1 35 | fi 36 | -------------------------------------------------------------------------------- /container_scripts/missionreport.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "${DEBUG}" = "true" ]; 4 | then 5 | set -x 6 | set -v 7 | else 8 | set +x 9 | set +v 10 | fi 11 | 12 | /usr/local/bin/upgradeCompatibilityChecks.sh 13 | 14 | if [[ "$?" != "0" ]]; 15 | then 16 | echo "Failed the upgrade compatibility check" 17 | exit 1 18 | fi 19 | 20 | /root/gravity-sync/gravity-sync.sh compare 21 | 22 | if [[ "$?" != "0" ]]; 23 | then 24 | echo "Failed to perform a comparison between pihole instances" 25 | exit 1 26 | fi 27 | 28 | filemoddate=`stat -c %Y /root/gravity-sync/logs/gravity-sync.cron` 29 | tolerance=$(( ${SYNC_FREQUENCY}*60 * 11/10 )) 30 | nextfilemoddate=$(( ${filemoddate} + ${tolerance} )) 31 | now=`date +%s` 32 | 33 | if [[ ${nextfilemoddate} -lt ${now} ]]; 34 | then 35 | echo "Failed to verify that GravitySync has run in the last ${SYNC_FREQUENCY} minutes" 36 | exit 1 37 | fi 38 | 39 | if [ "${DEBUG}" = "true" ]; 40 | then 41 | echo "Mission Report all clear"; 42 | fi 43 | 44 | exit 0 45 | -------------------------------------------------------------------------------- /container_scripts/prelaunch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | readYesNo() 4 | { 5 | old_stty_cfg=$(stty -g) 6 | stty raw -echo 7 | answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) 8 | stty $old_stty_cfg 9 | if echo "$answer" | grep -iq "^y" ;then 10 | true 11 | else 12 | false 13 | fi 14 | } 15 | 16 | remote_user="root" 17 | 18 | echo "What is the hostname / IP of the remote host?" 19 | read remote_host; 20 | 21 | echo "Is the remote SSH server on port 22?" 22 | if readYesNo; 23 | then 24 | remote_port="22" 25 | else 26 | echo "What is the port of your remote SSH server?" 27 | read remote_port; 28 | fi 29 | 30 | echo "We recomend creating a gravitysync user on the remote system - would you like to do this?" 31 | if readYesNo; 32 | then 33 | #Connect and create user 34 | remote_user="gravitysync" 35 | echo "Please provide a management user with sudo privileges" 36 | echo "We will use this user to create the gravitysync user only" 37 | echo "ssh -P${remote_port} USER@${remote_host}" 38 | read username; 39 | ssh -t -o "StrictHostKeyChecking no" ${username}@${remote_host} ' \ 40 | sudo adduser gravitysync && \ 41 | sudo usermod -a -G sudo gravitysync && \ 42 | sudo usermod -a -G docker gravitysync && \ 43 | umask u=r,g=r,o= && \ 44 | echo "gravitysync ALL=(ALL) NOPASSWD:ALL" | \ 45 | sudo tee /etc/sudoers.d/gravitysync > /dev/null' 46 | echo "The remote system is configured as recomended" 47 | else 48 | echo "Would you like to use the root account? NOT RECOMENDED!" 49 | if !readYesNo; 50 | then 51 | echo "What user would you like to connect to on the remote system?" 52 | echo "Please note that this user must be part of the sudo and docker groups, and must have passwordless sudo" 53 | read remote_user; 54 | fi 55 | fi 56 | 57 | #Next, we generate SSH keys if they do not exist 58 | ssh-keygen -t rsa 59 | 60 | echo "We will now copy the SSH Key to the remote system. Please provide a password." 61 | ssh-copy-id ${remote_user}@${remote_host} 62 | 63 | if [ $remote_user == "gravitysync" ]; 64 | then 65 | echo "Disabling password login for gravitysync user" 66 | ssh ${remote_user}@${remote_host} sudo passwd -d gravitysync 67 | fi 68 | 69 | echo "Installing dependencies rsync, sqlite3, git and verifying system" 70 | ssh -o BatchMode=yes -p${remote_port} ${remote_user}@${remote_host} '\ 71 | sudo apt install -y rsync sqlite3 git && \ 72 | sudo curl -sSL https://gravity.vmstan.com | sudo GS_INSTALL=primary bash' 73 | -------------------------------------------------------------------------------- /dev_scripts/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # The following is courtesy of the Stack Overflow Community 4 | # https://stackoverflow.com/a/4774063 5 | WORKDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" 6 | WORKDIR=$(dirname ${WORKDIR}) 7 | TESTDIR="/tmp/gravitysynctest" 8 | set -e 9 | 10 | # Get the current version. This is not neccesary to the testing process itself but we cannot build without it 11 | VERSION=$(cat ${WORKDIR}/Dockerfile | grep GS_VERSION= | cut -d '"' -f2) 12 | 13 | # Build a single platform image 14 | echo "Building Image" 15 | ${WORKDIR}/dev_scripts/cibuild --platform linux/amd64 --version ${VERSION} 16 | 17 | # Clean up testing environment (In case we previously failed testing) 18 | docker-compose -f ${WORKDIR}/docker-testenvironment-compose.yml down --remove-orphans 19 | if ! $(rm -rf ${TESTDIR} > /dev/null 2>&1); 20 | then 21 | echo "Need root priveleges to reset testing directory" 22 | sudo rm -rf ${TESTDIR} 23 | fi 24 | 25 | # Create the testing volume directory and temporary SSH keys 26 | mkdir -p ${TESTDIR}/.ssh/ 27 | docker run -v "$TESTDIR/:$TESTDIR/.ssh:rw" --rm alpine:latest apk --update add openssh-client && ssh-keygen -q -t rsa -f ${TESTDIR}/.ssh/id_rsa -N '' 28 | 29 | # Bring the testing environment online 30 | docker-compose -f ${WORKDIR}/docker-testenvironment-compose.yml up -d 31 | 32 | # Prepare the SSH container to accommodate for GravitySync's requirements 33 | docker exec ssh sh -c 'chmod +w /etc/sudoers && sudo sed -i "s/^gravitysync.*$/gravitysync ALL=(ALL) NOPASSWD: ALL/" /etc/sudoers' 34 | docker exec ssh apk add sqlite rsync docker 35 | 36 | # Add the SSH container's host key to the GravitySync container's local store 37 | docker exec gravitysynctest ssh -o BatchMode=yes -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa -p 2222 gravitysync@172.31.255.2 exit 0 38 | 39 | # Insert a new custom DNS record in the "primary" pihole and test it 40 | docker exec pihole1 sh -c 'echo "127.0.0.1 dnstest.local" > /etc/pihole/custom.list' 41 | docker exec pihole1 /usr/local/bin/pihole restartdns 42 | echo 'Waiting 10 seconds after PiHole DNS restart' 43 | sleep 10 44 | host -t A dnstest.local 172.31.255.3 45 | 46 | # Run the sync to the "secondary" pihole and test it 47 | docker exec gravitysynctest /root/gravity-sync/gravity-sync.sh pull 48 | host -t A dnstest.local 172.31.255.4 49 | 50 | # Clean up the testing environment 51 | docker-compose -f ${WORKDIR}/docker-testenvironment-compose.yml down --remove-orphans 52 | if ! $(rm -rf ${TESTDIR} > /dev/null 2>&1); 53 | then 54 | sudo rm -rf ${TESTDIR} 55 | fi 56 | 57 | echo "The test has succeeded" 58 | -------------------------------------------------------------------------------- /dev_scripts/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENTBUILDXVER=`ls ~/.docker/cli-plugins/buildx* | sed -E 's/^.*\/buildx-v([0-9\.]+).linux-amd64/\1/'` 4 | NEWBUILDXVER=`curl --silent "https://api.github.com/repos/docker/buildx/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/'` 5 | DOWNLOADURL='https://github.com/docker/buildx/releases/download/v'${NEWBUILDXVER}'/buildx-v'${NEWBUILDXVER}'.linux-amd64' 6 | 7 | #vercomp and testvercomp Functions thanks to Dennis Williamson 8 | #https://stackoverflow.com/a/4025065 9 | vercomp () { 10 | if [[ $1 == $2 ]]; 11 | then 12 | return 0 13 | fi 14 | 15 | local IFS=. 16 | local i ver1=($1) ver2=($2) 17 | 18 | # fill empty fields in ver1 with zeros 19 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); 20 | do 21 | ver1[i]=0 22 | done 23 | 24 | for ((i=0; i<${#ver1[@]}; i++)); 25 | do 26 | if [[ -z ${ver2[i]} ]]; 27 | then 28 | # fill empty fields in ver2 with zeros 29 | ver2[i]=0 30 | fi 31 | 32 | if ((10#${ver1[i]} > 10#${ver2[i]})); 33 | then 34 | return 1 35 | fi 36 | 37 | if ((10#${ver1[i]} < 10#${ver2[i]})); 38 | then 39 | return 2 40 | fi 41 | 42 | done 43 | return 0 44 | } 45 | 46 | testvercomp () { 47 | vercomp $1 $2 48 | case $? in 49 | 0) op='=';; 50 | 1) op='>';; 51 | 2) op='<';; 52 | esac 53 | 54 | if [[ $op != $3 ]]; 55 | then 56 | return 1 57 | else 58 | return 0 59 | fi 60 | } 61 | 62 | 63 | #Determine if we need to install the BuildX Plugin 64 | if $(ls ~/.docker/cli-plugins/buildx* 1> /dev/null 2>&1); 65 | then 66 | VERCMP=$(testvercomp ${NEWBUILDXVER} ${CURRENTBUILDXVER} '>') 67 | if testvercomp ${NEWBUILDXVER} ${CURRENTBUILDXVER} '>'; 68 | then 69 | DOUPGRADEBUILDX=true 70 | else 71 | DOUPGRADEBUILDX=false 72 | fi 73 | else 74 | DOUPGRADEBUILDX=true 75 | fi 76 | 77 | #Install BuildX if required 78 | if [ ${DOUPGRADEBUILDX} = true ]; 79 | then 80 | echo 'Upgrading BuildX' 81 | rm -rf ~/.docker/cli-plugins/buildx* 82 | wget ${DOWNLOADURL} -P ~/.docker/cli-plugins/ 83 | fi 84 | 85 | #Install QEMU 86 | echo "Installing and Registering QEMU" 87 | sudo apt-get install qemu binfmt-support qemu-user-static -y 88 | #Register QEMU 89 | docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 90 | # You can test QEMU by running the following; 91 | # docker run --rm -t arm64v8/ubuntu uname -m 92 | # which should provide the output "aarch64" 93 | 94 | docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64 95 | if ! eval cat /proc/sys/fs/binfmt_misc/qemu-aarch64 | grep enabled 1>/dev/null 2>&1; then 96 | echo "Failed to verify installation of qemu" 97 | exit 1 98 | fi 99 | -------------------------------------------------------------------------------- /dev_scripts/cibuild: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # The following is courtesy of the Stack Overflow Community 4 | # https://stackoverflow.com/a/4774063 5 | WORKDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 1; pwd -P)" 6 | WORKDIR=$(dirname "${WORKDIR}") 7 | OUTPUTTYPE="docker" 8 | REPO_OWNER="docker_" 9 | PLATFORM="multipleplatform" 10 | VERSION="0" 11 | 12 | # The following is courtesy of the Stack Overflow Community 13 | # https://stackoverflow.com/a/14203146 14 | while [[ $# -gt 0 ]] 15 | do 16 | key="$1" 17 | case $key in 18 | "--platform" ) 19 | PLATFORM="$2" 20 | shift # past argument 21 | shift # past value 22 | ;; 23 | 24 | "--version" ) 25 | VERSION="$2" 26 | shift # past argument 27 | shift # past value 28 | ;; 29 | 30 | "--push" ) 31 | if [ "${2}" == "yes" ]; 32 | then 33 | OUTPUTTYPE="registry" 34 | REPO_OWNER="nhmike94/" 35 | fi 36 | shift # past argument 37 | shift # past value 38 | ;; 39 | 40 | *) 41 | echo "Unknown Option" 42 | exit 1 43 | ;; 44 | esac 45 | done 46 | 47 | if [ "${VERSION}" = "0" ]; 48 | then 49 | echo "No version number supplied" 50 | exit 1 51 | fi 52 | 53 | # Do some checks now so if we fail we don't waste time 54 | case ${PLATFORM} 55 | in 56 | 57 | "multipleplatform" ) 58 | BUILD_PLATFORM="linux/amd64,linux/arm64,linux/arm/v7" 59 | ;; 60 | "linux/amd64" | \ 61 | "linux/arm64" | \ 62 | "linux/arm/v7" ) 63 | BUILD_PLATFORM=${PLATFORM} 64 | ;; 65 | 66 | * ) 67 | echo "Bad Platform ${PLATFORM}" 68 | exit 1 69 | ;; 70 | esac 71 | 72 | if [ "${OUTPUTTYPE}" = "docker" ]; 73 | then 74 | echo "Forcing Platform to linux/amd64 as output type is local" 75 | BUILD_PLATFORM="linux/amd64" 76 | fi 77 | 78 | # Tidy Up 79 | docker stop gravitysync 80 | docker rm gravitysync 81 | docker buildx prune -a --force 82 | 83 | # Remove all dangling images except those specified 84 | for r in $(docker image ls --format "{{.Repository}}" --filter "dangling=true"); 85 | do 86 | case ${r} 87 | in 88 | "multiarch/qemu-user-static" | \ 89 | "moby/buildkit") 90 | # Do not remove these images if they exist 91 | ;; 92 | 93 | * ) 94 | # As we are not forcefully removing, any images being used by containers will not be removed 95 | docker rmi "${r}" 2 &> /dev/null; 96 | ;; 97 | esac 98 | done 99 | 100 | # Create Builder 101 | docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 102 | docker buildx create --name gravitysyncdockerbuilder 103 | docker buildx use gravitysyncdockerbuilder 104 | 105 | # Build 106 | docker buildx build "${WORKDIR}" -f "${WORKDIR}/Dockerfile" --squash --platform "${BUILD_PLATFORM}" \ 107 | -t "${REPO_OWNER}gravity-sync-docker:${VERSION}" -t "${REPO_OWNER}gravity-sync-docker:latest" --output=type="${OUTPUTTYPE}" 108 | 109 | docker buildx rm gravitysyncdockerbuilder 110 | 111 | -------------------------------------------------------------------------------- /docker-testenvironment-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.4" 2 | 3 | services: 4 | ssh: 5 | image: "linuxserver/openssh-server:latest" 6 | container_name: "ssh" 7 | restart: "unless-stopped" 8 | hostname: "ssh" 9 | environment: 10 | PUID: "1000" 11 | PGID: "1000" 12 | TZ: "ETC/UTC" 13 | PUBLIC_KEY_FILE: "/tmp/gravitysynctest/.ssh/id_rsa.pub" 14 | SUDO_ACCESS: "true" 15 | USER_NAME: "gravitysync" 16 | networks: 17 | primary: 18 | ipv4_address: "172.31.255.2" 19 | volumes: 20 | - "/tmp/gravitysynctest/:/tmp/gravitysynctest/:rw" 21 | - "/var/run/docker.sock:/var/run/docker.sock:ro" 22 | 23 | pihole1: 24 | image: "pihole/pihole:latest" 25 | container_name: "pihole1" 26 | restart: "unless-stopped" 27 | environment: 28 | TZ: ETC/UTC 29 | DNS1: "1.1.1.1" 30 | DNSSEC: "True" 31 | IPV6: "False" 32 | networks: 33 | primary: 34 | ipv4_address: "172.31.255.3" 35 | dns: 36 | - "1.1.1.1" 37 | volumes: 38 | - "/tmp/gravitysynctest/pihole1/config/dnsmasq.d/:/etc/dnsmasq.d/:rw" 39 | - "/tmp/gravitysynctest/pihole1/config/pihole/:/etc/pihole/:rw" 40 | - "/tmp/gravitysynctest/pihole1/logs/:/var/log/:rw" 41 | 42 | 43 | pihole2: 44 | image: "pihole/pihole:latest" 45 | container_name: "pihole2" 46 | restart: "unless-stopped" 47 | environment: 48 | TZ: ETC/UTC 49 | DNS1: "1.1.1.1" 50 | DNSSEC: "True" 51 | IPV6: "False" 52 | networks: 53 | primary: 54 | ipv4_address: "172.31.255.4" 55 | dns: 56 | - "1.1.1.1" 57 | volumes: 58 | - "/tmp/gravitysynctest/pihole2/config/dnsmasq.d/:/etc/dnsmasq.d/:rw" 59 | - "/tmp/gravitysynctest/pihole2/config/pihole/:/etc/pihole/:rw" 60 | - "/tmp/gravitysynctest/pihole2/logs/:/var/log/:rw" 61 | 62 | 63 | gravitysynctest: 64 | image: "docker_gravity-sync-docker:latest" 65 | container_name: "gravitysynctest" 66 | restart: "unless-stopped" 67 | environment: 68 | TZ: ETC/UTC 69 | REMOTE_HOST: "172.31.255.2" 70 | REMOTE_SSH_PORT: "2222" 71 | REMOTE_USER: "gravitysync" 72 | LOCAL_INSTALL_TYPE: "docker" 73 | REMOTE_INSTALL_TYPE: "docker" 74 | LOCAL_PIHOLE_DIR: "/tmp/gravitysynctest/pihole2/config/pihole/" 75 | REMOTE_PIHOLE_DIR: "/tmp/gravitysynctest/pihole1/config/pihole/" 76 | LOCAL_FILE_OWNER: "root:root" 77 | REMOTE_FILE_OWNER: "root:root" 78 | LOCAL_DOCKER_CON: "pihole2" 79 | REMOTE_DOCKER_CON: "pihole1" 80 | SYNC_FREQUENCY: "30" 81 | BACKUP_HOUR: "4" 82 | DEBUG: "true" 83 | networks: 84 | primary: 85 | ipv4_address: "172.31.255.5" 86 | volumes: 87 | - "/tmp/gravitysynctest/gravitysync/logs/gravity-sync.log:/tmp/gravitysynctest/gravitysync/logs/gravity-sync.log:rw" 88 | - "/tmp/gravitysynctest/gravitysync/logs/gravity-sync.cron:/tmp/gravitysynctest/gravitysync/logs/gravity-sync.cron:rw" 89 | - "/tmp/gravitysynctest/gravitysync/data/backup/:/tmp/gravitysynctest/gravitysync/backup/:rw" 90 | - "/tmp/gravitysynctest/.ssh/:/root/.ssh/:rw" 91 | - "/tmp/gravitysynctest/pihole2/:/tmp/gravitysynctest/pihole2:rw" 92 | - "/var/run/docker.sock:/var/run/docker.sock:ro" 93 | 94 | networks: 95 | primary: 96 | driver: bridge 97 | ipam: 98 | config: 99 | - subnet: "172.31.255.0/24" 100 | -------------------------------------------------------------------------------- /container_scripts/configure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "${DEBUG}" = "true" ]; 4 | then 5 | set -x 6 | set -v 7 | else 8 | set +x 9 | set +v 10 | fi 11 | 12 | setLocalTimezone() 13 | { 14 | apk --update add tzdata 15 | cp /usr/share/zoneinfo/${TZ} /etc/localtime 16 | echo "${TZ}" > /etc/timezone 17 | apk del tzdata 18 | rm -rf /var/cache/apk/* 19 | rm -rf /usr/share/zoneinfo 20 | } 21 | 22 | connectSsh() 23 | { 24 | SSH_OUTPUT="$(ssh -o BatchMode=yes -i ${KEY_PATH} -p${SSH_PORT} ${REMOTE_USER}@${REMOTE_HOST} 'exit 0' 2>&1)" 25 | if [ $? -eq 0 ]; 26 | then 27 | if contains "${SSH_OUTPUT}" "Permission denied"; 28 | then 29 | echo false 30 | else 31 | echo true 32 | fi 33 | else 34 | echo true 35 | fi 36 | } 37 | 38 | checkSshKeys() 39 | { 40 | if [ -z $HOME/$SSH_PKIF ]; 41 | then 42 | KEY_PATH="/root/.ssh/id_rsa" 43 | else 44 | KEY_PATH=$HOME/$SSH_PKIF 45 | fi 46 | 47 | if [ ! -f "${KEY_PATH}" ]; 48 | then 49 | echo "ERROR - SSH Keys do not exist" 50 | exit 1 51 | elif [ ! connectSsh ]; 52 | then 53 | echo "Unable to initiate SSH connection - Permission Denied" 54 | fi 55 | } 56 | 57 | contains() 58 | { 59 | IN="${1}" 60 | PATTERN="${2}" 61 | echo "${1}" | grep -q "${PATTERN}" 62 | } 63 | 64 | createConfigFile() 65 | { 66 | rm -rf /root/gravity-sync/gravity-sync.conf 67 | addToConfigFile "REMOTE_HOST" ${REMOTE_HOST} 68 | addToConfigFile "SSH_PORT" ${REMOTE_SSH_PORT} 69 | addToConfigFile "REMOTE_USER" ${REMOTE_USER} 70 | addToConfigFile "PH_IN_TYPE" ${LOCAL_HOST_TYPE} 71 | addToConfigFile "RH_IN_TYPE" ${REMOTE_HOST_TYPE} 72 | addToConfigFile "PIHOLE_DIR" ${LOCAL_PIHOLE_DIR} 73 | addToConfigFile "RIHOLE_DIR" ${REMOTE_PIHOLE_DIR} 74 | addToConfigFile "DNSMAQ_DIR" ${LOCAL_DNSMASQ_DIR} 75 | addToConfigFile "RNSMAQ_DIR" ${REMOTE_DNSMASQ_DIR} 76 | addToConfigFile "PIHOLE_BIN" ${LOCAL_PIHOLE_BIN} 77 | addToConfigFile "RIHOLE_BIN" ${REMOTE_PIHOLE_BIN} 78 | addToConfigFile "DOCKER_BIN" ${LOCAL_DOCKER_BIN} 79 | addToConfigFile "ROCKER_BIN" ${REMOTE_DOCKER_BIN} 80 | addToConfigFile "FILE_OWNER" ${LOCAL_FILE_OWNER} 81 | addToConfigFile "RILE_OWNER" ${REMOTE_FILE_OWNER} 82 | addToConfigFile "DOCKER_CON" ${LOCAL_DOCKER_CON} 83 | addToConfigFile "ROCKER_CON" ${REMOTE_DOCKER_CON} 84 | addToConfigFile "GRAVITY_FI" ${GRAVITY_FI} 85 | addToConfigFile "CUSTOM_DNS" ${CUSTOM_DNS} 86 | addToConfigFile "VERIFY_PASS" ${VERIFY_PASS} 87 | addToConfigFile "SKIP_CUSTOM" ${SKIP_CUSTOM} 88 | addToConfigFile "INCLUDE_CNAME" ${INCLUDE_CNAME} 89 | addToConfigFile "DATE_OUTPUT" ${DATE_OUTPUT} 90 | addToConfigFile "PING_AVOID" ${PING_AVOID} 91 | addToConfigFile "ROOT_CHECK_AVOID" ${ROOT_CHECK_AVOID} 92 | addToConfigFile "BACKUP_RETAIN" ${BACKUP_RETAIN} 93 | addToConfigFile "SSH_PKIF" ${SSH_PKIF} 94 | addToConfigFile "BACKUP_TIMEOUT" ${BACKUP_TIMEOUT} 95 | } 96 | 97 | addToConfigFile() 98 | { 99 | SETTING=$1 100 | VALUE=$2 101 | if [ ! -z $VALUE ]; 102 | then 103 | echo "${SETTING}='${VALUE}'" >> /root/gravity-sync/gravity-sync.conf; 104 | fi 105 | } 106 | 107 | setLocalTimezone 108 | 109 | /usr/local/bin/upgradeCompatibilityChecks.sh 110 | 111 | if [[ "$?" != "0" ]]; 112 | then 113 | echo "Failed the upgrade compatibility check" 114 | exit 1; 115 | fi 116 | 117 | checkSshKeys 118 | createConfigFile 119 | /root/gravity-sync/gravity-sync.sh automate ${SYNC_FREQUENCY} ${BACKUP_HOUR} 120 | 121 | echo 'Finished Configuration' 122 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3 as baseenvironment 2 | 3 | LABEL maintainer Michael Thompson <25192401+nh-mike@users.noreply.github.com> 4 | 5 | ENV GS_INSTALL="secondary" \ 6 | GS_VERSION="3.6.2" \ 7 | GENERATE_SSH_CERTS="true" \ 8 | TINI_VERSION="0.19.0" \ 9 | DEBUG="false" \ 10 | SYNC_FREQUENCY="30" \ 11 | REMOTE_HOST="127.0.0.1" \ 12 | SSH_PORT="22" \ 13 | REMOTE_USER="root" \ 14 | LOCAL_HOST_TYPE="docker" \ 15 | REMOTE_HOST_TYPE="docker" \ 16 | LOCAL_PIHOLE_DIR="/etc/pihole/" \ 17 | REMOTE_PIHOLE_DIR="/etc/pihole/" \ 18 | LOCAL_PIHOLE_BIN="" \ 19 | REMOTE_PIHOLE_BIN="" \ 20 | LOCAL_PH_INSTALL_TYPE="default" \ 21 | LOCAL_RH_INSTALL_TYPE="default" \ 22 | LOCAL_DOCKER_BIN="" \ 23 | REMOTE_DOCKER_BIN="" \ 24 | LOCAL_FILE_OWNER="root:root" \ 25 | REMOTE_FILE_OWNER="root:root" \ 26 | LOCAL_DOCKER_CON="" \ 27 | REMOTE_DOCKER_CON="" \ 28 | GRAVITY_FI="" \ 29 | CUSTOM_DNS="" \ 30 | VERIFY_PASS="" \ 31 | SKIP_CUSTOM="" \ 32 | DATE_OUTPUT="" \ 33 | PING_AVOID="" \ 34 | ROOT_CHECK_AVOID="" \ 35 | SSH_PKIF=".ssh/id_rsa" 36 | 37 | COPY ./container_scripts/install_tini.sh /usr/local/bin/install_tini.sh 38 | 39 | RUN chmod +x /usr/local/bin/install_tini.sh && \ 40 | apk --update add openssh sudo bash coreutils && \ 41 | /usr/local/bin/install_tini.sh 42 | 43 | FROM baseenvironment as buildenvironment 44 | 45 | # apk --update add less rsync sqlite 46 | RUN apk --update add curl && \ 47 | rm -rf /var/lib/apt/lists/* && \ 48 | rm /var/cache/apk/* && \ 49 | cd /tmp/ && \ 50 | wget https://github.com/vmstan/gravity-sync/archive/v$GS_VERSION.zip && \ 51 | mkdir /tmp/gravity-sync/ && \ 52 | unzip v$GS_VERSION.zip -d /tmp/gravity-sync/ && \ 53 | mv /tmp/gravity-sync/gravity-sync-$GS_VERSION /root/gravity-sync 54 | 55 | 56 | FROM baseenvironment as prodbuildenvironment 57 | 58 | #COPY configure.sh /usr/local/bin/configure.sh 59 | #COPY missionreport.sh /usr/local/bin/missionreport.sh 60 | #COPY prelaunch.sh /usr/local/bin/prelaunch.sh 61 | #COPY startup.sh /usr/local/bin/startup.sh 62 | #COPY upgradeCompatibilityChecks.sh /usr/local/bin/upgradeCompatibilityChecks.sh 63 | COPY container_scripts/* /usr/local/bin/ 64 | COPY --from=buildenvironment /root/gravity-sync/ /root/gravity-sync/ 65 | 66 | WORKDIR /root/gravity-sync/ 67 | 68 | RUN apk --update add rsync sqlite docker-cli util-linux && \ 69 | rm -rf /var/lib/apt/lists/* && \ 70 | rm /var/cache/apk/* && \ 71 | echo 'echo "Git is not required"' > /usr/local/bin/git && \ 72 | chmod +x /usr/local/bin/git && \ 73 | chmod +x /usr/local/bin/configure.sh && \ 74 | chmod +x /usr/local/bin/missionreport.sh && \ 75 | chmod +x /usr/local/bin/prelaunch.sh && \ 76 | chmod +x /usr/local/bin/startup.sh && \ 77 | chmod +x /usr/local/bin/upgradeCompatibilityChecks.sh 78 | 79 | HEALTHCHECK --interval=5m --timeout=60s --start-period=10s \ 80 | CMD /usr/local/bin/missionreport.sh 81 | 82 | ENTRYPOINT ["/tini", "--"] 83 | CMD ["/usr/local/bin/startup.sh"] 84 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [3.6.2] - 21-03-2022 2 | ### Changed 3 | - Update to GravitySync version 3.6.2 4 | 5 | ## [3.6.1] - 21-03-2022 6 | ### Changed 7 | - Update to GravitySync version 3.6.1 8 | 9 | ## [3.6.0] - 21-03-2022 10 | ### Changed 11 | - Update to GravitySync version 3.6.0 12 | 13 | ## [3.5.0] - 15-03-2022 14 | ### Changed 15 | - Update to GravitySync version 3.5.0 16 | - Updated README.md to reflect removal of backup functionality 17 | - Updated dev_scripts/cibuild and dev_scripts/test to add image squashing and more flexibility 18 | 19 | ### Removed 20 | - Configration Options BACKUP_RETAIN and BACKUP_TIMEOUT 21 | - Legacy unsupported BACKUP_HOUR option (removed in GravitySync 3.3.0) 22 | - Build Target linux/arm (no longer supported upstream) 23 | 24 | ## [3.4.8] - 13-01-2021 25 | ### Changed 26 | - Update to GravitySync version 3.4.8 27 | - Fix bootstrap script always downloading buildx 28 | - Update all development scripts to pass shellcheck.net 29 | 30 | ## [3.4.7] - 29-09-2021 31 | ### Changed 32 | - Update to GravitySync version 3.4.7 33 | 34 | ## [3.4.5] - 20-07-2021 35 | ### Changed 36 | - Update to GravitySync version 3.4.5 37 | - Updated README.md to reflect current state of arm images 38 | - Script improvements for better reliability 39 | 40 | ### Added 41 | - Buildx platform linux/arm/v6 42 | 43 | ### Removed 44 | - Buildx platform linux/arm 45 | 46 | ## [3.4.4.2] - 2021-05-09 47 | ### Changed 48 | - Require push to be specified when running cibuild in order to push to Docker Hub 49 | - Fixed input device errors in CI by removing interactive TTY flags from docker commands 50 | - Changed dnstest in CI tests to dnstest.local to prevent auto-filling the domain name 51 | 52 | ### Added 53 | - Added GitHub Actions test and Cross Build CI runner 54 | 55 | ## [3.4.4.1] - 2021-05-08 56 | ### Changed 57 | - Massive changes related to building and testing 58 | - Odrered scripts into appropreate directories 59 | - Tidy up script code where multiple scripting styles were used 60 | - Test script will now build an x86_64 image as a test stage 61 | - No need to run cibuild before running test 62 | - Run cibuild for a production ready image 63 | - Requires a --version flag (i.e. --version 1.2.3) 64 | - Does not require --platform tag unless intending to build single platform 65 | 66 | - Install Tini Init system from a script picking build based on current architecture 67 | 68 | ### Added 69 | - Implement support for building ARM based images 70 | - Bootstrap script for installing build requirements 71 | 72 | ### Removed 73 | - Previous initial support for building ARM based images 74 | 75 | ## [3.4.4] - 2021-04-29 76 | ### Changed 77 | - Update to GravitySync version 3.4.4 78 | 79 | ## [3.4.2.1] - 2021-04-25 80 | ### Added 81 | - Initial support for building ARM based images 82 | 83 | ### Changed 84 | - Updated README.md to reflect ARM additions 85 | 86 | ## [3.4.2] - 2021-04-07 87 | ### Changed 88 | - Update to GravitySync version 3.4.2 89 | 90 | ## [3.4.1] - 2021-04-07 91 | ### Changed 92 | - Update to GravitySync version 3.4.1 93 | - Fixed bug where passwordless sudo may not be granted in SSH container during testing 94 | - Tidy up docker compose file 95 | - Add support for new BACKUP_TIMEOUT option 96 | 97 | ## [3.4.0] - 2021-04-06 98 | ### Changed 99 | - Update to GravitySync version 3.4.0 100 | 101 | ## [3.3.2] - 2021-02-17 102 | ### Added 103 | - Added gsbuild, gstest and docker-testenvironment-compose.yml for scripted build and testing 104 | - Added doocumentation and config options for remote SSH port and DNSMASQ directory locations 105 | 106 | ### Changed 107 | - Update to GravitySync version 3.3.2 108 | 109 | ## [3.2.6.1] - 2021-02-08 110 | ### Added 111 | - Added section to Readme to inform users to persist gravity-sync.md5 112 | - Update Dockerfile to add util-linux for support of the namei command 113 | - Create and backfill CHANGELOG.md 114 | - Added timezone correction (as this does not come with Alpine by default) 115 | - Added Healthcheck (Mission Report) 116 | - Fix syntax error in configuration script 117 | 118 | ## [3.2.6] - 2021-02-05 119 | ### Changed 120 | - Update to GravitySync version 3.2.6 121 | 122 | ## [3.2.5.1] - 2021-02-04 123 | ### Added 124 | - Item in todo in Readme to document gravity-sync.md5 persist requirements 125 | - Add placeholder for Git when running GravitySync Info 126 | - Install Coreutils to allow for timeout --preserve-status 127 | 128 | ## [3.2.5] - 2021-02-03 129 | ### Changed 130 | - Update to GravitySync version 3.2.5 131 | 132 | ## [3.2.4.1] - 2021-01-25 133 | ### Changed 134 | - Correct indenting of Dockerfile 135 | 136 | ## [3.2.4] - 2021-01-19 137 | ### Added 138 | - Initial commit at GravitySync version 3.2.4 139 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | With the discontinuation of Gravity Sync, it is time to archive this project. 2 | Thanks to everyone who has used my little project. 3 | 4 | [![CI Pipeline](https://github.com/nh-mike/gravity-sync-docker/actions/workflows/ci-pipeline.yml/badge.svg)](https://github.com/nh-mike/gravity-sync-docker/actions/workflows/ci-pipeline.yml) 5 | # Gravity Sync Docker 6 | 7 | These are the files required to run a Docker image running [Gravity Sync](https://github.com/vmstan/gravity-sync). Supports X86/64 and ARM. 8 | 9 | #### Before Running! 10 | If upgrading, then check the [Upgrade Instructions](#upgrade-instructions) for your intended release.
11 | You need to run the pre-launch scripts which will configure your remote host. Naturally, I reccomend you follow all reccomendations. Otherwise, you may have to do some manual configuration, or run with potentially less than desirable security configuration.
12 | To run this is quite simple. Firstly, we must have a directory in place to map to the .ssh directory within the container.
13 | `mkdir /path/to/gravitysync/.ssh`
14 | Then, simply run the container in interactive mode, mounting this directory and entering at the pre-flight script file.
15 | `docker run -t -i -v "/path/to/gravitysync/.ssh:/root/.ssh:rw" --rm docker_gravitysync /usr/local/bin/prelaunch.sh` 16 | 17 | #### Manual pre-launch 18 | Pre-generate your SSH keys and mount them into the container. Follow the instructions in the [SSH Keys section](#ssh-keys). I also recommend you create a user on the remote machine for the purpose of receiving the SSH connection. I personally created the user gravitysync. See the sections [SSH Keys](#ssh-keys) and [User Creation Recommendation](#user-creation-recommendation) below. 19 | 20 | #### Configuration of the container 21 | For instructions on how to configure the Gravity Sync service, please see https://github.com/vmstan/gravity-sync
22 | It is important to note that in the interests of making configuration values more sensical to most people, not all setting names in this "Docker Image" are identical to those in "Vanialla Gravity Sync". You can see these changes marked with an explaimation mark in the table below. Simply, the defined Environmental variables are mapped to the settings name upon the container's first run (install run) when the container builds the configuration file. Please do not try to mount your own configuration file as this will cause failure of the container. 23 | 24 | || Vanilla GS | Docker Image | 25 | | ------ | ------ | ------ | 26 | ||REMOTE_HOST|REMOTE_HOST| 27 | |**!**|SSH_PORT|REMOTE_SSH_PORT| 28 | ||REMOTE_USER|REMOTE_USER| 29 | |**!**|PH_IN_TYPE|LOCAL_HOST_TYPE| 30 | |**!**|RH_IN_TYPE|REMOTE_HOST_TYPE| 31 | |**!**|PIHOLE_DIR|LOCAL_PIHOLE_DIR| 32 | |**!**|RIHOLE_DIR|REMOTE_PIHOLE_DIR| 33 | |**!**|DNSMAQ_DIR|LOCAL_DNSMASQ_DIR| 34 | |**!**|RNSMAQ_DIR|REMOTE_DNSMASQ_DIR| 35 | |**!**|PIHOLE_BIN|LOCAL_PIHOLE_BIN| 36 | |**!**|RIHOLE_BIN|REMOTE_PIHOLE_BIN| 37 | |**!**|PH_IN_TYPE|LOCAL_PH_INSTALL_TYPE| 38 | |**!**|RH_IN_TYPE|REMOTE_PH_INSTALL_TYPE| 39 | |**!**|DOCKER_BIN|LOCAL_DOCKER_BIN| 40 | |**!**|ROCKER_BIN|REMOTE_DOCKER_BIN| 41 | |**!**|FILE_OWNER|LOCAL_FILE_OWNER| 42 | |**!**|RILE_OWNER|REMOTE_FILE_OWNER| 43 | |**!**|DOCKER_CON|LOCAL_DOCKER_CON| 44 | |**!**|ROCKER_CON|REMOTE_DOCKER_CON| 45 | ||GRAVITY_FI|GRAVITY_FI| 46 | ||CUSTOM_DNS|CUSTOM_DNS| 47 | ||INCLUDE_CNAME|INCLUDE_CNAME| 48 | ||VERIFY_PASS|VERIFY_PASS| 49 | ||SKIP_CUSTOM|SKIP_CUSTOM| 50 | ||DATE_OUTPUT|DATE_OUTPUT| 51 | ||PING_AVOID|PING_AVOID| 52 | ||ROOT_CHECK_AVOID|ROOT_CHECK_AVOID| 53 | ||SSH_PKIF|SSH_PKIF| 54 | 55 | #### Docker Compose example: 56 | ``` 57 | gravitysync: 58 | build: 59 | context: /docker/gravity-sync-docker/ 60 | dockerfile: /docker/gravity-sync-docker/Dockerfile 61 | container_name: "gravitysync" 62 | restart: "unless-stopped" 63 | environment: 64 | TZ: "ETC/UTC" 65 | REMOTE_HOST: "192.168.0.1" 66 | REMOTE_USER: "gravitysync" 67 | LOCAL_INSTALL_TYPE: "docker" 68 | REMOTE_INSTALL_TYPE: "docker" 69 | LOCAL_PIHOLE_DIR: "/etc/pihole/" 70 | REMOTE_PIHOLE_DIR: "/docker/pihole/config/pihole/" 71 | LOCAL_DNSMASQ_DIR: "/etc/dnsmasq.d/" 72 | REMOTE_DNSMASQ_DIR: "/docker/pihole/config/dnsmasq/" 73 | LOCAL_PH_INSTALL_TYPE: "default" 74 | REMOTE_PH_INSTALL_TYPE: "docker" 75 | LOCAL_FILE_OWNER: "root:root" 76 | REMOTE_FILE_OWNER: "root:root" 77 | INCLUDE_CNAME: "1" 78 | SYNC_FREQUENCY: "15" 79 | DEBUG: "true" 80 | volumes: 81 | - "/docker/gravity-sync/logs/:/root/gravity-sync/logs/:rw" 82 | - "/docker/gravity-sync/data/gravity-sync.md5:/root/gravity-sync/gravity-sync.md5:rw" 83 | - "/docker/gravity-sync/data/.ssh/:/root/.ssh/:rw" 84 | - "/docker/pihole/config/pihole:/etc/pihole/:rw" 85 | - "/docker/pihole/config/dnsmasq:/etc/dnsmasq.d/:rw" 86 | - "/var/run/docker.sock:/var/run/docker.sock:ro" 87 | ``` 88 | 89 | #### Mount Points 90 | The following are the mount points within the container. You can map them to wherever you like on your host. 91 | 92 | ###### Docker Socket 93 | `/var/run/docker.sock - READ ONLY`
94 | This is required to allow the container to interact with the Docker process on the host, to pass along commands to your PiHole container.
95 | It is located at `/var/run/docker.sock` and should be mounted at `/var/run/docker.sock` and only requires read access. 96 | 97 | ###### Secondary PiHole Configuration Directory 98 | `/etc/pihole/ - READ / WRITE`
99 | This is where your gravity database sits. On a standard PiHole install, it would sit at `/etc/pihole`. Ensure that wherever you mount this in the Gravity Sync container, you configure the ***LOCAL_PIHOLE_DIR*** to the same value (directory within the container). I personally prefer to mount it at `/etc/pihole/`. 100 | 101 | ###### Gravity Sync Log Files 102 | `/root/gravity-sync/logs/gravity-sync.log - READ / WRITE`
103 | `/root/gravity-sync/logs/gravity-sync.cron - READ / WRITE`
104 | Gravity Sync keeps a log file of it's most recent Cron run and also records of previous runs. You may find it useful to mount these from the host for easy viewing and also, if you wish to persist your logs between container rebuilds. 105 | 106 | ###### Gravity Sync MD5 File 107 | `/root/gravity-sync/gravity-sync.md5 - READ / WRITE`
108 | Gravity Sync records the MD5 hash for both the local and remote gravity.db, custom.list and 05-pihole-custom-cname.conf within this file. Ideally, we want to preserve these hashes between instances of the container. 109 | 110 | ###### SSH Keys Directory 111 | `/root/.ssh/ - READ ONLY*`
112 | SSH Keys must be configured and in place before the container is run for the first time. Without this, the initial run will try to generate keys. Without persisting this directory, the container continue to generate new keys with each run and so will be unable to connect to the remote host. Review the [SSH Keys section](#ssh-keys) below. 113 | 114 | #### User Creation Recommendation 115 | **If you ran the pre-launch scripts, then you were presented the option to have this done for you**
116 | I created the user gravitysync on my remote machine, as I have SSH for the root account disabled. Also, since this is a service account, I did not want it using my personal system administration account. This account requires passwordless sudo, and also must have root access in order to have read / write access to the PiHole configuration on the remote system. Here is how I achieved that on an Ubuntu host.
117 | ``` 118 | sudo adduser gravitysync 119 | sudo echo "gravitysync ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/gravitysync 120 | sudo usermod -a -G sudo gravitysync 121 | sudo usermod -a -G docker gravitysync 122 | ``` 123 | I also reccomend for the security conscious, to create a more locked down sudoers file, following the discussion [here](https://github.com/vmstan/gravity-sync/discussions/153). 124 | 125 | #### SSH KEYS 126 | **If you ran the pre-launch scripts, then this will have been done for you**
127 | In order to communicate with the remote host, SSH keys are required. An easy way to generate them is using the OpenSSH client. Using the following single liner, we can be sure on being able to generate these keys on any system.
128 | `docker run -t -i --rm alpine:latest apk --update add openssh-client && ssh-keygen -t rsa -f /tmp/id_rsa`
129 | Alternatively, if you have OpenSSH on your system already, you can use that. You then need to copy the key to the remote system. An easy way to do this is using ssh-copy-id like so:
130 | `ssh-copy-id -i /tmp/id_rsa.pub gravitysync@192.168.0.1`.
131 | This assumes that the key generated is indeed located at `/tmp/id_rsa.pub`, that the remote username is `gravitysync` and that the remote system is located at `192.168.0.1`. 132 | 133 | #### Upgrade Instructions 134 | ###### 3.5.0 135 | This version removes backup retention from GravitySync. This has happened upstream within GravitySync itself. For more information, read the [release notes](https://github.com/vmstan/gravity-sync/releases/tag/v3.5.0). 136 | 137 | ###### 3.0.0 138 | This version includes various neccesary configuration changes, including the changing of log directory mount points within the container. See [Gravity Sync Log Files](#gravity-sync-log-files) for the new mount points.
139 | This version also adds two new configuration options, LOCAL_PH_INSTALL_TYPE and REMOTE_PH_INSTALL_TYPE 140 | --------------------------------------------------------------------------------