This commit is contained in:
alessandro barucci
2026-10-11 23:49:35 +02:00
parent 23f276417f
commit 34213918fe
32 changed files with 1411 additions and 9 deletions
+35 -9
View File
@@ -47,8 +47,10 @@ for dir in containers/*/; do
PLATFORM_CONF="$dir/platform.conf"
BUILD_PLATFORM=""
MULTISTAGE=""
if [ -f "$PLATFORM_CONF" ]; then
BUILD_PLATFORM=$(grep -E '^[[:space:]]*platform[[:space:]]*=' "$PLATFORM_CONF" | tail -n 1 | cut -d '=' -f 2- | tr -d '[:space:]')
MULTISTAGE=$(grep -E '^[[:space:]]*multistage[[:space:]]*=' "$PLATFORM_CONF" | tail -n 1 | cut -d '=' -f 2- | tr -d '[:space:]')
if [ -n "$BUILD_PLATFORM" ]; then
echo "platform.conf trovato in $dir: uso platform=$BUILD_PLATFORM"
else
@@ -57,15 +59,39 @@ for dir in containers/*/; do
fi
if [ -f "$DOCKERFILE" ]; then
if [ -n "$BUILD_PLATFORM" ]; then
docker buildx build --platform "$BUILD_PLATFORM" -t "$IMAGE_TAG" -t "$IMAGE_TAG_LATEST" -f "$DOCKERFILE" "$dir" --push
else
docker buildx build \
--cache-from=type=registry,ref="${REGISTRY_URL}/${REPO_NAME}/${CONTAINER_NAME}:cache" \
--cache-to=type=registry,ref="${REGISTRY_URL}/${REPO_NAME}/${CONTAINER_NAME}:cache",mode=max \
-t "$IMAGE_TAG" -t "$IMAGE_TAG_LATEST" \
-f "$DOCKERFILE" "$dir" --push
fi
if [ -n "$MULTISTAGE" ] && ! [[ "$MULTISTAGE" =~ ^[1-9][0-9]*$ ]]; then
echo "Valore multistage non valido in $PLATFORM_CONF: $MULTISTAGE"
exit 1
fi
BUILD_COUNT="${MULTISTAGE:-1}"
for ((target_index = 1; target_index <= BUILD_COUNT; target_index++)); do
BUILD_TARGET=""
if [ -n "$MULTISTAGE" ]; then
BUILD_TARGET=$(grep -E "^[[:space:]]*target${target_index}[[:space:]]*=" "$PLATFORM_CONF" | tail -n 1 | cut -d '=' -f 2- | tr -d '[:space:]')
if [ -z "$BUILD_TARGET" ]; then
echo "target${target_index} non valorizzato in $PLATFORM_CONF"
exit 1
fi
fi
echo "Build $target_index/$BUILD_COUNT${BUILD_TARGET:+ target=$BUILD_TARGET}"
BUILD_TARGET_ARGS=()
if [ -n "$BUILD_TARGET" ]; then
BUILD_TARGET_ARGS=(--target "$BUILD_TARGET")
fi
if [ -n "$BUILD_PLATFORM" ]; then
docker buildx build --platform "$BUILD_PLATFORM" "${BUILD_TARGET_ARGS[@]}" -t "$IMAGE_TAG" -t "$IMAGE_TAG_LATEST" -f "$DOCKERFILE" "$dir" --push
else
docker buildx build \
--cache-from=type=registry,ref="${REGISTRY_URL}/${REPO_NAME}/${CONTAINER_NAME}:cache" \
--cache-to=type=registry,ref="${REGISTRY_URL}/${REPO_NAME}/${CONTAINER_NAME}:cache",mode=max \
"${BUILD_TARGET_ARGS[@]}" \
-t "$IMAGE_TAG" -t "$IMAGE_TAG_LATEST" \
-f "$DOCKERFILE" "$dir" --push
fi
done
echo "Build e push completate: $IMAGE_TAG"
# Cleanup immagini locali dopo il push (buildx --push potrebbe non averle in locale)
+6
View File
@@ -7,6 +7,8 @@ ENVIRONMENT="${1:-dev}"
YAML_DIR="kubernetes"
# Valore di alert_notification_email per l'ambiente (ultima occorrenza in env/<env>/*.env)
ALERT_EMAIL=$(cat "env/$ENVIRONMENT"/*.env 2>/dev/null | grep -E '^[[:space:]]*alert_notification_email[[:space:]]*=' | tail -n 1 | sed -E 's/^[^=]*=//' | tr -d '\r"'"'"'[:space:]' || true)
# ---------------------------------------------------------------------------
@@ -15,6 +17,10 @@ YAML_DIR="kubernetes"
find "$YAML_DIR" -type d | while read DIR; do
if ls "$DIR"/*.yaml 1> /dev/null 2>&1; then
if [ "$(basename "$DIR")" = "monitoring" ]; then
if [ -z "$ALERT_EMAIL" ]; then
echo "alert_notification_email non valorizzata per l'ambiente $ENVIRONMENT: deploy di $DIR saltato."
continue
fi
echo "Deploy delle risorse di monitoring nella directory $DIR con kubeconfig dedicato..."
kubectl --kubeconfig=/root/work/pipeline/kc apply -f "$DIR"
else