From 6f28029fb8b1dc0ef658ed4005cb85504a751658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 4 Feb 2023 22:44:33 +0100 Subject: [PATCH] Added a custom docker entrypoint which chowns used volumes This fixes issue #206. --- .docker/partdb-entrypoint.sh | 43 ++++++++++++++++++++++++++++++++++++ Dockerfile | 9 ++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 .docker/partdb-entrypoint.sh diff --git a/.docker/partdb-entrypoint.sh b/.docker/partdb-entrypoint.sh new file mode 100644 index 00000000..69fc3a4e --- /dev/null +++ b/.docker/partdb-entrypoint.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# +# This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). +# +# Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +set -e + +# recursive chowns can take a while, so we'll just do it if the owner is wrong + +# Chown uploads/ folder if it does not belong to www-data +if [ "$(stat -c '%u' /var/www/html/uploads)" != "$(id -u www-data)" ]; then + chown -R www-data:www-data /var/www/html/uploads +fi + +# Do the same for the public/media folder +if [ "$(stat -c '%u' /var/www/html/public/media)" != "$(id -u www-data)" ]; then + chown -R www-data:www-data /var/www/html/public/media +fi + +# If var/db/ folder exists, do the same for it +if [ -d /var/www/html/var/db ]; then + if [ "$(stat -c '%u' /var/www/html/var/db)" != "$(id -u www-data)" ]; then + chown -R www-data:www-data /var/www/html/var/db + fi +fi + +# Pass to the original entrypoint +exec "$@" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4c2ea511..e2abb800 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,5 +55,10 @@ ENV DATABASE_URL="sqlite:///%kernel.project_dir%/uploads/app.db" USER root -VOLUME ["/var/www/html/uploads", "/var/www/html/public/media"] -EXPOSE 80 \ No newline at end of file +# Copy entrypoint to /usr/local/bin and make it executable +RUN cp ./.docker/partdb-entrypoint.sh /usr/local/bin/partdb-entrypoint.sh && chmod +x /usr/local/bin/partdb-entrypoint.sh +ENTRYPOINT ["partdb-entrypoint.sh", "docker-php-entrypoint"] +CMD ["apache2-foreground"] + +EXPOSE 80 +VOLUME ["/var/www/html/uploads", "/var/www/html/public/media"] \ No newline at end of file