Skip to content

Commit 03df777

Browse files
committed
Implementing Pull Request #28 (BytemarkHosting/docker-webdav#28).
Signed-off-by: Jadin Heaston <jadin.heaston@como.gov>
1 parent 5685d96 commit 03df777

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

Dockerfile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ RUN set -ex; \
1313
chmod -R 777 "/var/www/html"; \
1414
# Create directories for Dav data and lock database.
1515
mkdir -p "/var/lib/dav/data"; \
16-
chown -R www-data:www-data "/var/lib/dav"; \
17-
chmod -R 777 "/var/lib/dav"; \
16+
touch "/var/lib/dav/DavLock"; \
1817
\
1918
# Enable DAV modules.
2019
for i in dav dav_fs; do \
@@ -31,11 +30,6 @@ RUN set -ex; \
3130
sed -i -e "/^#LoadModule ${i}_module.*/s/^#//" "conf/httpd.conf"; \
3231
done; \
3332
\
34-
# Run httpd as "www-data" (instead of "daemon").
35-
for i in User Group; do \
36-
sed -i -e "s|^$i .*|$i www-data|" "conf/httpd.conf"; \
37-
done; \
38-
\
3933
# Include enabled configs and sites.
4034
printf '%s\n' "Include conf/conf-enabled/*.conf" \
4135
>> "conf/httpd.conf"; \

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ All environment variables are optional. You probably want to at least specify `U
8888
* `PASSWORD`: Authenticate with this password (and the username above). This is ignored if you bind mount your own authentication file to `/user.passwd`.
8989
* `ANONYMOUS_METHODS`: Comma-separated list of HTTP request methods (eg, `GET,POST,OPTIONS,PROPFIND`). Clients can use any method you specify here without authentication. Set to `ALL` to disable authentication. The default is to disallow any anonymous access.
9090
* `SSL_CERT`: Set to `selfsigned` to generate a self-signed certificate and enable Apache's SSL module. If you specify `SERVER_NAMES`, the first domain is set as the Common Name.
91+
* **`PUID`**: file owner's UID of `/var/lib/dav`
92+
* **`PGID`**: file owner's GID of `/var/lib/dav`
93+
* **`PUMASK`**: umask of `/var/lib/dav/data`

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ services:
99
AUTH_TYPE: Digest
1010
USERNAME: Alice
1111
PASSWORD: Secret1234!
12+
PUID: 1000
13+
GUID: 1000
14+
PUMASK: 1000
1215
volumes:
1316
- webdav-data:/var/lib/dav

docker-entrypoint.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ set -e
1010
# PASSWORD
1111
# ANONYMOUS_METHODS
1212
# SSL_CERT
13+
# PUID
14+
# PGID
15+
# PUMASK
1316

1417
# Just in case this environment variable has gone missing.
1518
HTTPD_PREFIX="${HTTPD_PREFIX:-/usr/local/apache2}"
19+
PUID=${PUID:-1000}
20+
PGID=${PGID:-1000}
1621

1722
# Configure vhosts.
1823
if [ "x$SERVER_NAMES" != "x" ]; then
@@ -101,8 +106,20 @@ fi
101106
# Create directories for Dav data and lock database.
102107
[ ! -d "/var/lib/dav/data" ] && mkdir -p "/var/lib/dav/data"
103108
[ ! -e "/var/lib/dav/DavLock" ] && touch "/var/lib/dav/DavLock"
104-
chown -R www-data:www-data "/var/lib/dav"
105-
chmod -R 777 "/var/lib/dav"
106-
chmod -R 777 "/var/www/html"
109+
110+
# add PUID:PGID, ignore error
111+
addgroup -g $PGID -S user-group 1>/dev/null || true
112+
adduser -u $PUID -S user 1>/dev/null || true
113+
114+
# Run httpd as PUID:PGID
115+
sed -i -e "s|^User .*|User #$PUID|" "$HTTPD_PREFIX/conf/httpd.conf";
116+
sed -i -e "s|^Group .*|Group #$PGID|" "$HTTPD_PREFIX/conf/httpd.conf";
117+
118+
chown $PUID:$PGID "/var/lib/dav/DavLock"
119+
120+
# Set umask
121+
if [ "x$PUMASK" != "x" ]; then
122+
umask $PUMASK
123+
fi
107124

108125
exec "$@"

0 commit comments

Comments
 (0)