# Passo a Passo: Deploy mfe-user para OCI ## Visão Geral Este guia mostra como fazer o deploy do **mfe-user** (Micro Frontend) para a OCI usando: - **Object Storage** para arquivos estáticos - **API Gateway** para servir o MFE - **OCI CLI** via Azure DevOps --- ## Estado Atual da Infraestrutura (18/02/2026) | Recurso | Status | Ação Necessária | |---------|--------|-----------------| | VCN (Dev) | ✅ Existe | Nenhuma | | Subnet (sbn-lb-1) | ✅ Existe | Nenhuma | | API Gateway | ⏸️ Pausado | Não será usado por enquanto | | Bucket mfe-user-dev | ✅ Criado | Pipeline cria automaticamente | | PAR mfe-user-dev | ✅ Criado | Pipeline cria automaticamente | ### Buckets OCI Criados | Bucket | Ambiente | MFE | Status | |--------|----------|-----|--------| | mfe-user-dev | Dev | mfe-user | ✅ Criado e funcionando | --- ## Passo 1: Configurar Variable Group No Azure DevOps: **Project Settings** → **Pipelines** → **Library** → **Variable Groups** ### Variáveis necessárias no `oci-terraform` | Variável | Tipo | Valor | |----------|------|-------| | `OCI_TENANCY_OCID` | Secret | OCID da tenancy | | `OCI_USER_OCID` | Secret | OCID do usuário | | `OCI_FINGERPRINT` | Secret | Fingerprint da chave | | `OCI_PRIVATE_KEY_B64` | Secret | Chave privada (base64) | | `OCI_REGION` | 普通 | `sa-saopaulo-1` | | `COMPARTMENT_PARENT_OCID` | Secret | `ocid1.compartment.oc1..aaaaaaaa76x3nykkjwvctpr6px34dysu3pbg7p62h2r65fegt7fvbrioll3a` | | `OCI_SUBNET_OCID` | Secret | `ocid1.subnet.oc1.sa-saopaulo-1.aaaaaaaa2ezw57uocis6s2eioypdsnt2p4pwm4fwnjz5jdaqigrm6jaqexeq` | --- ## Passo 2: Executar Pipeline A pipeline cria automaticamente: 1. Bucket `mfe-user-dev` no Object Storage 2. Upload dos arquivos do build 3. Pre-Authenticated Request (PAR) 4. API Gateway com deployment ### Via Azure DevOps 1. Vá no repositório `mfe-user` 2. Faça push para branch `devops` 3. Execute a pipeline `azure-pipelines.yml` 4. Parâmetro `cloudProvider`: `oci` ### Fluxo da Pipeline ``` ┌─────────────┐ │ BUILD │ → npm ci + npm run build:dev └─────────────┘ │ ▼ ┌─────────────┐ │ UPLOAD │ → Upload para OCI Object Storage │ (OCI) │ Bucket: mfe--dev └─────────────┘ │ ▼ ┌─────────────┐ │ CREATEPAR │ → Cria Pre-Authenticated Request └─────────────┘ ``` **Nota**: O estágio DeployToAPIGateway foi removido. Não haverá atividade do API Gateway por enquanto. --- ## Passo 3: Obter URL do API Gateway ```bash oci api-gateway gateway list \ --compartment-id "ocid1.compartment.oc1..aaaaaaaa76x3nykkjwvctpr6px34dysu3pbg7p62h2r65fegt7fvbrioll3a" ``` URL: `https://.apigateway.sa-saopaulo-1.oci.customer-oci.com` --- ## Passo 4: Testar Acesse no navegador: ``` https://.apigateway.sa-saopaulo-1.oci.customer-oci.com/ ``` --- ## Ambientes | Ambiente | Bucket | Subnet | |----------|--------|--------| | Dev | `mfe-user-dev` | sbn-lb-1 | | HML | `mfe-user-hml` | (definir) | | PROD | `mfe-user-prod` | (definir) | --- ## Troubleshooting ### O que acontece se disparar a pipeline sem configuração? | Estágio | Se faltar configuração | Resultado | |---------|------------------------|-----------| | BUILD | - | ✅ Sempre funciona | | UPLOADTOOCI | - | ✅ Bucket criado automaticamente | | CREATEPAR | - | ✅ PAR criado automaticamente | | DEPLOYTOAPIGW | `OCI_SUBNET_OCID` não configurado | ❌ ERRO | | DEPLOYTOAPIGW | Subnet não existe | ❌ ERRO | ### Recursos Criados Automaticamente pela Pipeline | Recurso | Criado Automaticamente? | |---------|------------------------| | Bucket `mfe-user-dev` | ✅ Sim | | PAR `mfe-user-dev-par` | ✅ Sim | | API Gateway `mfe-user-gateway` | ✅ Sim (se subnet existir) | | Deployment `mfe-user-deployment` | ✅ Sim | ### Recursos Obrigatórios (devem existir antes) | Recurso | Status Dev | |---------|------------| | VCN | ✅ Já existe | | Subnet (sbn-lb-1) | ✅ Já existe | | `OCI_SUBNET_OCID` no Variable Group | ❌ Precisa adicionar | ### Cenário: Disparar sem `OCI_SUBNET_OCID` ``` BUILD → ✅ Sucesso UPLOADTOOCI → ✅ Sucesso (bucket criado) CREATEPAR → ✅ Sucesso (PAR criado) DEPLOYTOAPIGW → ❌ ERRO: subnet não encontrada ``` **Resultado**: Bucket e PAR criados, mas API Gateway falha. **Solução**: Adicionar `OCI_SUBNET_OCID` e reexecutar a pipeline. ### Problemas Comuns | Problema | Causa | Solução | |----------|-------|---------| | Pipeline falha no API Gateway | `OCI_SUBNET_OCID` não configurada | Adicionar no Variable Group | | 403 Forbidden | PAR expirou | Executar pipeline novamente | | Arquivos não carregam (404) | Rotas incorretas | Verificar rota `/{req.*}` | --- ## Comandos Úteis ```bash # Listar buckets oci os bucket list --compartment-id # Listar objetos no bucket oci os object list --namespace-name "grbb7qzeuoag" --bucket-name "mfe-user-dev" # Listar API Gateways oci api-gateway gateway list --compartment-id # Ver deployment oci api-gateway deployment get --deployment-id # Deletar PAR antigo oci os preauth-request delete --namespace-name "grbb7qzeuoag" --bucket-name "mfe-user-dev" --par-id ``` --- ## Referências - [OCI-MFE-TASKS.md](./OCI-MFE-TASKS.md) - [OCI-API-GATEWAY.md](./OCI-API-GATEWAY.md) - [Oracle Documentation](https://docs.oracle.com/en/learn/oci-api-gateway-web-hosting/index.html)