diff --git a/Dockerfile b/Dockerfile index c6655a8..f2cceed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,17 @@ FROM alpine:3 ARG TARGETPLATFORM +VOLUME /backups + RUN apk add --no-cache libc6-compat ADD ${TARGETPLATFORM}/git-backup / RUN chmod +x /git-backup -VOLUME /backups +## Add the user for command execution +RUN apk add --no-cache shadow + +ADD ./docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh -ENTRYPOINT ["/git-backup", "-backup.path", "/backups", "-config.file", "/backups/git-backup.yml"] +ENTRYPOINT ["/docker-entrypoint.sh", "-backup.path", "/backups", "-config.file", "/backups/git-backup.yml"] diff --git a/README.md b/README.md index ce4eab7..cc650c3 100644 --- a/README.md +++ b/README.md @@ -91,5 +91,16 @@ First, create your [git-backup.yml file](#configuration-file) at `/path/to/your/ Then update your backups using the mounted volume. ```bash -docker run --volume /path/to/backups:/backups ghcr.io/chappio/git-backup:latest +docker run -v /path/to/backups:/backups ghcr.io/chappio/git-backup:1 ``` + +### Parameters + +You can specify several parameters when starting this container. + +| **Parameter** | **Description** | +|--------------------------------|----------------------------------------------------------------------------------------| +| `-v /path/to/backups:/backups` | Mount the folder where you want to store your backups and read you configuration file. | +| `-e TZ=Europe/Amsterdam` | Set the timezone used for logging. | +| `-e PUID=0` | Set the user id of the unix user who will own the backup files in /backup. | +| `-e PGID=0` | Set the group id of the unix user's group who will own the backup files. | diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..e71a65f --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/sh +set -eu +if [[ -z "${PUID-}" && -z "${PGID-}" ]] +then + # We are running through normal docker user changes, so nothing special to do + /git-backup "$@" +else + # We are running with an environment variable user change + PUID=${PUID:-$(id -u)} + PGID=${PGID:-$(id -g)} + + # Make sure the user exists + useradd -o -u "$PUID" -U -d /backups -s /bin/false git-backup + groupmod -o -g "$PGID" git-backup + + # Own the backups folder + chown git-backup:git-backup /backups + + # Let's go! + echo /git-backup "$@" | su -s /bin/sh git-backup +fi +