Skip to content

Commit 375386a

Browse files
authored
Support PUID and PGID vars to set runtime user and group ids (#12)
1 parent 4f10693 commit 375386a

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ FROM alpine:3
22

33
ARG TARGETPLATFORM
44

5+
VOLUME /backups
6+
57
RUN apk add --no-cache libc6-compat
68

79
ADD ${TARGETPLATFORM}/git-backup /
810
RUN chmod +x /git-backup
911

10-
VOLUME /backups
12+
## Add the user for command execution
13+
RUN apk add --no-cache shadow
14+
15+
ADD ./docker-entrypoint.sh /docker-entrypoint.sh
16+
RUN chmod +x /docker-entrypoint.sh
1117

12-
ENTRYPOINT ["/git-backup", "-backup.path", "/backups", "-config.file", "/backups/git-backup.yml"]
18+
ENTRYPOINT ["/docker-entrypoint.sh", "-backup.path", "/backups", "-config.file", "/backups/git-backup.yml"]

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,16 @@ First, create your [git-backup.yml file](#configuration-file) at `/path/to/your/
9191
Then update your backups using the mounted volume.
9292

9393
```bash
94-
docker run --volume /path/to/backups:/backups ghcr.io/chappio/git-backup:latest
94+
docker run -v /path/to/backups:/backups ghcr.io/chappio/git-backup:1
9595
```
96+
97+
### Parameters
98+
99+
You can specify several parameters when starting this container.
100+
101+
| **Parameter** | **Description** |
102+
|--------------------------------|----------------------------------------------------------------------------------------|
103+
| `-v /path/to/backups:/backups` | Mount the folder where you want to store your backups and read you configuration file. |
104+
| `-e TZ=Europe/Amsterdam` | Set the timezone used for logging. |
105+
| `-e PUID=0` | Set the user id of the unix user who will own the backup files in /backup. |
106+
| `-e PGID=0` | Set the group id of the unix user's group who will own the backup files. |

docker-entrypoint.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
set -eu
3+
if [[ -z "${PUID-}" && -z "${PGID-}" ]]
4+
then
5+
# We are running through normal docker user changes, so nothing special to do
6+
/git-backup "$@"
7+
else
8+
# We are running with an environment variable user change
9+
PUID=${PUID:-$(id -u)}
10+
PGID=${PGID:-$(id -g)}
11+
12+
# Make sure the user exists
13+
useradd -o -u "$PUID" -U -d /backups -s /bin/false git-backup
14+
groupmod -o -g "$PGID" git-backup
15+
16+
# Own the backups folder
17+
chown git-backup:git-backup /backups
18+
19+
# Let's go!
20+
echo /git-backup "$@" | su -s /bin/sh git-backup
21+
fi
22+

0 commit comments

Comments
 (0)