Commit c8eb383d authored by guillecxb's avatar guillecxb
Browse files

new script for deploy

parent 37a8c51b
Loading
Loading
Loading
Loading

deploy.sh

0 → 100755
+56 −0
Original line number Diff line number Diff line
#!/bin/bash

set -e  # Detener la ejecución si ocurre un error

# Función para manejar errores
handle_error() {
    echo "Error en el script. Línea: $1"
    exit 1
}

# Capturar errores y llamar a la función handle_error
trap 'handle_error $LINENO' ERR

# Pedir al usuario el tag de las imágenes del backend y frontend
read -p "Introduce el tag de la imagen del backend (ej. v3.1.200): " BACKEND_TAG
read -p "Introduce el tag de la imagen del frontend (ej. v3.1.104): " FRONTEND_TAG

# Archivo values.yaml
VALUES_FILE="helm/backoffice/values.yaml"

# Verificar si el archivo values.yaml existe
if [ -f "$VALUES_FILE" ]; then
    echo "Actualizando el archivo $VALUES_FILE con los nuevos tags..."

    # Reemplazar el tag del backend comprobando el repository
    awk -v new_tag="$BACKEND_TAG" '
    $0 ~ /repository: public.ecr.aws\/o2v4a8t6\/opencapif\/backoffice-backend/ { found_backend=1 }
    found_backend && /tag:/ { sub(/"v3.1.[0-9]+"/, "\"" new_tag "\""); found_backend=0 }
    { print }
    ' "$VALUES_FILE" > "$VALUES_FILE.tmp" && mv "$VALUES_FILE.tmp" "$VALUES_FILE"

    # Reemplazar el tag del frontend comprobando el repository
    awk -v new_tag="$FRONTEND_TAG" '
    $0 ~ /repository: public.ecr.aws\/o2v4a8t6\/opencapif\/backoffice-frontend/ { found_frontend=1 }
    found_frontend && /tag:/ { sub(/"v3.1.[0-9]+"/, "\"" new_tag "\""); found_frontend=0 }
    { print }
    ' "$VALUES_FILE" > "$VALUES_FILE.tmp" && mv "$VALUES_FILE.tmp" "$VALUES_FILE"

    echo "Archivo $VALUES_FILE actualizado con los nuevos tags:"
    echo "Backend: $BACKEND_TAG"
    echo "Frontend: $FRONTEND_TAG"
else
    echo "Error: No se encontró el archivo $VALUES_FILE"
    exit 1
fi

# Ejecutar el comando Helm para actualizar la instalación
echo "Ejecutando helm upgrade..."
if helm upgrade --install -n backoffice backoffice helm/backoffice --create-namespace; then
    echo "Nuevas imágenes desplegadas correctamente:"
    echo "Backend: $BACKEND_TAG"
    echo "Frontend: $FRONTEND_TAG"
else
    echo "Error en el comando Helm."
    exit 1
fi