128 lines
4.4 KiB
Bash
Executable File
128 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Colores para output
|
|
GREEN='\033[0;32m'
|
|
BLUE='\033[0;34m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${BLUE}==============================================${NC}"
|
|
echo -e "${BLUE} ALICANTE CORE UPGRADER: V3.0/3.1 -> V3.2 ${NC}"
|
|
echo -e "${BLUE}==============================================${NC}"
|
|
|
|
# 1. Verificaciones previas
|
|
REPO_DIR=$(pwd)
|
|
if [ ! -f "$REPO_DIR/group_vars/all.yml" ]; then
|
|
echo -e "${RED}[ERROR] No se encuentra group_vars/all.yml. Asegúrate de ejecutar esto en la raíz del repo 'alicante-infra'.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${YELLOW}[1/5] Creando backups de seguridad...${NC}"
|
|
cp group_vars/all.yml group_vars/all.yml.bak.v3
|
|
cp roles/core/templates/docs-compose.j2 roles/core/templates/docs-compose.j2.bak.v3
|
|
if [ -f "deployment-checklist.sh" ]; then cp deployment-checklist.sh deployment-checklist.sh.bak.v3; fi
|
|
echo -e "${GREEN}Backups creados con extensión .bak.v3${NC}"
|
|
|
|
# 2. Actualizar Variables Globales
|
|
echo -e "${YELLOW}[2/5] Inyectando configuración en group_vars/all.yml...${NC}"
|
|
|
|
# Verificamos si ya existe para no duplicar
|
|
if grep -q "carbone_port" group_vars/all.yml; then
|
|
echo -e " Variable carbone_port ya existe. Saltando inyección."
|
|
else
|
|
cat <<EOT >> group_vars/all.yml
|
|
|
|
# --- ALICANTE CORE V3.2 CONFIGURATION ---
|
|
# Carbone (Stack Docs)
|
|
carbone_port: 4000
|
|
carbone_version: "4"
|
|
carbone_image: "carbone/carbone"
|
|
EOT
|
|
echo -e "${GREEN} Variables de Carbone añadidas.${NC}"
|
|
fi
|
|
|
|
# 3. Actualizar Template docs-compose.j2
|
|
echo -e "${YELLOW}[3/5] Parcheando roles/core/templates/docs-compose.j2...${NC}"
|
|
|
|
TEMPLATE_FILE="roles/core/templates/docs-compose.j2"
|
|
|
|
# Definimos el bloque del servicio Carbone
|
|
# NOTA: Usamos indentación de 2 espacios asumiendo estructura estándar docker-compose
|
|
read -r -d '' CARBONE_SERVICE << EOM
|
|
carbone:
|
|
image: "{{ carbone_image }}:{{ carbone_version }}"
|
|
container_name: carbone
|
|
restart: unless-stopped
|
|
ports:
|
|
- "{{ carbone_port }}:4000"
|
|
environment:
|
|
TZ: "{{ timezone }}"
|
|
volumes:
|
|
- carbone_templates:/app/templates
|
|
- carbone_output:/app/output
|
|
networks:
|
|
- docs_network
|
|
healthcheck:
|
|
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:4000/health"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 40s
|
|
|
|
EOM
|
|
|
|
# Definimos los volúmenes
|
|
read -r -d '' CARBONE_VOLUMES << EOM
|
|
carbone_templates:
|
|
carbone_output:
|
|
EOM
|
|
|
|
# Inserción inteligente usando sed
|
|
# 1. Insertar servicio antes de la definición global de 'volumes:'
|
|
if grep -q "container_name: carbone" "$TEMPLATE_FILE"; then
|
|
echo -e " Servicio Carbone ya existe en el template. Saltando."
|
|
else
|
|
# Busca la línea que empieza exactamente con 'volumes:' e inserta el servicio antes
|
|
sed -i "/^volumes:/i \\$CARBONE_SERVICE" "$TEMPLATE_FILE"
|
|
|
|
# Busca la línea que empieza con 'volumes:' e inserta los volúmenes justo después
|
|
sed -i "/^volumes:/a \\$CARBONE_VOLUMES" "$TEMPLATE_FILE"
|
|
|
|
echo -e "${GREEN} Servicio y volúmenes inyectados en el template.${NC}"
|
|
fi
|
|
|
|
# 4. Actualizar Checklist y Docs
|
|
echo -e "${YELLOW}[4/5] Actualizando scripts de mantenimiento...${NC}"
|
|
|
|
if [ -f "deployment-checklist.sh" ]; then
|
|
if ! grep -q "Carbone" "deployment-checklist.sh"; then
|
|
# Insertar verificación antes de la función main o al final
|
|
sed -i '/# Check Management Stack/i \ verify_service "Carbone" "4000"' deployment-checklist.sh
|
|
echo -e "${GREEN} Checklist actualizado.${NC}"
|
|
fi
|
|
fi
|
|
|
|
# Renombrar documentación principal si existe
|
|
if [ -f "ALICANTE_CORE_V3.1_COMPLETE.md" ]; then
|
|
mv ALICANTE_CORE_V3.1_COMPLETE.md ALICANTE_CORE_V3.2_COMPLETE.md
|
|
echo -e "${GREEN} Documentación renombrada a V3.2.${NC}"
|
|
fi
|
|
|
|
# 5. Git Operations
|
|
echo -e "${YELLOW}[5/5] Preparando Git...${NC}"
|
|
echo -e "${BLUE}------------------------------------------------${NC}"
|
|
echo -e "El código ha sido actualizado localmente."
|
|
echo -e "Para aplicar los cambios, ejecuta los siguientes pasos:"
|
|
echo -e ""
|
|
echo -e "1. Revisa los cambios:"
|
|
echo -e " ${YELLOW}git diff${NC}"
|
|
echo -e ""
|
|
echo -e "2. Sube los cambios al repo:"
|
|
echo -e " ${YELLOW}git add .${NC}"
|
|
echo -e " ${YELLOW}git commit -m \"Upgrade: Alicante Core V3.2 (Added Carbone)\"${NC}"
|
|
echo -e " ${YELLOW}git push origin main${NC}"
|
|
echo -e ""
|
|
echo -e "3. Ve a Semaphore UI y ejecuta el Deploy."
|
|
echo -e "${BLUE}------------------------------------------------${NC}"
|