feat: docker-push ne build que les services modifiés depuis le dernier tag

Détecte les fichiers changés depuis le dernier tag v* :
- apps/api/ ou crates/ changés → rebuild api
- apps/indexer/ ou crates/ changés → rebuild indexer
- apps/backoffice/ changé → rebuild backoffice
- Cargo.toml/Cargo.lock changés → rebuild tout

Affiche les services à build/skip, demande confirmation.
Option de forcer le build de tout si rien n'a changé.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 20:44:32 +02:00
parent 991f468d19
commit 93399c3a3d

View File

@@ -54,13 +54,66 @@ fi
VERSION="$NEW_VERSION"
# ─── Detect changed services ─────────────────────────────────────────────────
LAST_TAG=$(git tag -l "v*" --sort=-v:refname | head -1)
CHANGED_SERVICES=()
if [ -n "$LAST_TAG" ]; then
CHANGED_FILES=$(git diff --name-only "$LAST_TAG"..HEAD 2>/dev/null || echo "")
CRATES_CHANGED=false
if echo "$CHANGED_FILES" | grep -q "^crates/"; then
CRATES_CHANGED=true
fi
for service in "${SERVICES[@]}"; do
if echo "$CHANGED_FILES" | grep -q "^apps/$service/"; then
CHANGED_SERVICES+=("$service")
elif [ "$CRATES_CHANGED" = true ] && [ "$service" != "backoffice" ]; then
# Shared crates affect api and indexer, not backoffice
CHANGED_SERVICES+=("$service")
fi
done
# Also rebuild if root Cargo.toml/Cargo.lock/Dockerfile changed
if echo "$CHANGED_FILES" | grep -qE "^(Cargo\.(toml|lock)|docker-compose)"; then
for service in "${SERVICES[@]}"; do
if [[ ! " ${CHANGED_SERVICES[*]} " =~ " $service " ]]; then
CHANGED_SERVICES+=("$service")
fi
done
fi
else
# No previous tag → build everything
CHANGED_SERVICES=("${SERVICES[@]}")
fi
# If nothing changed, still allow force-building all
if [ ${#CHANGED_SERVICES[@]} -eq 0 ]; then
echo "No services changed since $LAST_TAG."
read -rp "Build all anyway? [y/N]: " FORCE_ALL
if [[ "$FORCE_ALL" =~ ^[Yy]$ ]]; then
CHANGED_SERVICES=("${SERVICES[@]}")
else
echo "Nothing to push."
exit 0
fi
fi
echo ""
echo "Registry: $REGISTRY"
echo "Version: $VERSION"
echo "Services: ${SERVICES[*]}"
echo "Last tag: ${LAST_TAG:-none}"
echo "Services to build: ${CHANGED_SERVICES[*]}"
echo "Skipped: $(for s in "${SERVICES[@]}"; do [[ ! " ${CHANGED_SERVICES[*]} " =~ " $s " ]] && echo -n "$s "; done)"
echo ""
read -rp "Continue? [Y/n]: " CONFIRM
if [[ "$CONFIRM" =~ ^[Nn]$ ]]; then
echo "Aborted."
exit 0
fi
for service in "${SERVICES[@]}"; do
for service in "${CHANGED_SERVICES[@]}"; do
echo "Building $service..."
docker build -f "apps/$service/Dockerfile" -t "$service:latest" .
@@ -78,12 +131,18 @@ for service in "${SERVICES[@]}"; do
echo ""
done
echo "=== All images pushed to $REGISTRY ==="
echo "Images:"
for service in "${SERVICES[@]}"; do
echo " - $REGISTRY/$OWNER/stripstream-$service:$VERSION"
echo " - $REGISTRY/$OWNER/stripstream-$service:latest"
echo "=== Push complete ==="
echo "Built & pushed:"
for service in "${CHANGED_SERVICES[@]}"; do
echo " $REGISTRY/$OWNER/stripstream-$service:$VERSION"
done
SKIPPED=""
for s in "${SERVICES[@]}"; do
[[ ! " ${CHANGED_SERVICES[*]} " =~ " $s " ]] && SKIPPED="$SKIPPED $s"
done
if [ -n "$SKIPPED" ]; then
echo "Skipped (unchanged):$SKIPPED"
fi
# Tag git with version
if ! git tag -l "v$VERSION" | grep -q "v$VERSION"; then