diff --git a/docker/production/entrypoint.d/00-setup.sh b/docker/production/entrypoint.d/00-setup.sh index 88dcdca8..66021ab9 100644 --- a/docker/production/entrypoint.d/00-setup.sh +++ b/docker/production/entrypoint.d/00-setup.sh @@ -12,6 +12,32 @@ InvoiceShelf Version: $version cd /var/www/html +# These carry no tracked content — only .gitignore stubs — so a mount over +# storage/ can arrive without them, and Laravel then dies at boot with "Please +# provide a valid cache path" (config/view.php resolves its compiled path with +# realpath(), which returns false for a missing directory). Recreate them before +# anything writes there, including the sqlite database placed in storage/app +# below. See InvoiceShelf/docker#75, #69 and #77. +echo "**** Ensuring storage directories exist ****" +if ! mkdir -p \ + storage/app/public \ + storage/framework/cache/data \ + storage/framework/sessions \ + storage/framework/views \ + storage/logs \ + bootstrap/cache 2>/dev/null; then + echo "!!!! Cannot write to /var/www/html/storage." + echo "!!!! This container runs as uid $(id -u) (www-data), but the mounted" + echo "!!!! directory belongs to someone else — usually a bind mount pointing" + echo "!!!! at a host directory owned by your own user." + echo "!!!! Give that directory to uid 82 on the host and start again:" + echo "!!!!" + echo "!!!! sudo chown -R 82:82 /path/to/your/storage" + echo "!!!!" + echo "!!!! See https://github.com/InvoiceShelf/docker/issues/77" + exit 1 +fi + if [ ! -e /var/www/html/.env ]; then cp .env.example .env echo "**** Setup initial .env values ****" && \ @@ -33,9 +59,17 @@ if [ "$DB_CONNECTION" = "sqlite" ] || [ -z "$DB_CONNECTION" ]; then chown www-data:www-data "$DB_DATABASE" fi -echo "**** Setting up artisan permissions ****" +echo "**** Setting up folder permissions ****" chmod +x artisan +# Only root may change ownership. The image normally runs as www-data, where +# this is both impossible and unnecessary — the files it created are already +# owned correctly — so it is skipped rather than failing the boot on a chown we +# are not permitted to make. It still helps anyone running the image as root. +if [ "$(id -u)" = "0" ]; then + chown -R www-data:www-data storage bootstrap/cache +fi + if ! grep -q "APP_KEY" /var/www/html/.env then echo "**** Creating empty APP_KEY variable ****"