ci(deploy): config por entorno en /etc/localesp/<slug>.env
deploy-branch / deploy (push) Successful in 3m18s
deploy-branch / teardown (push) Skipped
tests / Unitarias + componente + build (push) Failing after 3m25s
tests / Integración (Nominatim real, opt-in) (push) Skipped
tests / Unitarias + componente + build (pull_request) Failing after 3m29s
tests / Integración (Nominatim real, opt-in) (pull_request) Skipped
deploy-branch / deploy (push) Successful in 3m18s
deploy-branch / teardown (push) Skipped
tests / Unitarias + componente + build (push) Failing after 3m25s
tests / Integración (Nominatim real, opt-in) (push) Skipped
tests / Unitarias + componente + build (pull_request) Failing after 3m29s
tests / Integración (Nominatim real, opt-in) (pull_request) Skipped
El build ahora exige LOCALESP_ADMIN_PREFIX (sin valor por defecto), así que el CI necesita saber el prefijo de cada entorno de rama: - deploy.yml: el paso de build carga /etc/localesp/<slug>.env del host (Slug::from de lib/env.sh) y falla con mensaje claro si no existe - env.sh: Env::require_config valida la config, y Env::deploy la copia a <dest>/.env, que el servidor autocarga (sobrevive a rsync --delete) - tests.yml: el smoke-build usa un prefijo placeholder (/admin-ci); comprueba que el build funciona, no la configuración del entorno
This commit is contained in:
@@ -27,10 +27,23 @@ jobs:
|
|||||||
|
|
||||||
- name: Build (npm ci + vite build)
|
- name: Build (npm ci + vite build)
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
BRANCH: ${{ github.event.inputs.branch || github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
# better-sqlite3 (v12) requiere C++20; el GCC 8 del sistema (AlmaLinux 8) no lo soporta.
|
# better-sqlite3 (v12) requiere C++20; el GCC 8 del sistema (AlmaLinux 8) no lo soporta.
|
||||||
# gcc-toolset-12 (GCC 12) ya está instalado en /opt/rh.
|
# gcc-toolset-12 (GCC 12) ya está instalado en /opt/rh.
|
||||||
source /opt/rh/gcc-toolset-12/enable 2>/dev/null || echo "WARN: gcc-toolset-12 no encontrado"
|
source /opt/rh/gcc-toolset-12/enable 2>/dev/null || echo "WARN: gcc-toolset-12 no encontrado"
|
||||||
|
# Config por entorno en el host (la misma que usará el despliegue):
|
||||||
|
# /etc/localesp/<slug>.env define LOCALESP_ADMIN_PREFIX, que el build
|
||||||
|
# incrusta en el bundle. Sin ella el build falla (sin valor por defecto).
|
||||||
|
. scripts/lib/env.sh
|
||||||
|
slug="$(Slug::from "$BRANCH")"
|
||||||
|
config="/etc/localesp/${slug}.env"
|
||||||
|
if [ ! -f "$config" ]; then
|
||||||
|
echo "::error::Falta $config en el host: crea el fichero con LOCALESP_ADMIN_PREFIX=<prefijo> y relanza" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
set -a; . "$config"; set +a
|
||||||
npm ci
|
npm ci
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ jobs:
|
|||||||
run: npm test
|
run: npm test
|
||||||
|
|
||||||
- name: Build de producción
|
- name: Build de producción
|
||||||
|
# Smoke build: el prefijo real lo aporta cada entorno en deploy.yml
|
||||||
|
# (config /etc/localesp/<slug>.env del host). Aquí basta un valor
|
||||||
|
# cualquiera: se comprueba que el build funciona, no la configuración.
|
||||||
|
env:
|
||||||
|
LOCALESP_ADMIN_PREFIX: /admin-ci
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
integracion:
|
integracion:
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
DOMAIN="localesp.es"
|
DOMAIN="localesp.es"
|
||||||
PORT_BASE=8082 # 8080/8081 son entornos legacy
|
PORT_BASE=8082 # 8080/8081 son entornos legacy
|
||||||
|
ENV_CONFIG_DIR="/etc/localesp" # config por entorno: <slug>.env (ver Env::require_config)
|
||||||
LOGGER_TAG="env"
|
LOGGER_TAG="env"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -381,6 +382,7 @@ Env::new() {
|
|||||||
fi
|
fi
|
||||||
s[host]="${s[slug]}.$DOMAIN"
|
s[host]="${s[slug]}.$DOMAIN"
|
||||||
s[dest]="/opt/localesp/${s[slug]}"
|
s[dest]="/opt/localesp/${s[slug]}"
|
||||||
|
s[config]="$ENV_CONFIG_DIR/${s[slug]}.env"
|
||||||
s[unit_name]="localesp-${s[slug]}"
|
s[unit_name]="localesp-${s[slug]}"
|
||||||
s[port]="$(Port::acquire "${s[unit_name]}" "${s[dest]}")"
|
s[port]="$(Port::acquire "${s[unit_name]}" "${s[dest]}")"
|
||||||
|
|
||||||
@@ -390,14 +392,35 @@ Env::new() {
|
|||||||
TlsCert::new "${self}__cert" "${s[host]}"
|
TlsCert::new "${self}__cert" "${s[host]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Config por entorno: /etc/localesp/<slug>.env debe existir y definir al menos
|
||||||
|
# LOCALESP_ADMIN_PREFIX (obligatoria para servidor y build). Es config del
|
||||||
|
# operador (no viaja en el repo): la creación es manual y teardown NO la borra.
|
||||||
|
Env::require_config() {
|
||||||
|
local self="$1"
|
||||||
|
local -n s="$self"
|
||||||
|
|
||||||
|
if [ ! -f "${s[config]}" ]; then
|
||||||
|
Logger::error "falta ${s[config]}: crea el fichero en el host con LOCALESP_ADMIN_PREFIX=<prefijo>"
|
||||||
|
Logger::error "p. ej.: mkdir -p $ENV_CONFIG_DIR && echo 'LOCALESP_ADMIN_PREFIX=/administrador' > ${s[config]}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
Logger::info "config por entorno: ${s[config]}"
|
||||||
|
}
|
||||||
|
|
||||||
Env::deploy() {
|
Env::deploy() {
|
||||||
local self="$1"
|
local self="$1"
|
||||||
local -n s="$self"
|
local -n s="$self"
|
||||||
|
|
||||||
Artifacts::require_built "${s[root]}"
|
Artifacts::require_built "${s[root]}"
|
||||||
|
Env::require_config "$self"
|
||||||
Logger::info "sincronizando artefactos -> ${s[dest]}"
|
Logger::info "sincronizando artefactos -> ${s[dest]}"
|
||||||
Artifacts::sync "${s[root]}" "${s[dest]}"
|
Artifacts::sync "${s[root]}" "${s[dest]}"
|
||||||
|
|
||||||
|
# El servidor autocarga <dest>/.env (no pisa variables del entorno);
|
||||||
|
# rsync --delete sólo afecta a dist/ y server/, así que sobrevive, pero
|
||||||
|
# se recopia en cada despliegue para seguir los cambios de la config.
|
||||||
|
cp "${s[config]}" "${s[dest]}/.env"
|
||||||
|
|
||||||
Logger::info "instalando dependencias (prod)"
|
Logger::info "instalando dependencias (prod)"
|
||||||
Deps::install "${s[root]}" "${s[dest]}"
|
Deps::install "${s[root]}" "${s[dest]}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user