chore: sync bdt.sh v2.3.0 (monorepo @ 0a18eed)
This commit is contained in:
94
bdt.sh
94
bdt.sh
@@ -20,7 +20,7 @@ set -euo pipefail
|
|||||||
# CONFIGURACION
|
# CONFIGURACION
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
SCRIPT_VERSION="2.2.0"
|
SCRIPT_VERSION="2.3.0"
|
||||||
SCRIPT_NAME="$(basename "$0")"
|
SCRIPT_NAME="$(basename "$0")"
|
||||||
|
|
||||||
# Directorios - resolver symlinks para encontrar la ruta real
|
# Directorios - resolver symlinks para encontrar la ruta real
|
||||||
@@ -470,6 +470,80 @@ cmd_rebuild() {
|
|||||||
cd "$BDT_ROOT" 2>/dev/null || true
|
cd "$BDT_ROOT" 2>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#===============================================================================
|
||||||
|
# COMANDO: jar-deploy - Subir el JAR local a un server destino y reconstruir allá
|
||||||
|
# Para servicios Java (gateway, service-bus): compila/usa el JAR local, lo sube
|
||||||
|
# por SCP a build/libs del server y corre 'bdt build + up' remoto (vía SSH+sudo).
|
||||||
|
# Ideal para NEWIB01-DEV (.133), que NO alcanza el registry de Gitea.
|
||||||
|
# Config en ~/.bdt/config: DEPLOY_SERVER, DEPLOY_USER, BDT_REMOTE_ROOT (def /opt/bdt-platform).
|
||||||
|
#===============================================================================
|
||||||
|
|
||||||
|
cmd_jar_deploy() {
|
||||||
|
banner
|
||||||
|
local svc="" nocache="" do_build="" a
|
||||||
|
for a in "$@"; do
|
||||||
|
case "$a" in
|
||||||
|
--no-cache|nocache) nocache="--no-cache" ;;
|
||||||
|
--build) do_build="1" ;;
|
||||||
|
*) svc="$a" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
case "$svc" in
|
||||||
|
gateway|service-bus) ;;
|
||||||
|
*) err "jar-deploy es solo para servicios Java: gateway | service-bus"
|
||||||
|
echo -e " Uso: ${GRAY}bdt jar-deploy <gateway|service-bus> [--build] [--no-cache]${NC}"
|
||||||
|
return 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
local server="${DEPLOY_SERVER:-}" user="${DEPLOY_USER:-}"
|
||||||
|
local rroot="${BDT_REMOTE_ROOT:-/opt/bdt-platform}"
|
||||||
|
if [[ -z "$server" || -z "$user" ]]; then
|
||||||
|
err "Falta el server destino. Agregá en ${GRAY}~/.bdt/config${NC}:"
|
||||||
|
echo -e " ${GRAY}DEPLOY_SERVER=10.112.2.133${NC}"
|
||||||
|
echo -e " ${GRAY}DEPLOY_USER=luis.perezsm${NC}"
|
||||||
|
echo -e " ${GRAY}BDT_REMOTE_ROOT=/opt/bdt-platform${NC} (opcional)"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local dir; dir="$(repo_dir "$svc")"
|
||||||
|
[[ -z "$dir" ]] && { err "Servicio desconocido: ${svc}"; return 1; }
|
||||||
|
|
||||||
|
# 1. JAR local (compilar si se pide --build o si no existe)
|
||||||
|
step "1/4 JAR" "Resolviendo JAR local de ${svc}"
|
||||||
|
local jar
|
||||||
|
jar="$(ls "${dir}"/build/libs/*.jar 2>/dev/null | grep -v -- '-plain.jar' | head -1)"
|
||||||
|
if [[ -n "$do_build" || -z "$jar" ]]; then
|
||||||
|
info "Compilando ${svc} (gradle bootJar, sin tests)..."
|
||||||
|
( cd "$dir" && ./gradlew clean bootJar -x test > "${LOG_DIR}/${svc}-jardeploy-gradle.log" 2>&1 ) \
|
||||||
|
|| { err "Gradle falló (ver ${LOG_DIR}/${svc}-jardeploy-gradle.log)"; return 1; }
|
||||||
|
jar="$(ls "${dir}"/build/libs/*.jar 2>/dev/null | grep -v -- '-plain.jar' | head -1)"
|
||||||
|
fi
|
||||||
|
[[ -z "$jar" ]] && { err "No hay JAR en ${dir}/build/libs (corré con --build)"; return 1; }
|
||||||
|
local jar_base; jar_base="$(basename "$jar")"
|
||||||
|
ok "JAR: ${jar} ($(du -h "$jar" | cut -f1))"
|
||||||
|
|
||||||
|
# 2. SCP al server
|
||||||
|
local remote_libs="${rroot}/backend/${svc}/build/libs"
|
||||||
|
step "2/4 SCP" "Subiendo ${jar_base} → ${user}@${server}:${remote_libs}"
|
||||||
|
scp "$jar" "${user}@${server}:/tmp/${svc}-deploy.jar" || { err "SCP falló (¿VPN/SSH al server activa?)"; return 1; }
|
||||||
|
ok "JAR subido a /tmp"
|
||||||
|
|
||||||
|
# 3. Colocar el JAR (solo uno) en build/libs del server
|
||||||
|
step "3/4 PLACE" "Colocando JAR en ${remote_libs} (limpia .jar previos)"
|
||||||
|
ssh "${user}@${server}" "sudo mkdir -p '${remote_libs}' && sudo rm -f '${remote_libs}'/*.jar && sudo cp /tmp/${svc}-deploy.jar '${remote_libs}/${jar_base}' && rm -f /tmp/${svc}-deploy.jar && echo OK" \
|
||||||
|
|| { err "No se pudo colocar el JAR en el server"; return 1; }
|
||||||
|
ok "JAR colocado: ${remote_libs}/${jar_base}"
|
||||||
|
|
||||||
|
# 4. Build + up remoto (usa el bdt.sh del server)
|
||||||
|
step "4/4 REMOTE" "docker build${nocache:+ (sin caché)} + up de ${svc} en ${server}"
|
||||||
|
ssh "${user}@${server}" "cd '${rroot}' && sudo ./bdt.sh build ${svc} ${nocache} && sudo ./bdt.sh up ${svc}" 2>&1 \
|
||||||
|
| while read -r l; do echo -e " ${GRAY}${l}${NC}"; done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
ok "Deploy de ${svc} enviado a ${server}. Verificá salud con: ${GRAY}bdt logs ${svc} 100${NC} (o el health del server)."
|
||||||
|
}
|
||||||
|
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
# COMANDO: up - Levantar servicios
|
# COMANDO: up - Levantar servicios
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
@@ -1130,7 +1204,7 @@ _bdt_completions() {
|
|||||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
local commands="clone pull install build rebuild up down restart status logs health verify-db verify-api deploy construir publish env update creds clean setup menu help image-login image-build image-push image-pull image-deploy image-build-amd64 server-deploy"
|
local commands="clone pull install build rebuild jar-deploy up down restart status logs health verify-db verify-api deploy construir publish env update creds clean setup menu help image-login image-build image-push image-pull image-deploy image-build-amd64 server-deploy"
|
||||||
local services="frontend gateway service-bus canales-admin-web canales-worker apibank infrastructure database"
|
local services="frontend gateway service-bus canales-admin-web canales-worker apibank infrastructure database"
|
||||||
local up_targets="all infra apps tools frontend gateway canales-admin-web canales-worker service-bus postgres redis keycloak"
|
local up_targets="all infra apps tools frontend gateway canales-admin-web canales-worker service-bus postgres redis keycloak"
|
||||||
local envs="desarrollo calidad demo produccion"
|
local envs="desarrollo calidad demo produccion"
|
||||||
@@ -1283,6 +1357,15 @@ _menu_dispatch() {
|
|||||||
e) cmd_install ;;
|
e) cmd_install ;;
|
||||||
f) cmd_build all ;;
|
f) cmd_build all ;;
|
||||||
n) cmd_rebuild ;;
|
n) cmd_rebuild ;;
|
||||||
|
p)
|
||||||
|
echo -ne " Servicio Java a subir (gateway/service-bus): "
|
||||||
|
read -r jd_svc
|
||||||
|
echo -ne " ¿Build sin caché? (s/N): "
|
||||||
|
read -r jd_nc
|
||||||
|
if [[ -n "$jd_svc" ]]; then
|
||||||
|
if [[ "$jd_nc" =~ ^[sSyY] ]]; then cmd_jar_deploy "$jd_svc" --build --no-cache; else cmd_jar_deploy "$jd_svc" --build; fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
g) cmd_clone ;;
|
g) cmd_clone ;;
|
||||||
h) cmd_pull ;;
|
h) cmd_pull ;;
|
||||||
i)
|
i)
|
||||||
@@ -1330,6 +1413,7 @@ cmd_menu() {
|
|||||||
echo -e " ${WHITE}e${NC}) Compilar todo ${WHITE}h${NC}) Actualizar repos ${WHITE}j${NC}) Cambiar ambiente"
|
echo -e " ${WHITE}e${NC}) Compilar todo ${WHITE}h${NC}) Actualizar repos ${WHITE}j${NC}) Cambiar ambiente"
|
||||||
echo -e " ${WHITE}f${NC}) Build Docker ${WHITE}i${NC}) Actualizar servicio ${WHITE}k${NC}) Limpiar Docker"
|
echo -e " ${WHITE}f${NC}) Build Docker ${WHITE}i${NC}) Actualizar servicio ${WHITE}k${NC}) Limpiar Docker"
|
||||||
echo -e " ${WHITE}r${NC}) Build amd64 + push registry ${WHITE}t${NC}) Deploy en server (SSH)"
|
echo -e " ${WHITE}r${NC}) Build amd64 + push registry ${WHITE}t${NC}) Deploy en server (SSH)"
|
||||||
|
echo -e " ${WHITE}p${NC}) Subir JAR al server (jar-deploy: scp jar → build/libs → build+up remoto)"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " ${WHITE}?${NC}) Ayuda ${WHITE}q${NC}) Salir"
|
echo -e " ${WHITE}?${NC}) Ayuda ${WHITE}q${NC}) Salir"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -1846,7 +1930,10 @@ cmd_help() {
|
|||||||
echo -e " ${WHITE}image-pull${NC} [svc|all] [tag] Pull desde Gitea Registry"
|
echo -e " ${WHITE}image-pull${NC} [svc|all] [tag] Pull desde Gitea Registry"
|
||||||
echo -e " ${WHITE}image-deploy${NC} [svc|all] [tag] Pull + down + rm + up + health (server)"
|
echo -e " ${WHITE}image-deploy${NC} [svc|all] [tag] Pull + down + rm + up + health (server)"
|
||||||
echo -e " ${WHITE}image-build-amd64${NC} [svc|all] Build linux/amd64 + push al registry — sin Gradle"
|
echo -e " ${WHITE}image-build-amd64${NC} [svc|all] Build linux/amd64 + push al registry — sin Gradle"
|
||||||
echo -e " ${WHITE}server-deploy${NC} [svc|all] SCP + ejecutar deploy en NEWIB01-DEV via SSH"
|
echo -e " ${WHITE}server-deploy${NC} [svc|all] SCP + ejecutar deploy en NEWIB01-DEV via SSH (vía registry)"
|
||||||
|
echo -e " ${WHITE}jar-deploy${NC} <gateway|service-bus> [--build] [--no-cache]"
|
||||||
|
echo -e " Sube TU jar local al server (DEPLOY_SERVER) → build/libs → build+up remoto."
|
||||||
|
echo -e " Útil para .133 (no usa el registry de Gitea). Requiere ~/.bdt/config + sudo remoto."
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " ${O3}${BOLD}JAR pre-compilado (image-build / image-build-amd64):${NC}"
|
echo -e " ${O3}${BOLD}JAR pre-compilado (image-build / image-build-amd64):${NC}"
|
||||||
echo -e " Gradle NO corre. Copiá el JAR compilado ANTES de buildear:"
|
echo -e " Gradle NO corre. Copiá el JAR compilado ANTES de buildear:"
|
||||||
@@ -1886,6 +1973,7 @@ case "$cmd" in
|
|||||||
install) cmd_install "$@" ;;
|
install) cmd_install "$@" ;;
|
||||||
build) cmd_build "$@" ;;
|
build) cmd_build "$@" ;;
|
||||||
rebuild|rebuild-nc) cmd_rebuild "$@" ;;
|
rebuild|rebuild-nc) cmd_rebuild "$@" ;;
|
||||||
|
jar-deploy|jardeploy) cmd_jar_deploy "$@" ;;
|
||||||
up|start) cmd_up "$@" ;;
|
up|start) cmd_up "$@" ;;
|
||||||
down|stop) cmd_down "$@" ;;
|
down|stop) cmd_down "$@" ;;
|
||||||
restart) cmd_restart "$@" ;;
|
restart) cmd_restart "$@" ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user