Fix deployment pipeline: resolve git divergent branches and prevent paperless build issues

- Updated git pull strategy to use fetch + reset instead of pull to handle divergent branches
- Added docker system prune to clean up build artifacts
- Modified image pulling to separate web services from standard images
- Added --no-build flag to prevent accidental local builds
- Addresses production 502 errors from failed deployments
This commit is contained in:
Stiftung Development
2025-09-21 20:52:41 +02:00
parent 8c7a5173a8
commit 34b30be0a6

View File

@@ -208,8 +208,10 @@ jobs:
echo "Production .env file found - proceeding with deployment" echo "Production .env file found - proceeding with deployment"
# Pull latest code changes (.env is in .gitignore so won't be touched) # Configure git pull strategy and force pull latest code changes
git pull https://$DEPLOY_TOKEN@github.com/remmerinio/stiftung-management-system.git main git config pull.rebase false
git fetch https://$DEPLOY_TOKEN@github.com/remmerinio/stiftung-management-system.git main
git reset --hard FETCH_HEAD
# The main compose.yml is already the correct production configuration # The main compose.yml is already the correct production configuration
# No need to copy from deploy-production since we use compose.yml directly # No need to copy from deploy-production since we use compose.yml directly
@@ -219,8 +221,8 @@ jobs:
echo "Attempting to pull images from GitHub Container Registry..." echo "Attempting to pull images from GitHub Container Registry..."
if echo $DEPLOY_TOKEN | docker login ghcr.io -u remmerinio --password-stdin; then if echo $DEPLOY_TOKEN | docker login ghcr.io -u remmerinio --password-stdin; then
echo "✅ Successfully logged into GHCR" echo "✅ Successfully logged into GHCR"
if docker-compose -f compose.yml pull; then if docker-compose -f compose.yml pull web worker beat; then
echo "✅ Successfully pulled images from GHCR" echo "✅ Successfully pulled web images from GHCR"
USE_REMOTE_IMAGES=true USE_REMOTE_IMAGES=true
else else
echo "⚠️ Failed to pull images from GHCR, will build locally" echo "⚠️ Failed to pull images from GHCR, will build locally"
@@ -231,17 +233,22 @@ jobs:
USE_REMOTE_IMAGES=false USE_REMOTE_IMAGES=false
fi fi
# Pull other standard images (paperless, redis, postgres, grampsweb)
echo "Pulling standard Docker images..."
docker-compose -f compose.yml pull db redis paperless grampsweb || echo "Some standard images failed to pull, will use cached versions"
# If we couldn't pull from GHCR, build locally # If we couldn't pull from GHCR, build locally
if [ "$USE_REMOTE_IMAGES" = "false" ]; then if [ "$USE_REMOTE_IMAGES" = "false" ]; then
echo "🔨 Building images locally from source code..." echo "🔨 Building images locally from source code..."
docker build -t ghcr.io/remmerinio/stiftung-management-system:latest ./app docker build -t ghcr.io/remmerinio/stiftung-management-system:latest ./app
fi fi
# Stop containers # Stop containers and clean up
docker-compose -f compose.yml down docker-compose -f compose.yml down
docker system prune -f
# Start containers with latest images # Start containers with latest images
docker-compose -f compose.yml up -d docker-compose -f compose.yml up -d --no-build
# Wait for containers to be ready # Wait for containers to be ready
echo "Waiting for containers to start..." echo "Waiting for containers to start..."