summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthias Lucas Jaros <jarlucmat@mailbox.org>2026-07-11 11:29:08 +0200
committerGravatar Matthias Lucas Jaros <jarlucmat@mailbox.org>2026-07-11 11:29:08 +0200
commit0701e4d908f407c8893d8c3fcd5e1ea4dec0e937 (patch)
treef06b8439562f252ff93fe9496d8f823ff3073a33
parentc6aad223a77c376fee134ca875f8a02a383d4441 (diff)
Added entrypoint file to adjust uid and gid on the fly using docker-compose
-rw-r--r--Dockerfile14
-rw-r--r--docker-compose.yml8
-rw-r--r--entrypoint.sh20
3 files changed, 35 insertions, 7 deletions
diff --git a/Dockerfile b/Dockerfile
index 67f15b6..1dfb37b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -28,11 +28,8 @@ FROM httpd:${APACHE_VERSION}
RUN apk add --no-cache luajit
-RUN addgroup -g 1000 cgit \
- && adduser -D -H -u 1000 -G cgit cgit
-
-RUN sed -i 's/^User www-data/User cgit/' /usr/local/apache2/conf/httpd.conf
-RUN sed -i 's/^Group www-data/Group cgit/' /usr/local/apache2/conf/httpd.conf
+RUN sed -i 's/^\(User\) www-data/\1 cgit/' /usr/local/apache2/conf/httpd.conf
+RUN sed -i 's/^\(Group\) www-data/\1 cgit/' /usr/local/apache2/conf/httpd.conf
RUN sed -i 's/#\(LoadModule cgi_module\)/\1/' /usr/local/apache2/conf/httpd.conf
RUN sed -i 's/#\(LoadModule cgid_module\)/\1/' /usr/local/apache2/conf/httpd.conf
RUN echo -e "\n#cgit configuration\nInclude conf/extra/cgit.conf" >> /usr/local/apache2/conf/httpd.conf
@@ -41,7 +38,12 @@ ENV CGIT_APP_USER=cgit
COPY ./rootfs/ /
COPY --from=build /opt/cgit /opt/cgit
-RUN chown cgit:cgit -R /opt/cgit
+RUN chmod 755 -R /opt/cgit
+
+COPY entrypoint.sh /usr/local/bin/entrypoint.sh
+RUN chmod +x /usr/local/bin/entrypoint.sh
VOLUME ["/opt/git"]
+ENTRYPOINT ["entrypoint.sh"]
+CMD ["httpd-foreground"]
EXPOSE 80
diff --git a/docker-compose.yml b/docker-compose.yml
index e97a947..fc68ebe 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -5,10 +5,16 @@ services:
build: .
ports:
- "8086:80"
+ environment:
+ PUID: "1000"
+ PGID: "1000"
volumes:
- /srv/shares/git:/srv/git/:ro
- - /srv/shares/cgit/cache:/opt/cgit/cache:rw
+ - cgit-cache:/opt/cgit/cache:rw
- ./cgit.css:/opt/cgit/app/cgit.css:ro
- ./cgit.png:/opt/cgit/app/cgit.png:ro
- ./favicon.ico:/opt/cgit/app/favicon.ico:ro
- ./cgitrc:/opt/cgit/cgitrc:ro
+
+volumes:
+ cgit-cache:
diff --git a/entrypoint.sh b/entrypoint.sh
new file mode 100644
index 0000000..f6b0b54
--- /dev/null
+++ b/entrypoint.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+set -eu
+
+: "${PUID:=1000}"
+: "${PGID:=1000}"
+
+# Create group at container start
+if ! grep -q '^cgit:' /etc/group; then
+ addgroup -g "$PGID" cgit
+fi
+
+# Create user at container start
+if ! grep -q '^cgit:' /etc/passwd; then
+ adduser -D -H -u "$PUID" -G cgit cgit
+fi
+
+# Make cache writable for Apache/cgit
+chown -R "$PUID:$PGID" /opt/cgit/cache
+
+exec "$@"