Files
nhgooi.nl/docker-entrypoint.sh
T
eric.busandClaude Opus 5.5 da971e1646
Build and Deploy (dev) / build (push) Successful in 4m23s
docker: support running the container as www-data (uid 33)
- Set ownership of storage, bootstrap/cache and public/assets/vendor at
  build time
- Entrypoint only creates/chowns directories when running as root

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 14:17:42 +01:00

51 lines
1.6 KiB
Bash

#!/bin/bash
set -e
cd /var/www/app
# Set HOME for npm cache (www-data user needs writable cache directory)
export HOME=/tmp
WRITABLE_DIRS="storage/framework storage/logs bootstrap/cache public/assets/vendor"
# Ownership is already set in the image. Only fix it when running as root,
# e.g. when a root-owned volume is mounted over one of these directories.
# When running as www-data (uid 33) we can't (and don't need to) chown.
fix_permissions() {
if [ "$(id -u)" = "0" ]; then
mkdir -p $WRITABLE_DIRS
chown -R www-data:www-data $WRITABLE_DIRS
chmod -R ug+rwX $WRITABLE_DIRS
fi
}
fix_permissions
# PHP dependencies are installed in the image. Only install them here as a
# fallback, e.g. when the app directory is mounted as a volume without vendor/.
if [ ! -f vendor/autoload.php ]; then
echo "vendor/ missing, installing PHP packages..."
composer install \
--no-dev \
--prefer-dist \
--no-interaction \
--optimize-autoloader
fi
# npm packages and public/assets/vendor are also built into the image. Only
# (re)create them here as a fallback, e.g. when they are hidden by a volume.
if [ ! -d node_modules ]; then
echo "node_modules/ missing, installing npm packages..."
npm ci --omit=dev --ignore-scripts
node scripts/setup-vendor.js
elif [ -z "$(ls -A public/assets/vendor 2>/dev/null)" ]; then
echo "public/assets/vendor is empty, copying npm packages..."
node scripts/setup-vendor.js
fi
# Files created by the fallbacks above may be owned by root
fix_permissions
echo "Starting Apache..."
exec apache2-foreground