app/Dockerfile.dev

124 lines
No EOL
2.6 KiB
Text

# Development Dockerfile with FrankenPHP
FROM dunglas/frankenphp:latest-php8.3-alpine
# Install system dependencies + development tools
RUN apk add --no-cache \
nodejs \
npm \
git \
mysql-client \
vim \
bash \
nano
# Install PHP extensions including xdebug for development
RUN install-php-extensions \
pdo_mysql \
opcache \
zip \
gd \
intl \
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"
# Configure Xdebug
RUN 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
# Configure Caddy for development with file watching
RUN cat > /etc/caddy/Caddyfile <<EOF
{
frankenphp {
worker {
file /app/public/index.php
num 1
watch
}
}
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"
}
# Show PHP errors in development
@phpFiles {
path *.php
}
header @phpFiles {
X-Debug-Mode "development"
}
}
EOF
# Install Node development dependencies globally
RUN npm install -g nodemon
# Create startup script
RUN cat > /start.sh <<'EOF'
#!/bin/sh
set -e
# Install/update composer dependencies if needed
if [ ! -d "vendor" ]; then
echo "Installing composer dependencies..."
composer install
fi
# Install/update npm dependencies if needed
if [ ! -d "node_modules" ]; then
echo "Installing npm dependencies..."
npm install
fi
# Clear Laravel caches for development
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
# Ensure storage permissions
chown -R www-data:www-data /app/storage /app/bootstrap/cache
chmod -R 777 /app/storage /app/bootstrap/cache
# Run migrations if database is ready
echo "Waiting for database..."
sleep 5
php artisan migrate --force || echo "Migration failed or not needed"
# Start Vite dev server in background for hot reload
npm run dev &
# Start FrankenPHP
exec frankenphp run --config /etc/caddy/Caddyfile --watch
EOF
RUN chmod +x /start.sh
# Expose ports
EXPOSE 8000 5173
# Use the startup script
CMD ["/start.sh"]