From 5e2388185256a4cec9faaa6a61886867c3f9adb8 Mon Sep 17 00:00:00 2001 From: Edgar Friendly Date: Sun, 1 Nov 2026 11:14:26 +0100 Subject: [PATCH] ci(deploy): alias rama -> entorno (prototipo-ef publica en prototipo-yb01.localesp.es) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sólo hay un subdominio libre configurado (prototipo-yb01.localesp.es), así que la rama prototipo-ef no puede publicar en prototipo-ef.localesp.es. - scripts/entornos.alias.env: mapping = (del repo, revisable en PR). Sin entrada, la rama usa su propio slug. - EnvSlug::environment + uso en Env::new: con alias, la rama reutiliza host, unit systemd, puerto, destino y vhost del entorno indicado; Port::acquire y NginxVhost::find_path ya adoptan los existentes. --- scripts/entornos.alias.env | 9 +++++++++ scripts/lib/env.sh | 22 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 scripts/entornos.alias.env diff --git a/scripts/entornos.alias.env b/scripts/entornos.alias.env new file mode 100644 index 0000000..2922604 --- /dev/null +++ b/scripts/entornos.alias.env @@ -0,0 +1,9 @@ +# entornos.alias.env — alias rama -> entorno (una línea: =) +# +# Por defecto cada rama publica en .localesp.es. Con un alias, la +# rama comparte HOST, unit systemd, puerto y vhost con otro entorno, que es lo +# que hace falta cuando el DNS sólo tiene configurado un subdominio. +# +# prototipo-ef -> se publica en prototipo-yb01.localesp.es (único subdominio +# disponible), ocupando el entorno prototipo-yb01. +prototipo-ef=prototipo-yb01 diff --git a/scripts/lib/env.sh b/scripts/lib/env.sh index d0e26eb..a172c5d 100644 --- a/scripts/lib/env.sh +++ b/scripts/lib/env.sh @@ -25,6 +25,7 @@ DOMAIN="localesp.es" PORT_BASE=8082 # 8080/8081 son entornos legacy LOGGER_TAG="env" +ENV_ALIAS_FILE="scripts/entornos.alias.env" # mapping slug-rama=slug-entorno (fichero del repo) # --------------------------------------------------------------------------- # Logger — servicio singleton (tag configurable según entrypoint). @@ -49,6 +50,25 @@ Slug::from() { printf '%s' "$branch" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//' } +# --------------------------------------------------------------------------- +# EnvSlug — servicio estático: alias rama -> entorno. +# --------------------------------------------------------------------------- +# scripts/entornos.alias.env mapea =. Con alias, la +# rama reutiliza host, unit, puerto, destino y vhost del entorno indicado; sin +# alias, el entorno es la propia rama (comportamiento histórico). +EnvSlug::environment() { + local slug="$1" + local root="${2:-.}" + local alias + + alias="$(grep -E "^[[:space:]]*${slug}[[:space:]]*=" "$root/$ENV_ALIAS_FILE" 2>/dev/null | tail -1 | cut -d= -f2- | tr -d '[:space:]')" + if [ -n "$alias" ]; then + printf '%s' "$alias" + else + printf '%s' "$slug" + fi +} + # --------------------------------------------------------------------------- # Host — servicio estático: IP pública y resolución DNS. # --------------------------------------------------------------------------- @@ -374,7 +394,7 @@ Env::new() { s[branch]="$branch" s[root]="$root" - s[slug]="$(Slug::from "$branch")" + s[slug]="$(EnvSlug::environment "$(Slug::from "$branch")" "$root")" if [ -z "${s[slug]}" ]; then Logger::error "slug vacío para la rama '$branch'" exit 2