app/Dockerfile.dev

135 lines
No EOL
3.5 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 (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
# Configure Caddy for development (simpler, no worker mode)
RUN cat > /etc/caddy/Caddyfile <<EOF
{
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
# Create startup script
RUN cat > /start.sh <<'EOF'
#!/bin/sh
set -e
# Ensure all required Laravel directories exist
mkdir -p /app/bootstrap/cache
mkdir -p /app/storage/app/public
mkdir -p /app/storage/framework/cache/data
mkdir -p /app/storage/framework/sessions
mkdir -p /app/storage/framework/testing
mkdir -p /app/storage/framework/views
mkdir -p /app/storage/logs
# Set permissions - use www-data user
chown -R www-data:www-data /app/storage /app/bootstrap/cache
chmod -R 775 /app/storage /app/bootstrap/cache
# Create cache directories with proper permissions
mkdir -p /app/storage/framework/cache/data
chown -R www-data:www-data /app/storage/framework/cache
chmod -R 775 /app/storage/framework/cache
# Check if vendor exists in the volume
if [ ! -f "vendor/autoload.php" ]; then
echo "Installing composer dependencies..."
composer install
else
echo "Composer dependencies found, skipping install..."
fi
# Check if node_modules exists in the volume
if [ ! -f "node_modules/.bin/vite" ]; then
echo "Installing npm dependencies..."
npm install
else
echo "Node modules found, skipping npm install..."
fi
# Run Laravel commands as www-data to avoid permission issues
su -s /bin/sh www-data -c "php artisan config:clear" || true
su -s /bin/sh www-data -c "php artisan cache:clear" || true
su -s /bin/sh www-data -c "php artisan route:clear" || true
su -s /bin/sh www-data -c "php artisan view:clear" || true
# Run migrations if database is ready
echo "Waiting for database..."
sleep 5
su -s /bin/sh www-data -c "php artisan migrate --force" || echo "Migration failed or not needed"
# Generate app key if not set
if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "base64:YOUR_KEY_HERE" ]; then
echo "Generating application key..."
su -s /bin/sh www-data -c "php artisan key:generate"
fi
# Start Vite dev server in background for hot reload
npm run dev &
# Start FrankenPHP (runs as root in dev for simplicity)
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"]