2025-12-27 17:00:16 +01:00
|
|
|
# Production Dockerfile with FrankenPHP
|
|
|
|
|
FROM dunglas/frankenphp:latest-php8.3-alpine
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 17:00:16 +01:00
|
|
|
# Install system dependencies
|
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
|
nodejs \
|
|
|
|
|
npm \
|
|
|
|
|
git \
|
|
|
|
|
mysql-client
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 17:00:16 +01:00
|
|
|
# Install PHP extensions
|
|
|
|
|
RUN install-php-extensions \
|
|
|
|
|
pdo_mysql \
|
|
|
|
|
opcache \
|
|
|
|
|
zip \
|
|
|
|
|
gd \
|
|
|
|
|
intl
|
|
|
|
|
|
|
|
|
|
# Install Composer
|
2025-10-13 14:57:11 +02:00
|
|
|
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
|
|
|
|
|
2025-12-27 17:00:16 +01:00
|
|
|
# Set working directory
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Set fixed production environment variables
|
|
|
|
|
ENV APP_ENV=production \
|
|
|
|
|
APP_DEBUG=false \
|
|
|
|
|
DB_CONNECTION=mysql \
|
|
|
|
|
DB_HOST=db \
|
|
|
|
|
DB_PORT=3306 \
|
|
|
|
|
SESSION_DRIVER=database \
|
|
|
|
|
CACHE_DRIVER=file \
|
|
|
|
|
QUEUE_CONNECTION=database \
|
|
|
|
|
LOG_CHANNEL=stack \
|
|
|
|
|
LOG_LEVEL=error \
|
|
|
|
|
MAIL_MAILER=smtp \
|
|
|
|
|
MAIL_ENCRYPTION=tls
|
|
|
|
|
|
2025-12-27 20:55:04 +01:00
|
|
|
# Copy application code first
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
# Install PHP dependencies (production only)
|
2025-12-27 17:00:16 +01:00
|
|
|
RUN composer install --no-dev --no-interaction --optimize-autoloader
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 20:55:04 +01:00
|
|
|
# Install ALL Node dependencies (including dev for building)
|
|
|
|
|
RUN npm ci
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 17:00:16 +01:00
|
|
|
# Build frontend assets
|
|
|
|
|
RUN npm run build
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 20:55:04 +01:00
|
|
|
# Remove node_modules after build to save space
|
|
|
|
|
RUN rm -rf node_modules
|
|
|
|
|
|
2025-10-13 14:57:11 +02:00
|
|
|
# Laravel optimizations
|
|
|
|
|
RUN php artisan config:cache \
|
|
|
|
|
&& php artisan route:cache \
|
2025-12-27 17:00:16 +01:00
|
|
|
&& composer dump-autoload --optimize
|
|
|
|
|
|
|
|
|
|
# Set permissions
|
|
|
|
|
RUN chown -R www-data:www-data /app/storage /app/bootstrap/cache
|
|
|
|
|
|
|
|
|
|
# Configure Caddy
|
|
|
|
|
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
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 17:00:16 +01:00
|
|
|
header {
|
|
|
|
|
X-Frame-Options "SAMEORIGIN"
|
|
|
|
|
X-Content-Type-Options "nosniff"
|
|
|
|
|
X-XSS-Protection "1; mode=block"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EOF
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 17:00:16 +01:00
|
|
|
# Expose port
|
|
|
|
|
EXPOSE 8000
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 17:00:16 +01:00
|
|
|
# Health check
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
|
|
|
CMD curl -f http://localhost:8000/up || exit 1
|
2025-10-13 14:57:11 +02:00
|
|
|
|
2025-12-27 20:55:04 +01:00
|
|
|
# Create startup script for production
|
|
|
|
|
RUN cat > /start-prod.sh <<'EOF'
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
# Wait for database to be ready
|
|
|
|
|
echo "Waiting for database..."
|
|
|
|
|
for i in $(seq 1 30); do
|
2026-01-04 03:21:19 +01:00
|
|
|
if mysqladmin ping -h "$DB_HOST" -u "$DB_USERNAME" -p"$DB_PASSWORD" --silent 2>/dev/null; then
|
2025-12-27 20:55:04 +01:00
|
|
|
echo "Database is ready!"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
echo "Waiting for database... ($i/30)"
|
|
|
|
|
sleep 2
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Run migrations
|
|
|
|
|
echo "Running migrations..."
|
|
|
|
|
php artisan migrate --force || echo "Migrations failed or already up-to-date"
|
|
|
|
|
|
2025-12-27 17:00:16 +01:00
|
|
|
# Start FrankenPHP
|
2025-12-27 20:55:04 +01:00
|
|
|
exec frankenphp run --config /etc/caddy/Caddyfile
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
RUN chmod +x /start-prod.sh
|
|
|
|
|
|
|
|
|
|
# Start with our script
|
|
|
|
|
CMD ["/start-prod.sh"]
|