From 3640cd57548fcbe7e262ce195b9b87911397034b Mon Sep 17 00:00:00 2001 From: Cristian Felipe Cruz Buitron Date: Mon, 14 Sep 2026 02:46:06 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20script=20de=20promoci=C3=B3n=20manual?= =?UTF-8?q?=20de=20Staging=20a=20Producci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contraparte del cambio en apps-registry/.gitea/workflows/build.yaml: desde ahora el CI solo actualiza Staging automáticamente en cada push. Este script lee la versión actual en workloads/ecommerce-staging/frontend/patches/deployment.yaml y la aplica a workloads/ecommerce/frontend/patches/deployment.yaml (con confirmación interactiva), commiteando y pusheando a apps-registry. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_012Y4df3Z7odr9Cg8F2nw6uV --- promote-to-production.sh | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 promote-to-production.sh 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."