dishplanner/Dockerfile.dev

148 lines
4.1 KiB
Text
Raw Permalink Normal View History

# Development Dockerfile with FrankenPHP
#
# Debian rather than Alpine so Playwright can run its own Chromium: it treats
# debian12 as an officially supported platform and has no musl build at all.
FROM dunglas/frankenphp:latest-php8.3-bookworm
# Install system dependencies + development tools. Node comes from NodeSource
# rather than apt: bookworm ships Node 18, below what Vite 6 targets.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gnupg \
git \
default-mysql-client \
vim \
nano \
bash \
unzip \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& rm -rf /var/lib/apt/lists/*
# Playwright's browser lives outside the bind-mounted /app so a host node_modules
# never shadows it; --with-deps pulls the shared libraries Chromium needs.
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
COPY package.json package-lock.json /tmp/pw/
RUN cd /tmp/pw \
&& npm ci --no-audit --no-fund \
&& ./node_modules/.bin/playwright install --with-deps chromium \
&& rm -rf /tmp/pw
# Install PHP extensions including xdebug for development
RUN install-php-extensions \
pdo_mysql \
sockets \
opcache \
zip \
gd \
intl \
bcmath \
xdebug
# Install Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /app
# Configure PHP for development
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
2025-12-27 17:30:07 +01:00
# Configure Xdebug (disabled by default to reduce noise)
RUN echo "xdebug.mode=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo ";xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo ";xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo ";xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
2025-12-27 17:30:07 +01:00
# Configure Caddy for development (simpler, no worker mode)
RUN cat > /etc/caddy/Caddyfile <<EOF
{
2025-12-27 17:30:07 +01:00
frankenphp
order php_server before file_server
}
:8000 {
root * /app/public
php_server {
index index.php
}
encode gzip
file_server
# Less strict headers for development
header {
X-Frame-Options "SAMEORIGIN"
}
}
EOF
# Install Node development dependencies globally
RUN npm install -g nodemon
2025-12-27 21:18:09 +01:00
# Create startup script for development (runs as host user)
RUN cat > /start.sh <<'EOF'
#!/bin/sh
set -e
2025-12-27 21:18:09 +01:00
# Create .env file if it doesn't exist
if [ ! -f ".env" ]; then
echo "Creating .env file from .env.example..."
cp .env.example .env
fi
# Install dependencies if volumes are empty
2025-12-27 17:30:07 +01:00
if [ ! -f "vendor/autoload.php" ]; then
echo "Installing composer dependencies..."
composer install
fi
2025-12-27 21:18:09 +01:00
# Handle node_modules with care - clean install if having issues
2025-12-27 17:30:07 +01:00
if [ ! -f "node_modules/.bin/vite" ]; then
echo "Installing npm dependencies..."
2025-12-27 21:18:09 +01:00
# Clean any remnants first
rm -rf node_modules/.* 2>/dev/null || true
rm -rf /app/.npm 2>/dev/null || true
# Fresh install with cache in tmp to avoid permission issues
npm install --cache /tmp/.npm
2025-12-27 17:30:07 +01:00
else
2025-12-27 21:18:09 +01:00
echo "Node modules already installed, skipping npm install"
fi
2025-12-27 21:18:09 +01:00
# Clear Laravel caches
php artisan config:clear || true
php artisan cache:clear || true
2025-12-27 21:18:09 +01:00
# Wait for database and run migrations
echo "Waiting for database..."
sleep 5
2025-12-27 21:18:09 +01:00
php artisan migrate --force || echo "Migration failed or not needed"
2025-12-27 17:30:07 +01:00
2025-12-29 17:30:17 +01:00
# Run development seeder (only in dev environment)
echo "Running development seeder..."
php artisan db:seed --class=DevelopmentSeeder --force || echo "Seeding skipped or already done"
2025-12-27 17:30:07 +01:00
# Generate app key if not set
if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "base64:YOUR_KEY_HERE" ]; then
echo "Generating application key..."
2025-12-27 21:18:09 +01:00
php artisan key:generate
2025-12-27 17:30:07 +01:00
fi
2025-12-27 21:18:09 +01:00
# Start Vite dev server in background
npm run dev &
2025-12-27 21:18:09 +01:00
# Start FrankenPHP
2025-12-27 17:30:07 +01:00
exec frankenphp run --config /etc/caddy/Caddyfile
EOF
RUN chmod +x /start.sh
# Expose ports
EXPOSE 8000 5173
# Use the startup script
CMD ["/start.sh"]