fix production
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m9s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 15s
Build, Push and Deploy / deploy-staging (push) Successful in 38s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s

This commit is contained in:
eko
2026-04-04 23:34:45 +07:00
parent 481b8fba7e
commit 4398aee449
2 changed files with 43 additions and 20 deletions

View File

@@ -215,7 +215,7 @@ jobs:
-e MODE=production \
-e APP_ENV=production \
-e APP_DEBUG=false \
-e APP_URL=https://prod-test.kulakpos.id \
-e AUTO_MIGRATE=false \
kode.sadateknologi.site/${{ gitea.repository_owner }}/kulakpos_web:$IMAGE_TAG
# Wait for container to be ready
@@ -261,6 +261,7 @@ jobs:
-e MODE=production \
-e APP_ENV=production \
-e APP_DEBUG=false \
-e AUTO_MIGRATE=false \
$PREVIOUS_IMAGE
echo "Rollback completed"
fi

View File

@@ -9,9 +9,14 @@ echo "========================================"
echo "Current user: $(whoami)"
echo "Current directory: $(pwd)"
# Force debug mode for troubleshooting
# Set debug based on environment
if [ "$APP_ENV" = "production" ]; then
export APP_DEBUG=false
export LOG_LEVEL=error
else
export APP_DEBUG=true
export LOG_LEVEL=debug
fi
# Create ALL required Laravel directories
echo "Creating storage directories..."
@@ -62,7 +67,6 @@ fi
echo "Checking .env for APP_KEY..."
if ! grep -E "APP_KEY=.{10,}" .env; then
echo "APP_KEY is empty or missing. Generating..."
echo "Generating application key..."
# If the file doesn't have APP_KEY= at all, add it so artisan can replace it
if ! grep -q "APP_KEY=" .env; then
echo "Appending APP_KEY= placeholder..."
@@ -80,7 +84,7 @@ echo "Verifying and synchronizing Composer dependencies..."
# Run composer install to physically ensure all files (like laravel/prompts) are present in the volume
composer install --no-interaction --optimize-autoloader
# FIX: Ensure all generated/downloaded files are fully readable and executable by PHP-FPM
# FIX: Ensure all generated/downloaded files are fully readable and executable
echo "Setting correct ownership for web server..."
chown -R www-data:www-data vendor
chmod -R 755 vendor
@@ -91,13 +95,22 @@ ls -la /var/www/html/vendor/laravel/prompts/src/helpers.php
php -r 'if (file_exists("/var/www/html/vendor/laravel/prompts/src/helpers.php")) { echo "✅ file_exists true\n"; }'
php -r 'require "/var/www/html/vendor/laravel/prompts/src/helpers.php"; echo "✅ PHP successfully REQUIRED helpers.php\n";'
# Clear all caches to ensure fresh state
# Run production optimizations for production environment
if [ "$APP_ENV" = "production" ] || [ "$MODE" = "production" ]; then
echo "Running production optimizations..."
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
else
# Clear all caches to ensure fresh state for non-production
echo "Clearing caches..."
php artisan config:clear || true
php artisan view:clear || true
php artisan route:clear || true
php artisan cache:clear || true
php artisan optimize:clear || true
fi
# Verify Vite manifest exists
if [ -f public/build/manifest.json ]; then
@@ -108,20 +121,29 @@ else
ls -la public/build/ 2>/dev/null || echo "public/build directory does not exist"
fi
# Optional: Run migrations if needed
# php artisan migrate --force
# Optional: Run migrations if needed (with safety for production)
if [ "$AUTO_MIGRATE" = "true" ] || [ "$APP_ENV" != "production" ]; then
echo "Running migrations..."
php artisan migrate --force
fi
echo "========================================"
echo "Setup complete. Starting application..."
echo "========================================"
# Start the application with proper error handling
if [ "$MODE" = "staging" ]; then
echo "Starting DIRECT PHP server on port 8000 (Bypassing artisan serve)..."
# Start the application based on environment
if [ "$APP_ENV" = "production" ] || [ "$MODE" = "production" ]; then
echo "Starting PHP built-in server on port 8000 (Production mode)..."
echo "Document root: /var/www/html/public"
echo "Workers: Single-threaded PHP server (use Nginx for production scaling)"
# Use direct php -S for production (optimized)
exec php -d opcache.enable=1 -d opcache.memory_consumption=128 -d opcache.max_accelerated_files=10000 -S 0.0.0.0:8000 -t public
elif [ "$MODE" = "staging" ]; then
echo "Starting PHP built-in server on port 8000 (Staging mode)..."
# Use direct php -S to eliminate any artisan wrapper issues
exec php -d opcache.enable=0 -S 0.0.0.0:8000 -t public server.php 2>&1 | tee -a /var/log/php-server.log
exec php -d opcache.enable=0 -S 0.0.0.0:8000 -t public
else
echo "Starting PHP-FPM on port 9000..."
echo "Starting PHP-FPM on port 9000 (Development mode)..."
# Ensure PHP-FPM is properly configured
exec php-fpm -F
fi