migrate
All checks were successful
All checks were successful
This commit is contained in:
@@ -84,7 +84,7 @@ jobs:
|
|||||||
echo "Starting new container..."
|
echo "Starting new container..."
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
--health-cmd="curl -f http://localhost:8000 || exit 1" \
|
--health-cmd="curl -f http://127.0.0.1:8000 || exit 1" \
|
||||||
--health-interval=30s \
|
--health-interval=30s \
|
||||||
--health-timeout=10s \
|
--health-timeout=10s \
|
||||||
--health-retries=3 \
|
--health-retries=3 \
|
||||||
@@ -98,7 +98,7 @@ jobs:
|
|||||||
|
|
||||||
# Check if container is running
|
# Check if container is running
|
||||||
sleep 5
|
sleep 5
|
||||||
if docker ps | grep -q kulakpos_web_staging; then
|
if docker ps | grep kulakpos_web_staging; then
|
||||||
echo "✅ Staging deployment successful!"
|
echo "✅ Staging deployment successful!"
|
||||||
docker logs --tail 20 kulakpos_web_staging
|
docker logs --tail 20 kulakpos_web_staging
|
||||||
else
|
else
|
||||||
@@ -183,7 +183,13 @@ jobs:
|
|||||||
docker ps --filter name=kulakpos_web_prod
|
docker ps --filter name=kulakpos_web_prod
|
||||||
|
|
||||||
# Create backup of current deployment info
|
# Create backup of current deployment info
|
||||||
docker inspect kulakpos_web_prod > /tmp/kulakpos_backup_$(date +%Y%m%d_%H%M%S).json || true
|
mkdir -p /opt/kulakpos/backups
|
||||||
|
docker inspect kulakpos_web_prod > /opt/kulakpos/backups/kulakpos_backup_$(date +%Y%m%d_%H%M%S).json || true
|
||||||
|
|
||||||
|
# Backup .env file
|
||||||
|
if [ -f "/opt/kulakpos/.env" ]; then
|
||||||
|
cp /opt/kulakpos/.env /opt/kulakpos/backups/.env_backup_$(date +%Y%m%d_%H%M%S)
|
||||||
|
fi
|
||||||
|
|
||||||
# Pull the specified image
|
# Pull the specified image
|
||||||
echo "Pulling image: kode.sadateknologi.site/${{ gitea.repository_owner }}/kulakpos_web:$IMAGE_TAG"
|
echo "Pulling image: kode.sadateknologi.site/${{ gitea.repository_owner }}/kulakpos_web:$IMAGE_TAG"
|
||||||
@@ -194,11 +200,11 @@ jobs:
|
|||||||
docker stop kulakpos_web_prod || true
|
docker stop kulakpos_web_prod || true
|
||||||
docker rm kulakpos_web_prod || true
|
docker rm kulakpos_web_prod || true
|
||||||
|
|
||||||
# Run new container
|
# Run new container (using PHP's built-in server on port 8000 like staging)
|
||||||
echo "Starting new container..."
|
echo "Starting new production container on port 8000..."
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
--health-cmd="pgrep php-fpm" \
|
--health-cmd="curl -f http://127.0.0.1:8000 || exit 1" \
|
||||||
--health-interval=30s \
|
--health-interval=30s \
|
||||||
--health-timeout=10s \
|
--health-timeout=10s \
|
||||||
--health-start-period=40s \
|
--health-start-period=40s \
|
||||||
@@ -206,15 +212,23 @@ jobs:
|
|||||||
--name kulakpos_web_prod \
|
--name kulakpos_web_prod \
|
||||||
--network="host" \
|
--network="host" \
|
||||||
-v /opt/kulakpos/.env:/var/www/html/.env \
|
-v /opt/kulakpos/.env:/var/www/html/.env \
|
||||||
-p 9000:9000 \
|
-e MODE=production \
|
||||||
-e MODE=prod \
|
|
||||||
-e APP_ENV=production \
|
-e APP_ENV=production \
|
||||||
|
-e APP_DEBUG=false \
|
||||||
|
-e AUTO_MIGRATE=false \
|
||||||
kode.sadateknologi.site/${{ gitea.repository_owner }}/kulakpos_web:$IMAGE_TAG
|
kode.sadateknologi.site/${{ gitea.repository_owner }}/kulakpos_web:$IMAGE_TAG
|
||||||
|
|
||||||
# Check if container is running
|
# Wait for container to be ready
|
||||||
|
echo "Waiting for container to be ready..."
|
||||||
sleep 10
|
sleep 10
|
||||||
if docker ps | grep -q kulakpos_web_prod; then
|
|
||||||
|
# Check if container is running
|
||||||
|
if docker ps | grep kulakpos_web_prod; then
|
||||||
echo "✅ Production deployment successful!"
|
echo "✅ Production deployment successful!"
|
||||||
|
echo ""
|
||||||
|
echo "Container status:"
|
||||||
|
docker ps --filter name=kulakpos_web_prod --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
echo ""
|
||||||
echo "Container logs (last 20 lines):"
|
echo "Container logs (last 20 lines):"
|
||||||
docker logs --tail 20 kulakpos_web_prod
|
docker logs --tail 20 kulakpos_web_prod
|
||||||
else
|
else
|
||||||
@@ -222,50 +236,31 @@ jobs:
|
|||||||
docker logs kulakpos_web_prod || echo "No logs available"
|
docker logs kulakpos_web_prod || echo "No logs available"
|
||||||
|
|
||||||
# Attempt rollback to previous version if available
|
# Attempt rollback to previous version if available
|
||||||
|
echo ""
|
||||||
echo "Attempting rollback to previous version..."
|
echo "Attempting rollback to previous version..."
|
||||||
PREVIOUS_IMAGE=$(docker inspect kulakpos_web_prod --format='{{.Config.Image}}' 2>/dev/null || echo "")
|
PREVIOUS_BACKUP=$(ls -t /opt/kulakpos/backups/kulakpos_backup_*.json 2>/dev/null | head -1)
|
||||||
|
if [ -f "$PREVIOUS_BACKUP" ]; then
|
||||||
|
PREVIOUS_IMAGE=$(jq -r '.[0].Config.Image' $PREVIOUS_BACKUP 2>/dev/null || echo "")
|
||||||
if [ -n "$PREVIOUS_IMAGE" ] && [ "$PREVIOUS_IMAGE" != "kode.sadateknologi.site/${{ gitea.repository_owner }}/kulakpos_web:$IMAGE_TAG" ]; then
|
if [ -n "$PREVIOUS_IMAGE" ] && [ "$PREVIOUS_IMAGE" != "kode.sadateknologi.site/${{ gitea.repository_owner }}/kulakpos_web:$IMAGE_TAG" ]; then
|
||||||
|
echo "Rolling back to: $PREVIOUS_IMAGE"
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
|
--health-cmd="curl -f http://127.0.0.1:8000 || exit 1" \
|
||||||
|
--health-interval=30s \
|
||||||
|
--health-timeout=10s \
|
||||||
|
--health-start-period=40s \
|
||||||
|
--health-retries=3 \
|
||||||
--name kulakpos_web_prod \
|
--name kulakpos_web_prod \
|
||||||
--network="host" \
|
--network="host" \
|
||||||
-v /opt/kulakpos/.env:/var/www/html/.env \
|
-v /opt/kulakpos/.env:/var/www/html/.env \
|
||||||
-p 8000:8000 \
|
-e MODE=production \
|
||||||
-e MODE=prod \
|
|
||||||
-e APP_ENV=production \
|
-e APP_ENV=production \
|
||||||
|
-e APP_DEBUG=false \
|
||||||
|
-e AUTO_MIGRATE=false \
|
||||||
$PREVIOUS_IMAGE
|
$PREVIOUS_IMAGE
|
||||||
echo "Rollback attempted"
|
echo "Rollback completed"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# - name: Verify Production Deployment
|
|
||||||
# run: |
|
|
||||||
# ssh kulakpos_prod "curl -f http://localhost:8000/health || curl -f http://localhost:8000 || echo 'Service is running but health check endpoint not configured'"
|
|
||||||
# echo "✅ Production deployment verified!"
|
|
||||||
|
|
||||||
- name: Verify Production Deployment
|
|
||||||
run: |
|
|
||||||
ssh kulakpos_prod "docker ps --filter 'name=kulakpos_web_prod' --format '{{.Status}}' | grep -q healthy"
|
|
||||||
echo "✅ Production deployment verified!"
|
|
||||||
|
|
||||||
- name: Send Deployment Notification
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
STATUS="${{ job.status }}"
|
|
||||||
if [ "$STATUS" = "success" ]; then
|
|
||||||
echo "✅ Production deployment completed successfully!"
|
|
||||||
else
|
|
||||||
echo "❌ Production deployment failed!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [deploy-staging, deploy-production]
|
|
||||||
if: always()
|
|
||||||
steps:
|
|
||||||
- name: Cleanup old Docker images on runners
|
|
||||||
run: |
|
|
||||||
docker system prune -f --filter "until=24h"
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -20,3 +20,4 @@ yarn-error.log
|
|||||||
/public/modules/*
|
/public/modules/*
|
||||||
.qodo
|
.qodo
|
||||||
.camel-jbang
|
.camel-jbang
|
||||||
|
dump/
|
||||||
@@ -53,7 +53,8 @@
|
|||||||
"mockery/mockery": "^1.4.4",
|
"mockery/mockery": "^1.4.4",
|
||||||
"nunomaduro/collision": "^7.0",
|
"nunomaduro/collision": "^7.0",
|
||||||
"phpunit/phpunit": "^10.1",
|
"phpunit/phpunit": "^10.1",
|
||||||
"spatie/laravel-ignition": "^2.0"
|
"spatie/laravel-ignition": "^2.0",
|
||||||
|
"knuckleswtf/scribe": "5.9.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
115
entrypoint.sh
115
entrypoint.sh
@@ -9,9 +9,14 @@ echo "========================================"
|
|||||||
echo "Current user: $(whoami)"
|
echo "Current user: $(whoami)"
|
||||||
echo "Current directory: $(pwd)"
|
echo "Current directory: $(pwd)"
|
||||||
|
|
||||||
# Force debug mode for troubleshooting
|
# Set debug based on environment
|
||||||
export APP_DEBUG=true
|
if [ "$APP_ENV" = "production" ]; then
|
||||||
export LOG_LEVEL=debug
|
export APP_DEBUG=false
|
||||||
|
export LOG_LEVEL=error
|
||||||
|
else
|
||||||
|
export APP_DEBUG=true
|
||||||
|
export LOG_LEVEL=debug
|
||||||
|
fi
|
||||||
|
|
||||||
# Create ALL required Laravel directories
|
# Create ALL required Laravel directories
|
||||||
echo "Creating storage directories..."
|
echo "Creating storage directories..."
|
||||||
@@ -62,7 +67,6 @@ fi
|
|||||||
echo "Checking .env for APP_KEY..."
|
echo "Checking .env for APP_KEY..."
|
||||||
if ! grep -E "APP_KEY=.{10,}" .env; then
|
if ! grep -E "APP_KEY=.{10,}" .env; then
|
||||||
echo "APP_KEY is empty or missing. Generating..."
|
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 the file doesn't have APP_KEY= at all, add it so artisan can replace it
|
||||||
if ! grep -q "APP_KEY=" .env; then
|
if ! grep -q "APP_KEY=" .env; then
|
||||||
echo "Appending APP_KEY= placeholder..."
|
echo "Appending APP_KEY= placeholder..."
|
||||||
@@ -77,10 +81,62 @@ grep "APP_KEY" .env
|
|||||||
|
|
||||||
# Ensure vendor directory matches composer.lock exactly, syncing missing packages
|
# Ensure vendor directory matches composer.lock exactly, syncing missing packages
|
||||||
echo "Verifying and synchronizing Composer dependencies..."
|
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
|
# Check if scribe is in composer.json but not installed
|
||||||
|
if grep -q "knuckleswtf/scribe" composer.json; then
|
||||||
|
if ! composer show --locked knuckleswtf/scribe --no-ansi 2>/dev/null | grep -q "name"; then
|
||||||
|
echo "📦 knuckleswtf/scribe found in composer.json but not in lock file. Installing..."
|
||||||
|
composer require --dev knuckleswtf/scribe --no-interaction --no-progress --update-with-dependencies
|
||||||
|
else
|
||||||
|
echo "✅ knuckleswtf/scribe is already in lock file"
|
||||||
|
composer install --no-interaction --optimize-autoloader
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Normal install
|
||||||
|
composer install --no-interaction --optimize-autoloader
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If install fails, try update
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "⚠️ Composer install failed, attempting update..."
|
||||||
|
composer update --no-interaction --optimize-autoloader --with-all-dependencies
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install and publish Scribe assets
|
||||||
|
echo "Setting up Scribe/OpenAPI documentation..."
|
||||||
|
|
||||||
|
# Publish Scribe config (if not already published)
|
||||||
|
if [ ! -f config/scribe.php ]; then
|
||||||
|
echo "Publishing Scribe configuration..."
|
||||||
|
php artisan vendor:publish --tag=scribe-config --force
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate OpenAPI/Swagger documentation
|
||||||
|
if [ "$APP_ENV" != "production" ] || [ "$AUTO_GENERATE_API_DOCS" = "true" ]; then
|
||||||
|
echo "Generating API documentation..."
|
||||||
|
|
||||||
|
# Generate Scribe documentation
|
||||||
|
php artisan scribe:generate --no-interaction || echo "⚠️ Scribe generation failed, check your API routes"
|
||||||
|
|
||||||
|
# For OpenAPI/Swagger UI specifically
|
||||||
|
if [ -f public/docs/openapi.yaml ] || [ -f public/docs/collection.json ]; then
|
||||||
|
echo "✅ Documentation generated successfully"
|
||||||
|
echo "📚 Swagger UI available at: /docs (if configured)"
|
||||||
|
echo "📄 OpenAPI spec available at: /docs/openapi.yaml"
|
||||||
|
else
|
||||||
|
echo "⚠️ Documentation files not found after generation"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create symbolic link for Scribe assets if needed
|
||||||
|
if [ -d vendor/knuckleswtf/scribe/dist ]; then
|
||||||
|
echo "Creating Scribe assets symlink..."
|
||||||
|
mkdir -p public/vendor/scribe
|
||||||
|
cp -r vendor/knuckleswtf/scribe/dist/* public/vendor/scribe/ 2>/dev/null || \
|
||||||
|
ln -sf ../vendor/knuckleswtf/scribe/dist public/vendor/scribe 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# FIX: Ensure all generated/downloaded files are fully readable and executable
|
||||||
echo "Setting correct ownership for web server..."
|
echo "Setting correct ownership for web server..."
|
||||||
chown -R www-data:www-data vendor
|
chown -R www-data:www-data vendor
|
||||||
chmod -R 755 vendor
|
chmod -R 755 vendor
|
||||||
@@ -91,13 +147,21 @@ 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 '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";'
|
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
|
||||||
echo "Clearing caches..."
|
if [ "$APP_ENV" = "production" ] || [ "$MODE" = "production" ]; then
|
||||||
php artisan config:clear || true
|
echo "Running production optimizations..."
|
||||||
php artisan view:clear || true
|
php artisan config:cache
|
||||||
php artisan route:clear || true
|
php artisan view:cache
|
||||||
php artisan cache:clear || true
|
php artisan event:cache
|
||||||
php artisan optimize:clear || true
|
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
|
# Verify Vite manifest exists
|
||||||
if [ -f public/build/manifest.json ]; then
|
if [ -f public/build/manifest.json ]; then
|
||||||
@@ -108,20 +172,29 @@ else
|
|||||||
ls -la public/build/ 2>/dev/null || echo "public/build directory does not exist"
|
ls -la public/build/ 2>/dev/null || echo "public/build directory does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Optional: Run migrations if needed
|
# Optional: Run migrations if needed (with safety for production)
|
||||||
php artisan migrate --force
|
if [ "$AUTO_MIGRATE" = "true" ] || [ "$APP_ENV" != "production" ]; then
|
||||||
|
echo "Running migrations..."
|
||||||
|
php artisan migrate --force
|
||||||
|
fi
|
||||||
|
|
||||||
echo "========================================"
|
echo "========================================"
|
||||||
echo "Setup complete. Starting application..."
|
echo "Setup complete. Starting application..."
|
||||||
echo "========================================"
|
echo "========================================"
|
||||||
|
|
||||||
# Start the application with proper error handling
|
# Start the application based on environment
|
||||||
if [ "$MODE" = "staging" ]; then
|
if [ "$APP_ENV" = "production" ] || [ "$MODE" = "production" ]; then
|
||||||
echo "Starting DIRECT PHP server on port 8000 (Bypassing artisan serve)..."
|
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
|
# 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
|
else
|
||||||
echo "Starting PHP-FPM on port 9000..."
|
echo "Starting PHP-FPM on port 9000 (Development mode)..."
|
||||||
# Ensure PHP-FPM is properly configured
|
# Ensure PHP-FPM is properly configured
|
||||||
exec php-fpm -F
|
exec php-fpm -F
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user