diff --git a/promote-to-production.sh b/promote-to-production.sh new file mode 100755 index 0000000..a36f367 --- /dev/null +++ b/promote-to-production.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +# Promueve el tag de imagen del frontend actualmente desplegado en Staging +# (workloads/ecommerce-staging/frontend/patches/deployment.yaml) al +# manifiesto real de Producción (workloads/ecommerce/frontend/patches/ +# deployment.yaml). Es la contraparte manual del job "Actualizar +# Manifiesto GitOps (CD)" de .gitea/workflows/build.yaml, que desde +# 2026-09-14 solo actualiza Staging automáticamente en cada push a main. +# +# Asume que este repo (scripts) y apps-registry están clonados como +# hermanos bajo el mismo directorio del lab (mismo layout que +# lab-cruzcloud/{apps-registry,platform-infra,scripts} en esta NAS). + +APPS_REGISTRY_DIR="${APPS_REGISTRY_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../apps-registry" && pwd)}" +STAGING_MANIFEST="${APPS_REGISTRY_DIR}/workloads/ecommerce-staging/frontend/patches/deployment.yaml" +PROD_MANIFEST="${APPS_REGISTRY_DIR}/workloads/ecommerce/frontend/patches/deployment.yaml" +IMAGE_NAME="gitea.cruzcloud.net/devops/ecommerce-frontend" + +test -d "${APPS_REGISTRY_DIR}/.git" || { + echo "ERROR: no se encontró un checkout de apps-registry en ${APPS_REGISTRY_DIR}." + echo "Definí APPS_REGISTRY_DIR=/ruta/al/checkout si no está junto a este repo." + exit 1 +} + +STAGING_VERSION="$(grep -oE "${IMAGE_NAME}:v[0-9.]+" "${STAGING_MANIFEST}" | head -1 | cut -d: -f2)" +test -n "${STAGING_VERSION}" || { + echo "ERROR: no se pudo leer la versión actual de Staging desde ${STAGING_MANIFEST}." + exit 1 +} + +CURRENT_PROD_VERSION="$(grep -oE "${IMAGE_NAME}:v[0-9.]+" "${PROD_MANIFEST}" | head -1 | cut -d: -f2)" + +echo "Staging: ${STAGING_VERSION}" +echo "Producción: ${CURRENT_PROD_VERSION}" + +if [[ "${STAGING_VERSION}" == "${CURRENT_PROD_VERSION}" ]]; then + echo "Producción ya está en ${STAGING_VERSION}. Nada que promover." + exit 0 +fi + +read -rp "¿Promover ${STAGING_VERSION} a Producción? [s/N] " CONFIRM +[[ "${CONFIRM}" =~ ^[sS]$ ]] || { echo "Cancelado."; exit 1; } + +cd "${APPS_REGISTRY_DIR}" +git fetch origin main +git checkout -B main origin/main + +sed -i -E "s|(image: ${IMAGE_NAME}:).*|\1${STAGING_VERSION}|g" "${PROD_MANIFEST}" + +git add "${PROD_MANIFEST}" +if git diff --cached --quiet; then + echo "No hay cambios en el manifiesto de Producción." + exit 0 +fi + +git commit -m "chore: promote ${STAGING_VERSION} to production" +git push origin HEAD:main + +echo "Promovido. Argo CD sincroniza ecommerce-app en unos segundos."