Added a custom docker entrypoint which chowns used volumes

This fixes issue #206.
This commit is contained in:
Jan Böhmer 2023-02-04 22:44:33 +01:00
parent f0947fd948
commit 6f28029fb8
2 changed files with 50 additions and 2 deletions

View file

@ -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 <https://www.gnu.org/licenses/>.
#
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 "$@"

View file

@ -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
# 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"]