k8-mini-app/ci-build.sh

43 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Script per buildare e pushare le immagini al registry locale
# Variabili
REGISTRY="localhost:5000"
TAG=$(date +%Y%m%d-%H%M%S) # Usa timestamp come tag
# Verifica che il registry locale sia in esecuzione
if ! curl -s http://localhost:5000/v2/ > /dev/null; then
echo "❌ Registry localhost:5000 non raggiungibile. Avvialo con: docker run -d -p 5000:5000 registry:2"
exit 1
fi
# Build e push delle immagini
echo "🔨 Building backend image..."
docker build -t $REGISTRY/backend:$TAG ./backend
docker push $REGISTRY/backend:$TAG
echo "🔨 Building frontend image..."
docker build -t $REGISTRY/frontend:$TAG ./frontend
docker push $REGISTRY/frontend:$TAG
echo "🔨 Building worker image..."
docker build -t $REGISTRY/worker:$TAG ./worker
docker push $REGISTRY/worker:$TAG
# Aggiorna i file YAML di Kubernetes
echo "📝 Updating Kubernetes manifests..."
sed -i "s|localhost:5000/backend:latest|$REGISTRY/backend:$TAG|g" k8s/backend.yaml
sed -i "s|localhost:5000/frontend:latest|$REGISTRY/frontend:$TAG|g" k8s/frontend.yaml
sed -i "s|localhost:5000/worker:latest|$REGISTRY/worker:$TAG|g" k8s/worker.yaml
# Commit e push a Gitea se necessario
if [ "$1" == "--push" ]; then
echo "🚀 Pushing changes to Gitea..."
git add k8s/
git commit -m "Update images to tag $TAG"
git push
fi
echo "✅ Build completato. Immagini taggate come: $TAG"
echo "📋 Per applicare le modifiche manualmente: kubectl apply -f k8s/"
echo "🔄 Per sincronizzare con Argo CD: argocd app sync k8-mini-app"