#!/bin/bash set -ex echo "========================================" echo "๐Ÿš€ INICIANDO DEPLOY LANGFUSE" echo "========================================" # ========================= # ๐Ÿ” CONFIG SECRETS (OCIDs) # ========================= echo "" echo "๐Ÿ” Etapa 1: Configurando OCIDs dos secrets..." export OCI_SECRET_OCI_SECRET="ocid1.vaultsecret.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export OCI_SECRET_OCI_ACCESS="ocid1.vaultsecret.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export OCI_SECRET_SALT="ocid1.vaultsecret.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export OCI_SECRET_ENCRYPTION="ocid1.vaultsecret.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export OCI_SECRET_NEXTAUTH="ocid1.vaultsecret.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export OCI_SECRET_CLICKHOUSE="ocid1.vaultsecret.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export OCI_SECRET_REDIS="ocid1.vaultsecret.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export OCI_SECRET_DB="ocid1.vaultsecret.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" export OCI_NAMESPACE="xxxxxxxxxxx" echo "โœ… OCIDs carregados" # ========================= # โš™๏ธ CONFIG OCI # ========================= echo "" echo "โš™๏ธ Etapa 2: Configuraรงรฃo OCI..." export OCI_PROFILE=DEFAULT export OCI_REGION=us-ashburn-1 echo "โœ”๏ธ Profile: $OCI_PROFILE" echo "โœ”๏ธ Region: $OCI_REGION" # ========================= # ๐Ÿ“ฆ REGISTRY # ========================= echo "" echo "๐Ÿ“ฆ Etapa 3: Configurando registry..." export REGION="iad" export TENANCY_NAMESPACE=${OCI_NAMESPACE} export REGISTRY="${REGION}.ocir.io/${TENANCY_NAMESPACE}" echo "โœ”๏ธ Registry: $REGISTRY" # ========================= # ๐Ÿงฉ DEPLOY CONFIG # ========================= echo "" echo "๐Ÿงฉ Etapa 4: Configuraรงรฃo do deploy..." export APP_NAME="langfuse" export K8S_NAMESPACE="langfuse" export IMAGE_REPOSITORY="${REGISTRY}" export IMAGE_TAG="3.1.0" export CLICKHOUSE_TAG="23.8" export REDIS_TAG="7.2" export POSTGRES_TAG="15" echo "โœ”๏ธ App: $APP_NAME" echo "โœ”๏ธ Namespace: $K8S_NAMESPACE" echo "โœ”๏ธ Image: $IMAGE_REPOSITORY:$IMAGE_TAG" # ========================= # ๐ŸŒ URL # ========================= echo "" echo "๐ŸŒ Etapa 5: URL..." export NEXTAUTH_URL="https://langfuse.seudominio.com" echo "โœ”๏ธ URL: $NEXTAUTH_URL" # ========================= # ๐Ÿ” FUNร‡รƒO SECRET # ========================= get_secret() { local secret_ocid=$1 echo "๐Ÿ”Ž Buscando secret: $secret_ocid" >&2 oci secrets secret-bundle get \ --secret-id "$secret_ocid" \ --query 'data."secret-bundle-content".content' \ --raw-output | base64 --decode } # ========================= # ๐Ÿ”ฅ CARREGAR SECRETS # ========================= echo "" echo "๐Ÿ” Etapa 6: Carregando secrets do OCI..." export DB_PASSWORD=$(get_secret "$OCI_SECRET_DB") export DATABASE_URL="postgresql://langfuse:${DB_PASSWORD}@${APP_NAME}-db:5432/langfuse" echo "โœ”๏ธ DATABASE_URL carregado" export REDIS_AUTH=$(get_secret "$OCI_SECRET_REDIS") echo "โœ”๏ธ REDIS_AUTH carregado" export CLICKHOUSE_PASSWORD=$(get_secret "$OCI_SECRET_CLICKHOUSE") echo "โœ”๏ธ CLICKHOUSE_PASSWORD carregado" export NEXTAUTH_SECRET=$(get_secret "$OCI_SECRET_NEXTAUTH") echo "โœ”๏ธ NEXTAUTH_SECRET carregado" export ENCRYPTION_KEY=$(get_secret "$OCI_SECRET_ENCRYPTION" | tr -d '\r\n') # Corrige automaticamente caso a key esteja invรกlida if ! [[ "$ENCRYPTION_KEY" =~ ^[a-fA-F0-9]{64}$ ]]; then echo "โš ๏ธ ENCRYPTION_KEY invรกlida no Vault. Gerando automaticamente..." ENCRYPTION_KEY=$(openssl rand -hex 32) echo "๐Ÿ” Nova ENCRYPTION_KEY:" echo "$ENCRYPTION_KEY" fi echo "โœ”๏ธ ENCRYPTION_KEY carregado" export SALT=$(get_secret "$OCI_SECRET_SALT") echo "โœ”๏ธ SALT carregado" # ========================= # โšก REDIS # ========================= echo "" echo "โšก Etapa 7: Config Redis..." export REDIS_HOST="${APP_NAME}-redis" export REDIS_PORT="6379" echo "โœ”๏ธ Redis: $REDIS_HOST:$REDIS_PORT" # ========================= # ๐Ÿ“Š CLICKHOUSE # ========================= echo "" echo "๐Ÿ“Š Etapa 8: Config ClickHouse..." export CLICKHOUSE_URL="http://${APP_NAME}-clickhouse:8123" export CLICKHOUSE_USER="default" export CLICKHOUSE_MIGRATION_URL="clickhouse://${APP_NAME}-clickhouse:9000" export CLICKHOUSE_CLUSTER_ENABLED="false" echo "โœ”๏ธ ClickHouse: $CLICKHOUSE_URL" # ========================= # โ˜๏ธ OBJECT STORAGE # ========================= echo "" echo "โ˜๏ธ Etapa 9: Config OCI Object Storage..." export LANGFUSE_S3_EVENT_UPLOAD_BUCKET="langfuse-events" export LANGFUSE_S3_EVENT_UPLOAD_REGION="${OCI_REGION}" export LANGFUSE_S3_EVENT_UPLOAD_ENDPOINT="https://${OCI_NAMESPACE}.compat.objectstorage.${OCI_REGION}.oraclecloud.com" export LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE="true" echo "โœ”๏ธ Bucket eventos: $LANGFUSE_S3_EVENT_UPLOAD_BUCKET" # ========================= # ๐Ÿš€ DEPLOY # ========================= echo "" echo "๐Ÿš€ Etapa 10: Aplicando Kubernetes..." echo "๐Ÿ“„ Preview YAML (primeiras linhas):" envsubst < langfuse_dest.yaml | head -n 20 echo "" echo "๐Ÿ“ฆ Aplicando..." echo "" echo "๐Ÿ“„ Gerando YAML final..." envsubst < langfuse_dest.yaml > final.yaml echo "" echo "๐Ÿ“„ Preview:" head -n 20 final.yaml echo "" echo "๐Ÿ” Validando YAML..." kubectl apply --dry-run=client -f final.yaml echo "" echo "๐Ÿ“ฆ Aplicando..." # kubectl apply -f final.yaml echo "" echo "========================================" echo "๐ŸŽฏ DEPLOY FINALIZADO COM SUCESSO!" echo "========================================"