refactor: Improve deployment workflow with retry logic for image pushes and optimized build process
Some checks failed
Deploy to Production, build images and push to Gitea Registry / build_and_push (pull_request) Has been cancelled

This commit is contained in:
mohamad 2025-06-01 16:03:58 +02:00
parent 1e9957de91
commit 59f2f47949

View File

@ -51,24 +51,27 @@ jobs:
echo "Using ACTOR: $ACTOR" echo "Using ACTOR: $ACTOR"
echo "Using REPO_NAME: $REPO_NAME" echo "Using REPO_NAME: $REPO_NAME"
# Build with compression # Build with compression and smaller layers
docker build --compress -t git.vinylnostalgia.com/$ACTOR/$REPO_NAME-backend:latest ./be -f ./be/Dockerfile.prod docker build --compress --no-cache -t git.vinylnostalgia.com/$ACTOR/$REPO_NAME-backend:latest ./be -f ./be/Dockerfile.prod
# Save image to tar file # Push with retries
docker save git.vinylnostalgia.com/$ACTOR/$REPO_NAME-backend:latest > backend.tar max_retries=3
retry_count=0
# Split the tar file into smaller chunks (100MB each) while [ $retry_count -lt $max_retries ]; do
split -b 100M backend.tar backend.tar.part_ if docker push git.vinylnostalgia.com/$ACTOR/$REPO_NAME-backend:latest; then
break
# Push each chunk fi
for chunk in backend.tar.part_*; do retry_count=$((retry_count + 1))
docker load < "$chunk" if [ $retry_count -lt $max_retries ]; then
docker push git.vinylnostalgia.com/$ACTOR/$REPO_NAME-backend:latest echo "Push failed, retrying in 10 seconds... (Attempt $retry_count of $max_retries)"
sleep 5 # Add delay between pushes sleep 10
fi
done done
# Cleanup if [ $retry_count -eq $max_retries ]; then
rm backend.tar backend.tar.part_* echo "Failed to push after $max_retries attempts"
exit 1
fi
- name: Build and push frontend image - name: Build and push frontend image
env: env:
@ -93,21 +96,24 @@ jobs:
echo "Using ACTOR: $ACTOR" echo "Using ACTOR: $ACTOR"
echo "Using REPO_NAME: $REPO_NAME" echo "Using REPO_NAME: $REPO_NAME"
# Build with compression # Build with compression and smaller layers
docker build --compress -t git.vinylnostalgia.com/$ACTOR/$REPO_NAME-frontend:latest ./fe -f ./fe/Dockerfile.prod docker build --compress --no-cache -t git.vinylnostalgia.com/$ACTOR/$REPO_NAME-frontend:latest ./fe -f ./fe/Dockerfile.prod
# Save image to tar file # Push with retries
docker save git.vinylnostalgia.com/$ACTOR/$REPO_NAME-frontend:latest > frontend.tar max_retries=3
retry_count=0
# Split the tar file into smaller chunks (100MB each) while [ $retry_count -lt $max_retries ]; do
split -b 100M frontend.tar frontend.tar.part_ if docker push git.vinylnostalgia.com/$ACTOR/$REPO_NAME-frontend:latest; then
break
# Push each chunk fi
for chunk in frontend.tar.part_*; do retry_count=$((retry_count + 1))
docker load < "$chunk" if [ $retry_count -lt $max_retries ]; then
docker push git.vinylnostalgia.com/$ACTOR/$REPO_NAME-frontend:latest echo "Push failed, retrying in 10 seconds... (Attempt $retry_count of $max_retries)"
sleep 5 # Add delay between pushes sleep 10
fi
done done
# Cleanup if [ $retry_count -eq $max_retries ]; then
rm frontend.tar frontend.tar.part_* echo "Failed to push after $max_retries attempts"
exit 1
fi