app/Dockerfile.dev

127 lines
3.1 KiB
Text
Raw Normal View History

# 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"
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"]