From 5e99ccbc9f80c384204d5bbe782e25a35077707c Mon Sep 17 00:00:00 2001 From: Stefan Bratic Date: Wed, 19 Jun 2019 10:18:06 +0000 Subject: [PATCH 1/5] added general repository checking --- entry.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/entry.sh b/entry.sh index a01f82d..42ae1d8 100755 --- a/entry.sh +++ b/entry.sh @@ -1,5 +1,4 @@ #!bin/sh -set -e echo "Starting container ..." @@ -14,11 +13,22 @@ if [ -n "${NFS_TARGET}" ]; then mount -o nolock -v ${NFS_TARGET} /mnt/restic fi -if [ ! -f "$RESTIC_REPOSITORY/config" ]; then +restic snapshots &>/dev/null +status=$? +echo "Check Repo status $status" + +if [ $status != 0 ]; then echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init." restic init | true + + if [ $? == 0 ]; then + echo "Failed to init the repository: '${RESTIC_REPOSITORY}'" + exit 1 + fi fi + + echo "Setup backup cron job with cron expression BACKUP_CRON: ${BACKUP_CRON}" echo "${BACKUP_CRON} /bin/backup >> /var/log/cron.log 2>&1" > /var/spool/cron/crontabs/root @@ -30,4 +40,4 @@ crond echo "Container started." -tail -fn0 /var/log/cron.log +tail -fn0 /var/log/cron.log \ No newline at end of file From 6bedee1ab1bbf44c2702afffeaeb27d94eabd5b6 Mon Sep 17 00:00:00 2001 From: Stefan Bratic Date: Wed, 19 Jun 2019 11:05:34 +0000 Subject: [PATCH 2/5] fixed status check --- entry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry.sh b/entry.sh index 42ae1d8..cfaa7b3 100755 --- a/entry.sh +++ b/entry.sh @@ -21,7 +21,7 @@ if [ $status != 0 ]; then echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init." restic init | true - if [ $? == 0 ]; then + if [ $? != 0 ]; then echo "Failed to init the repository: '${RESTIC_REPOSITORY}'" exit 1 fi From 8a49ee9a53d1a2e1b0386498f890f3f52f596ab1 Mon Sep 17 00:00:00 2001 From: Cobrijani Date: Wed, 19 Jun 2019 21:06:17 +0000 Subject: [PATCH 3/5] corrected check status --- entry.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/entry.sh b/entry.sh index cfaa7b3..42c3ea5 100755 --- a/entry.sh +++ b/entry.sh @@ -19,9 +19,12 @@ echo "Check Repo status $status" if [ $status != 0 ]; then echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init." - restic init | true + restic init - if [ $? != 0 ]; then + init_status=$? + echo "Repo init status $init_status" + + if [ $init_status != 0 ]; then echo "Failed to init the repository: '${RESTIC_REPOSITORY}'" exit 1 fi From f4275c5aef2e7d10399b6bf28a39a467890a454b Mon Sep 17 00:00:00 2001 From: Cobrijani Date: Sun, 7 Jul 2019 12:44:55 +0100 Subject: [PATCH 4/5] added changes from master --- Dockerfile | 2 +- config.yml | 21 +++++++++++++++++++++ docker-compose.test.yml | 9 +++++++++ entry.sh | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 config.yml create mode 100644 docker-compose.test.yml diff --git a/Dockerfile b/Dockerfile index e3c3742..f64f3ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,4 +33,4 @@ RUN touch /var/log/cron.log WORKDIR "/" ENTRYPOINT ["/entry.sh"] - +CMD ["tail","-fn0","/var/log/cron.log"] \ No newline at end of file diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..12228f0 --- /dev/null +++ b/config.yml @@ -0,0 +1,21 @@ +schemaVersion: '2.0.0' +commandTests: + - name: "restic package installation" + setup: [["/entry.sh"]] + command: "which" + args: ["restic"] + expectedOutput: ["/bin/restic"] +fileExistenceTests: +- name: 'log directory exists' + path: '/var/log' + shouldExist: true +- name: 'cron log file exists' + path: '/var/log/cron.log' + shouldExist: true +- name: 'backup script exists' + path: '/bin/backup' + shouldExist: true +metadataTest: + volumes: ["/data"] + entrypoint: ["/entry.sh"] + cmd: ["tail","-fn0", "/var/log/cron.log"] \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..364a7b6 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,9 @@ +version: '2' + +services: + test: + image: gcr.io/gcp-runtimes/container-structure-test + command: ["test", "--image", "restic-backup", "--config", "config.yml"] + volumes: + - ./config.yml:/config.yml + - /var/run/docker.sock:/var/run/docker.sock \ No newline at end of file diff --git a/entry.sh b/entry.sh index 42c3ea5..38fb703 100755 --- a/entry.sh +++ b/entry.sh @@ -43,4 +43,4 @@ crond echo "Container started." -tail -fn0 /var/log/cron.log \ No newline at end of file +exec "$@" \ No newline at end of file From 5f5f75f9030c3915d5ba7bfac246d31757523171 Mon Sep 17 00:00:00 2001 From: Stefan Bratic Date: Fri, 19 Jul 2019 10:13:21 +0000 Subject: [PATCH 5/5] Fixed dockerhub test --- docker-compose.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 364a7b6..61ac2c3 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,7 +1,7 @@ version: '2' services: - test: + sut: image: gcr.io/gcp-runtimes/container-structure-test command: ["test", "--image", "restic-backup", "--config", "config.yml"] volumes: