From e42eef8fcdad28fe43ea289be015def7a58a8755 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 28 Jun 2017 18:12:49 -0700 Subject: [PATCH] Add x86 and arm builds and tests --- .dockerignore | 3 +++ Dockerfile.raspbian | 29 +++++++++++++++++++++++++++++ Dockerfile => Dockerfile.ubuntu | 1 + Makefile | 21 +++++++++++++++++++++ entrypoint.sh | 2 +- test.sh | 15 +++++++++++++++ verify.sh | 4 ++++ 7 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.raspbian rename Dockerfile => Dockerfile.ubuntu (97%) create mode 100644 Makefile create mode 100755 test.sh create mode 100755 verify.sh diff --git a/.dockerignore b/.dockerignore index 11d220f..23d6153 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,5 @@ +Dockerfile.* +Makefile Readme.md docker-compose.yaml +test.sh diff --git a/Dockerfile.raspbian b/Dockerfile.raspbian new file mode 100644 index 0000000..a2c6e5e --- /dev/null +++ b/Dockerfile.raspbian @@ -0,0 +1,29 @@ +FROM resin/rpi-raspbian:jessie +MAINTAINER ViViDboarder + +RUN [ "cross-build-start" ] + +RUN apt-get update \ + && apt-get install -y duplicity python-setuptools \ + python-boto python-swiftclient python-pexpect openssh-client \ + && rm -rf /var/apt/lists/* + +RUN [ "cross-build-end" ] + +VOLUME "/root/.cache/duplicity" +VOLUME "/backups" + +ENV BACKUP_DEST="file:///backups" +ENV BACKUP_NAME="backup" +ENV PATH_TO_BACKUP="/data" +ENV PASSPHRASE="Correct.Horse.Battery.Staple" + +# Cron schedules +ENV CRON_SCHEDULE="" +ENV VERIFY_CRON_SCHEDULE="" + +ADD entrypoint.sh / +ADD backup.sh / +ADD verify.sh / + +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/Dockerfile b/Dockerfile.ubuntu similarity index 97% rename from Dockerfile rename to Dockerfile.ubuntu index dc4de15..f3a0eca 100644 --- a/Dockerfile +++ b/Dockerfile.ubuntu @@ -23,5 +23,6 @@ ENV VERIFY_CRON_SCHEDULE="" ADD entrypoint.sh / ADD backup.sh / +ADD verify.sh / ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7d5388c --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +.PHONY: build-x86 build-arm build-all + +DOCKER_TAG ?= docker-duplicity-cron + +default: build-x86 + +build-x86: + docker build -f ./Dockerfile.ubuntu -t $(DOCKER_TAG):ubuntu . + +build-arm: + docker build -f ./Dockerfile.raspbian -t $(DOCKER_TAG):raspbian . + +build-all: build-x86 build-arm + +test-x86: build-x86 + ./test.sh $(DOCKER_TAG) ubuntu + +test-arm: build-arm + ./test.sh $(DOCKER_TAG) raspbian + +test-all: test-x86 test-arm diff --git a/entrypoint.sh b/entrypoint.sh index 681a142..144736d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,7 +25,7 @@ if [ -n "$CRON_SCHEDULE" ]; then echo "Backups scheduled as $CRON_SCHEDULE" if [ -n "$VERIFY_CRON_SCHEDULE" ]; then - echo "$VERIFY_CRON_SCHEDULE source /env.sh && duplicity verify $BACKUP_DEST $PATH_TO_BACKUP" >> /crontab.conf + echo "$VERIFY_CRON_SCHEDULE source /env.sh && /verify.sh 2>> /cron.log" >> /crontab.conf echo "Verify scheduled as $VERIFY_CRON_SCHEDULE" fi diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..af8ab5a --- /dev/null +++ b/test.sh @@ -0,0 +1,15 @@ +#! /bin/bash + +image_name=$1 +tag=$2 + +full_image="${image_name}:${tag}" +container_name="${image_name}-${tag}" + +docker run -d -e CRON_SCHEDULE="0 0 12 1 1 ? *" -e SKIP_ON_START=true --name $container_name $full_image +sleep 2 +docker exec $container_name sh -c "mkdir -p /data && echo Test > /data/test.txt" +docker exec $container_name /backup.sh +docker exec $container_name /verify.sh +docker stop $container_name +docker rm $container_name diff --git a/verify.sh b/verify.sh new file mode 100755 index 0000000..49f73ce --- /dev/null +++ b/verify.sh @@ -0,0 +1,4 @@ +#! /bin/bash +set -e + +duplicity verify $BACKUP_DEST $PATH_TO_BACKUP