diff --git a/deploy/azure/06-AZURE-DEPLOY-SERVICES.md b/deploy/azure/06-AZURE-DEPLOY-SERVICES.md index 949ad1b..0de8798 100644 --- a/deploy/azure/06-AZURE-DEPLOY-SERVICES.md +++ b/deploy/azure/06-AZURE-DEPLOY-SERVICES.md @@ -398,6 +398,67 @@ exit ## Troubleshooting +### API Gateway Service no se crea + +**Síntoma:** El pod del API Gateway está Running pero no aparece el Service en `kubectl get svc -n fuel-system` + +**Causa:** Error silencioso durante el apply de Helm, generalmente por timeout esperando la IP del LoadBalancer + +**Solución:** + +```bash +# 1. Verificar si el Service existe +kubectl get svc fuel-system-api-gateway -n fuel-system + +# Si no existe, crearlo manualmente: +kubectl apply -f - </dev/null || true + +# Para Gmail con App Password: +kubectl create secret generic fuel-system-smtp \ + --from-literal=host='smtp.gmail.com' \ + --from-literal=port='587' \ + --from-literal=user='tu-email@gmail.com' \ + --from-literal=password='tu-app-password-de-16-caracteres' \ + --namespace=fuel-system + +# NOTA: Para Gmail necesitas generar una App Password en: +# https://myaccount.google.com/apppasswords +# (requiere tener 2FA habilitado) + +# 3. Verificar las variables de entorno en el pod +kubectl exec -it deployment/fuel-system-email-service -n fuel-system -- sh +# Dentro del pod: +env | grep SMTP +# Debe mostrar: SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS +exit + +# 4. Reiniciar el email-service para que tome las nuevas credenciales +kubectl rollout restart deployment/fuel-system-email-service -n fuel-system + +# 5. Ver logs para verificar +kubectl logs -f deployment/fuel-system-email-service -n fuel-system + +# 6. Probar recuperación de contraseña +INGRESS_IP=$(kubectl get svc ingress-nginx-controller -n ingress-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}') +curl -X POST http://$INGRESS_IP/auth/recover-password \ + -H "Content-Type: application/json" \ + -d '{"email":"test@example.com"}' +``` + +**Prevención:** Asegúrate de crear el secret SMTP **antes** de desplegar con Helm, o usa valores correctos en `values-azure.yaml` para que Helm lo cree automáticamente. + ### ImagePullBackOff ```bash diff --git a/deploy/helm/fuel-system/templates/auth-service.yaml b/deploy/helm/fuel-system/templates/auth-service.yaml index 627b977..cc729ef 100644 --- a/deploy/helm/fuel-system/templates/auth-service.yaml +++ b/deploy/helm/fuel-system/templates/auth-service.yaml @@ -21,32 +21,49 @@ spec: app.kubernetes.io/component: auth-service spec: {{- include "fuel-system.imagePullSecrets" . | nindent 6 }} - # Init Container para esperar a que la base de datos esté disponible - # Auth-service usa TypeORM con synchronize:true, no necesita SQL manual initContainers: - - name: wait-for-db + - name: create-tables image: postgres:15-alpine command: - sh - -c - | set -e - echo "🔄 Waiting for auth database to be ready..." + echo "[Auth Init] Waiting for auth database to be ready..." {{- $sslMode := .Values.postgresql.external.sslMode | default "disable" }} + + {{- if eq $sslMode "require" }} + CONN_STRING="postgresql://${AUTH_DB_USER}:${AUTH_DB_PASS}@${AUTH_DB_HOST}:${AUTH_DB_PORT}/${AUTH_DB_NAME}?sslmode=require" + {{- else }} + CONN_STRING="postgresql://${AUTH_DB_USER}:${AUTH_DB_PASS}@${AUTH_DB_HOST}:${AUTH_DB_PORT}/${AUTH_DB_NAME}?sslmode=disable" + {{- end }} + for i in $(seq 1 30); do - {{- if eq $sslMode "require" }} - if PGPASSWORD="${AUTH_DB_PASS}" psql "sslmode=require host=${AUTH_DB_HOST} port=${AUTH_DB_PORT} user=${AUTH_DB_USER} dbname=${AUTH_DB_NAME}" -c '\q' 2>/dev/null; then - {{- else }} - if PGPASSWORD="${AUTH_DB_PASS}" psql -h "${AUTH_DB_HOST}" -p "${AUTH_DB_PORT}" -U "${AUTH_DB_USER}" -d "${AUTH_DB_NAME}" -c '\q' 2>/dev/null; then - {{- end }} - echo "✅ Auth database is ready!" - exit 0 + if psql "${CONN_STRING}" -c '\q' 2>/dev/null; then + echo "[Auth Init] Database connection successful" + break fi - echo "⏳ Waiting for auth database... ($i/30)" + echo "[Auth Init] Waiting for database... (attempt $i/30)" sleep 2 done - echo "❌ ERROR: Auth database no disponible después de 60 segundos" - exit 1 + + echo "[Auth Init] Creating verification_tokens table..." + psql "${CONN_STRING}" <<'EOF' + CREATE TABLE IF NOT EXISTS verification_tokens ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + "userId" INTEGER NOT NULL, + "tokenHash" VARCHAR(255) NOT NULL, + "expiresAt" TIMESTAMP NOT NULL, + used BOOLEAN NOT NULL DEFAULT false, + "createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + ); + + CREATE INDEX IF NOT EXISTS idx_verification_tokens_token ON verification_tokens("tokenHash"); + CREATE INDEX IF NOT EXISTS idx_verification_tokens_user ON verification_tokens("userId"); + CREATE INDEX IF NOT EXISTS idx_verification_tokens_expires ON verification_tokens("expiresAt"); + EOF + + echo "[Auth Init] Tables created successfully" env: - name: AUTH_DB_HOST {{- if .Values.postgresql.external.hosts }} @@ -264,6 +281,15 @@ spec: name: {{ include "fuel-system.fullname" . }}-config key: POSTGRESQL_SSL_REJECT_UNAUTHORIZED + # ========== CRITICAL: gRPC Server Configuration ========== + # These variables prevent SASL authentication issues + - name: GRPC_VERBOSITY + value: "ERROR" + - name: GRPC_TRACE + value: "" + - name: GRPC_ENABLE_FORK_SUPPORT + value: "1" + resources: {{- toYaml .Values.authService.resources | nindent 10 }} --- diff --git a/deploy/helm/fuel-system/templates/microservices.yaml b/deploy/helm/fuel-system/templates/microservices.yaml index ab921a5..de384df 100644 --- a/deploy/helm/fuel-system/templates/microservices.yaml +++ b/deploy/helm/fuel-system/templates/microservices.yaml @@ -716,11 +716,16 @@ spec: secretKeyRef: name: {{ include "fuel-system.fullname" $ }}-smtp key: user - - name: SMTP_PASSWORD + - name: SMTP_PASS valueFrom: secretKeyRef: name: {{ include "fuel-system.fullname" $ }}-smtp key: password + - name: FRONTEND_URL + valueFrom: + configMapKeyRef: + name: {{ include "fuel-system.fullname" $ }}-config + key: FRONTEND_URL {{- end }} resources: {{- toYaml $config.config.resources | nindent 10 }} diff --git a/deploy/helm/fuel-system/values.yaml b/deploy/helm/fuel-system/values.yaml index 98fb617..315e804 100644 --- a/deploy/helm/fuel-system/values.yaml +++ b/deploy/helm/fuel-system/values.yaml @@ -155,6 +155,7 @@ authService: GRPC_PORT: 50052 AUTH_GRPC_PORT: 50052 DB_NAME: auth_db + DB_SYNCHRONIZE: "false" database: enabled: false resources: diff --git a/services/api-gateway/Dockerfile b/services/api-gateway/Dockerfile index 65de938..d3f05db 100644 --- a/services/api-gateway/Dockerfile +++ b/services/api-gateway/Dockerfile @@ -23,9 +23,11 @@ COPY protos/*.proto ./protos/ FROM node:20-alpine WORKDIR /app -# Instalar curl para healthchecks -RUN apk add --no-cache curl +# Instalar curl para healthchecks y tzdata para timezone +RUN apk add --no-cache curl tzdata +# Configurar timezone +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json diff --git a/services/auth-svc/Dockerfile b/services/auth-svc/Dockerfile index ac9f218..b926e23 100644 --- a/services/auth-svc/Dockerfile +++ b/services/auth-svc/Dockerfile @@ -35,7 +35,11 @@ COPY protos ./protos FROM node:20-alpine AS runtime WORKDIR /app +# Instalar tzdata para timezone +RUN apk add --no-cache tzdata + # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json diff --git a/services/driver-ms/Dockerfile b/services/driver-ms/Dockerfile index f7e8b80..f7fcb43 100644 --- a/services/driver-ms/Dockerfile +++ b/services/driver-ms/Dockerfile @@ -39,10 +39,11 @@ COPY protos/users.proto ./protos/users.proto FROM node:20-alpine AS runtime WORKDIR /app -# Instalar postgresql-client para ejecutar seeds -RUN apk add --no-cache postgresql-client +# Instalar postgresql-client para ejecutar seeds y tzdata para timezone +RUN apk add --no-cache postgresql-client tzdata # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json diff --git a/services/email-svc/Dockerfile b/services/email-svc/Dockerfile index 7f1682c..681cafc 100644 --- a/services/email-svc/Dockerfile +++ b/services/email-svc/Dockerfile @@ -35,7 +35,11 @@ COPY protos/email.proto ./protos/email.proto FROM node:20-alpine AS runtime WORKDIR /app +# Instalar tzdata para timezone +RUN apk add --no-cache tzdata + # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json diff --git a/services/fuel-svc/Dockerfile b/services/fuel-svc/Dockerfile index 972042f..e227c77 100644 --- a/services/fuel-svc/Dockerfile +++ b/services/fuel-svc/Dockerfile @@ -35,7 +35,11 @@ COPY protos ./protos FROM node:20-alpine AS runtime WORKDIR /app +# Instalar tzdata para timezone +RUN apk add --no-cache tzdata + # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json diff --git a/services/hello-svc/Dockerfile b/services/hello-svc/Dockerfile index 3ec4801..d495310 100644 --- a/services/hello-svc/Dockerfile +++ b/services/hello-svc/Dockerfile @@ -28,7 +28,11 @@ RUN npm run build FROM node:20-alpine AS runtime WORKDIR /app +# Instalar tzdata para timezone +RUN apk add --no-cache tzdata + # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar dependencias de producción diff --git a/services/logger-svc/Dockerfile b/services/logger-svc/Dockerfile index 1a16069..cf964a3 100644 --- a/services/logger-svc/Dockerfile +++ b/services/logger-svc/Dockerfile @@ -31,10 +31,11 @@ RUN npm run build FROM node:20-alpine AS runtime WORKDIR /app -# Instalar curl para healthchecks -RUN apk add --no-cache curl +# Instalar curl para healthchecks y tzdata para timezone +RUN apk add --no-cache curl tzdata # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar dependencias de producción diff --git a/services/publisher-rabbit-srv/Dockerfile b/services/publisher-rabbit-srv/Dockerfile index b48a6d4..9358a2a 100644 --- a/services/publisher-rabbit-srv/Dockerfile +++ b/services/publisher-rabbit-srv/Dockerfile @@ -23,7 +23,11 @@ COPY protos/logs.proto ./protos/logs.proto FROM node:20-alpine AS runtime WORKDIR /app +# Instalar tzdata para timezone +RUN apk add --no-cache tzdata + # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json diff --git a/services/routes-srv/Dockerfile b/services/routes-srv/Dockerfile index da9c5fd..34f3713 100644 --- a/services/routes-srv/Dockerfile +++ b/services/routes-srv/Dockerfile @@ -38,10 +38,11 @@ COPY protos ./protos FROM node:20-alpine AS runtime WORKDIR /app -# Instalar postgresql-client para ejecutar init.sql -RUN apk add --no-cache postgresql-client +# Instalar postgresql-client para ejecutar init.sql y tzdata para timezone +RUN apk add --no-cache postgresql-client tzdata # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json diff --git a/services/users-srv/Dockerfile b/services/users-srv/Dockerfile index 97ae709..1ed6e93 100644 --- a/services/users-srv/Dockerfile +++ b/services/users-srv/Dockerfile @@ -60,10 +60,11 @@ COPY protos/users.proto ./protos/users.proto FROM node:20-alpine AS runtime WORKDIR /app -# Instalar OpenSSL para Prisma -RUN apk add --no-cache openssl +# Instalar OpenSSL para Prisma y tzdata para timezone +RUN apk add --no-cache openssl tzdata # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json diff --git a/services/vehicles-svc/Dockerfile b/services/vehicles-svc/Dockerfile index 9d6f844..3abe2ca 100644 --- a/services/vehicles-svc/Dockerfile +++ b/services/vehicles-svc/Dockerfile @@ -62,10 +62,11 @@ COPY protos ./protos FROM node:20-alpine AS runtime WORKDIR /app -# Instalar OpenSSL para Prisma -RUN apk add --no-cache openssl +# Instalar OpenSSL para Prisma y tzdata para timezone +RUN apk add --no-cache openssl tzdata # Variables de entorno +ENV TZ=America/Guayaquil ENV NODE_ENV=production # Copiar package.json