diff --git a/infrastrucure/docker/image/Dockerfile b/infrastrucure/docker/image/Dockerfile index 083917d..8f3c30d 100644 --- a/infrastrucure/docker/image/Dockerfile +++ b/infrastrucure/docker/image/Dockerfile @@ -1,28 +1,7 @@ FROM ubuntu:focal -# https://stackoverflow.com/questions/59299133/how-to-silent-install-postgresql-in-ubuntu-via-dockerfile ARG DEBIAN_FRONTEND=noninteractive - -RUN apt-get update > /dev/null; \ - apt-get install restic ca-certificates -y > /dev/null; \ - update-ca-certificates - - -# This will install the latest postgresql version -# Taken from https://www.postgresql.org/download/linux/ubuntu/ -RUN apt-get -y install vim bash-completion wget lsb-release gnupg -# Create the file repository configuration: -RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' -# Import the repository signing key: -RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - -# Update the package lists: -RUN apt-get update -# Install the latest version of PostgreSQL. -# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql': -RUN apt-get -y install postgresql-client-13 - - -# Prepare Entrypoint Script -ADD resources /usr/local/bin/ -RUN chmod 700 /usr/local/bin/entrypoint.sh /usr/local/bin/create_pgpass.sh /usr/local/bin/backup.sh /usr/local/bin/restore.sh +# install it +ADD resources /tmp/ +RUN /tmp/install.sh diff --git a/infrastrucure/docker/image/resources/backup.sh b/infrastrucure/docker/image/resources/backup.sh old mode 100644 new mode 100755 index 9f5d1b2..bdff344 --- a/infrastrucure/docker/image/resources/backup.sh +++ b/infrastrucure/docker/image/resources/backup.sh @@ -1,6 +1,10 @@ +#!/bin/bash + set -o pipefail + # backup database dump pg_dump -d $(cat ${POSTGRES_DB_FILE}) -h $POSTGRES_SERVICE -p $POSTGRES_PORT -U $(cat ${POSTGRES_USER_FILE}) --no-password --serializable-deferrable --clean --no-privileges | \ restic -r $RESTIC_REPOSITORY --verbose backup --stdin --tag DB_Backup + # backup nextcloud filesystem restic -r $RESTIC_REPOSITORY backup /var/backups/ --tag Nextcloud_Filesystem diff --git a/infrastrucure/docker/image/resources/create_pgpass.sh b/infrastrucure/docker/image/resources/create_pgpass.sh deleted file mode 100644 index 9ccf5da..0000000 --- a/infrastrucure/docker/image/resources/create_pgpass.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -echo "${POSTGRES_HOST}:$(cat ${POSTGRES_DB_FILE}):$(cat ${POSTGRES_USER_FILE}):$(cat ${POSTGRES_PASSWORD_FILE})" > /root/.pgpass -echo "${POSTGRES_HOST}:template1:$(cat ${POSTGRES_USER_FILE}):$(cat ${POSTGRES_PASSWORD_FILE})" >> /root/.pgpass -chmod 0600 /root/.pgpass diff --git a/infrastrucure/docker/image/resources/entrypoint.sh b/infrastrucure/docker/image/resources/entrypoint.sh old mode 100644 new mode 100755 index 62ff78e..5473fec --- a/infrastrucure/docker/image/resources/entrypoint.sh +++ b/infrastrucure/docker/image/resources/entrypoint.sh @@ -1,6 +1,8 @@ #!/bin/bash -/usr/local/bin/create_pgpass.sh +echo "${POSTGRES_HOST}:$(cat ${POSTGRES_DB_FILE}):$(cat ${POSTGRES_USER_FILE}):$(cat ${POSTGRES_PASSWORD_FILE})" > /root/.pgpass +echo "${POSTGRES_HOST}:template1:$(cat ${POSTGRES_USER_FILE}):$(cat ${POSTGRES_PASSWORD_FILE})" >> /root/.pgpass +chmod 0600 /root/.pgpass # Idle process while true; do diff --git a/infrastrucure/docker/image/resources/init.sh b/infrastrucure/docker/image/resources/init.sh new file mode 100755 index 0000000..15b970b --- /dev/null +++ b/infrastrucure/docker/image/resources/init.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +restic -r $RESTIC_REPOSITORY --verbose init diff --git a/infrastrucure/docker/image/resources/install.sh b/infrastrucure/docker/image/resources/install.sh new file mode 100755 index 0000000..93b9e91 --- /dev/null +++ b/infrastrucure/docker/image/resources/install.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +apt-get update > /dev/null; +apt-get install -qqy ca-certificates curl wget gnupg > /dev/null +sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt focal-pgdg main" > /etc/apt/sources.list.d/pgdg.list' +wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + +apt-get update > /dev/null; +apt-get -qqy install wget postgresql-client-13 restic > /dev/null; + +update-ca-certificates + +install -m 0700 /tmp/entrypoint.sh /usr/local/bin/ +install -m 0700 /tmp/init.sh /usr/local/bin/ +install -m 0700 /tmp/backup.sh /usr/local/bin/ +install -m 0700 /tmp/restore.sh /usr/local/bin/ diff --git a/infrastrucure/docker/image/resources/restore.sh b/infrastrucure/docker/image/resources/restore.sh old mode 100644 new mode 100755 index cd8bbf9..c5f54d2 --- a/infrastrucure/docker/image/resources/restore.sh +++ b/infrastrucure/docker/image/resources/restore.sh @@ -1,4 +1,7 @@ +#!/bin/bash + # Restore Nextcloud Filesystem +# TODO: describe input params # Reads restore snapshot_ID from first CLI Argument restic -r $RESTIC_REPOSITORY restore $1 --target / diff --git a/infrastrucure/docker/test/Dockerfile b/infrastrucure/docker/test/Dockerfile index 435a68b..e243a95 100644 --- a/infrastrucure/docker/test/Dockerfile +++ b/infrastrucure/docker/test/Dockerfile @@ -1,6 +1,6 @@ -FROM meissa-cloud +FROM dda-backup -RUN apt-get -yqq install curl openjdk-11-jre > /dev/null +RUN apt -yqq install openjdk-13-jre-headless > /dev/null RUN curl -L -o /tmp/serverspec.jar https://github.com/DomainDrivenArchitecture/dda-serverspec-crate/releases/download/2.0.0/dda-serverspec-standalone.jar diff --git a/infrastrucure/docker/test/serverspec.edn b/infrastrucure/docker/test/serverspec.edn index 830f957..c1bbe46 100644 --- a/infrastrucure/docker/test/serverspec.edn +++ b/infrastrucure/docker/test/serverspec.edn @@ -1,2 +1,6 @@ {:package [{:name "restic"} - {:name "postgresql-client-12"}]} + {:name "postgresql-client-13"}] + :file [{:path "/usr/local/bin/entrypoint.sh" :mod "700"} + {:path "/usr/local/bin/init.sh" :mod "700"} + {:path "/usr/local/bin/backup.sh" :mod "700"} + {:path "/usr/local/bin/restore.sh" :mod "700"}]}