libretime/easypanel/update.sh
Cesar Jhoanny Mendivil Rubio 83724ddc26
Some checks are pending
Container / meta (analyzer) (push) Waiting to run
Container / meta (api) (push) Waiting to run
Container / meta (legacy) (push) Waiting to run
Container / meta (nginx) (push) Waiting to run
Container / meta (playout) (push) Waiting to run
Container / meta (worker) (push) Waiting to run
Container / build (push) Blocked by required conditions
Project / pre-commit (push) Waiting to run
Project / test-tools (push) Waiting to run
Release-Please / release-please (push) Waiting to run
feat(easypanel): agregar instrucciones y validaciones para secretos en EasyPanel, incluyendo generación de contraseñas seguras y actualización de archivos de configuración
2025-10-01 17:33:30 -07:00

82 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Este script prepara el compose para EasyPanel.
# Si Node.js está disponible y existe easypanel/update.js, lo ejecuta.
# De lo contrario, realiza la copia y saneado en bash/perl (fallback).
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
SRC="$BASE_DIR/../docker-compose.easypanel.yml"
DEST_DIR="$BASE_DIR/code"
DEST="$DEST_DIR/docker-compose.yml"
REQUIRED_SECRETS=(POSTGRES_PASSWORD RABBITMQ_DEFAULT_PASS)
function read_env_file() {
local f="$BASE_DIR/service.env"
if [ ! -f "$f" ]; then
return
fi
# shellcheck disable=SC1090
# do not source to avoid side effects; parse manually
grep -E '^[A-Za-z_][A-Za-z0-9_]*=' "$f" | sed "s/^[^=]*=//" >/dev/null 2>&1 || true
}
function check_required_secrets() {
local missing=()
for key in "${REQUIRED_SECRETS[@]}"; do
# prefer environment then service.env
val="${!key:-}"
if [ -z "$val" ] && [ -f "$BASE_DIR/service.env" ]; then
val=$(grep -E "^${key}=" "$BASE_DIR/service.env" | head -n1 | sed -E "s/^${key}=//")
fi
if [ -z "$val" ] || echo "$val" | grep -Eiq '^(CAMBIA|pon_aqui|tu_|CHANGE|REPLACE)'; then
missing+=("$key")
fi
done
if [ ${#missing[@]} -ne 0 ]; then
echo "ERROR: faltan valores seguros para las siguientes variables: ${missing[*]}"
echo "Definelas en la sección Environment/Secrets de EasyPanel o en $BASE_DIR/service.env"
exit 2
fi
}
check_required_secrets
if command -v node >/dev/null 2>&1 && [ -f "$BASE_DIR/update.js" ]; then
echo "Node.js detectado, ejecutando easypanel/update.js"
# Ejecutar con node (permitirá usar la versión JS en lugar del sed/perl)
node "$BASE_DIR/update.js"
echo "Preparado $DEST para EasyPanel (vía update.js)."
exit 0
fi
echo "Node.js no disponible o easypanel/update.js no encontrado; usando fallback shell copy"
mkdir -p "$DEST_DIR"
if [ ! -f "$SRC" ]; then
echo "ERROR: no se encuentra $SRC"
exit 2
fi
# Copiar
cp "$SRC" "$DEST"
# Eliminar container_name y ports keys (simplemente eliminamos las líneas que contienen 'container_name:' o 'ports:')
# Esto es similar a lo que hacen muchos ejemplos de EasyPanel.
if command -v perl >/dev/null 2>&1; then
perl -0777 -pe "s/^[ \t]*container_name:[^\n]*\n//mg" -i "$DEST"
perl -0777 -pe "s/^[ \t]*ports:[^\n]*\n(?:^[ \t]+-.*\n)*//mg" -i "$DEST"
perl -0777 -pe "s/^[ \t]*version:[^\n]*\n//mg" -i "$DEST"
else
# Fallback con awk/sed si perl no está disponible
# Elimina líneas 'container_name:' y bloques 'ports:' simples
sed -E '/^[ \t]*container_name:/d' -i "" "$DEST" 2>/dev/null || sed -E '/^[ \t]*container_name:/d' -i '$DEST'
awk 'BEGIN{skip=0} /^[ \t]*ports:[ \t]*$/ {skip=1; next} /^[ \t]*[^ \t]/ { if(skip){skip=0} } { if(!skip) print $0 }' "$DEST" > "$DEST.tmp" && mv "$DEST.tmp" "$DEST"
# Elimina 'version:' si queda
sed -E '/^[ \t]*version:/d' -i "" "$DEST" 2>/dev/null || sed -E '/^[ \t]*version:/d' -i '$DEST'
fi
echo "Preparado $DEST para EasyPanel. Revisa variables de entorno en el README y súbelas en la UI de EasyPanel."