cleanup image & bring test to work

This commit is contained in:
jem 2020-12-04 18:10:24 +01:00
parent 2233676fdd
commit 7d759e4d68
9 changed files with 39 additions and 33 deletions

View file

@ -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

4
infrastrucure/docker/image/resources/backup.sh Normal file → Executable file
View file

@ -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

View file

@ -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

4
infrastrucure/docker/image/resources/entrypoint.sh Normal file → Executable file
View file

@ -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

View file

@ -0,0 +1,3 @@
#!/bin/bash
restic -r $RESTIC_REPOSITORY --verbose init

View file

@ -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/

3
infrastrucure/docker/image/resources/restore.sh Normal file → Executable file
View file

@ -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 /

View file

@ -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

View file

@ -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"}]}