364 lines
7.9 KiB
Markdown
364 lines
7.9 KiB
Markdown
# CarneiroTech - Deployment Guide
|
|
|
|
## 🚀 Deploy para Produção (OCI)
|
|
|
|
O site CarneiroTech está hospedado no servidor OCI (Oracle Cloud Infrastructure) com IP final **218**.
|
|
|
|
### Arquitetura
|
|
|
|
```
|
|
Internet
|
|
↓
|
|
Nginx (Port 80/443)
|
|
↓
|
|
Docker Container (Port 5008)
|
|
↓
|
|
ASP.NET Core MVC App
|
|
```
|
|
|
|
---
|
|
|
|
## 📋 Informações do Servidor
|
|
|
|
- **Servidor**: `ubuntu@129.146.116.218`
|
|
- **Diretório**: `/home/ubuntu/apps/carneirotech`
|
|
- **Container**: `carneirotech-web`
|
|
- **Porta Interna**: `5008`
|
|
- **Domínio**: `carneirotech.com`
|
|
- **SSL**: Let's Encrypt (auto-renovação configurada)
|
|
|
|
---
|
|
|
|
## 🔧 Como Fazer Deploy
|
|
|
|
### Opção 1: Deploy Automático (Recomendado)
|
|
|
|
Execute o script de deploy da sua máquina local:
|
|
|
|
```bash
|
|
cd /mnt/c/Users/ricar/Nextcloud/CarneiroTech/Site/aspnet/CarneiroTech
|
|
./deploy-to-oci.sh
|
|
```
|
|
|
|
O script irá:
|
|
1. ✅ Criar pacote compactado excluindo bin/obj
|
|
2. ✅ Transferir para servidor via SCP
|
|
3. ✅ Extrair arquivos
|
|
4. ✅ Fazer backup da imagem anterior
|
|
5. ✅ Fazer build da nova imagem
|
|
6. ✅ Parar container antigo
|
|
7. ✅ Subir container novo
|
|
8. ✅ Verificar health check
|
|
9. ✅ Limpar imagens antigas (mantém últimas 3)
|
|
|
|
**Rollback automático:** Se o health check falhar, o script restaura automaticamente a versão anterior.
|
|
|
|
---
|
|
|
|
### Opção 2: Deploy Manual
|
|
|
|
1. Conectar no servidor:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218
|
|
cd ~/apps/carneirotech
|
|
```
|
|
|
|
2. Transferir arquivos alterados (da sua máquina):
|
|
```bash
|
|
scp arquivo.cs ubuntu@129.146.116.218:~/apps/carneirotech/Controllers/
|
|
```
|
|
|
|
3. No servidor, fazer rebuild e restart:
|
|
```bash
|
|
./deploy.sh
|
|
```
|
|
|
|
---
|
|
|
|
## 🔍 Comandos Úteis
|
|
|
|
### Ver logs do container
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker logs carneirotech-web --tail=50 -f"
|
|
```
|
|
|
|
### Verificar status
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker ps --filter name=carneirotech"
|
|
```
|
|
|
|
### Entrar no container
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker exec -it carneirotech-web bash"
|
|
```
|
|
|
|
### Reiniciar container
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "cd ~/apps/carneirotech && docker compose restart"
|
|
```
|
|
|
|
### Ver logs do Nginx
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo tail -f /var/log/nginx/access.log"
|
|
ssh ubuntu@129.146.116.218 "sudo tail -f /var/log/nginx/error.log"
|
|
```
|
|
|
|
### Testar Nginx config
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo nginx -t"
|
|
```
|
|
|
|
### Recarregar Nginx
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo systemctl reload nginx"
|
|
```
|
|
|
|
---
|
|
|
|
## 📁 Estrutura de Arquivos no Servidor
|
|
|
|
```
|
|
/home/ubuntu/apps/carneirotech/
|
|
├── Content/ # Markdown files dos cases
|
|
├── Controllers/ # MVC Controllers
|
|
├── Models/ # Models
|
|
├── Services/ # Services (CaseService)
|
|
├── Views/ # Razor Views
|
|
├── wwwroot/ # Static files (CSS, JS, images)
|
|
├── Dockerfile # Docker build instructions (ARM64)
|
|
├── docker-compose.yml # Docker Compose config
|
|
├── deploy.sh # Deploy script (no servidor)
|
|
└── CarneiroTech.csproj # Project file
|
|
|
|
/etc/nginx/sites-available/
|
|
└── carneirotech.com.conf # Nginx proxy config
|
|
|
|
/etc/letsencrypt/live/carneirotech.com/
|
|
├── fullchain.pem # SSL certificate
|
|
└── privkey.pem # SSL private key
|
|
```
|
|
|
|
---
|
|
|
|
## 🔐 SSL / HTTPS
|
|
|
|
O certificado SSL é gerenciado automaticamente pelo **Let's Encrypt** via Certbot.
|
|
|
|
### Renovação Automática
|
|
|
|
O Certbot está configurado para renovar automaticamente. Verifique o status:
|
|
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo certbot certificates"
|
|
```
|
|
|
|
### Renovar Manualmente (se necessário)
|
|
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo certbot renew"
|
|
```
|
|
|
|
### Adicionar www.carneirotech.com
|
|
|
|
Quando você adicionar o registro DNS para `www.carneirotech.com`:
|
|
|
|
1. Adicionar ao Namecheap (A record apontando para 129.146.116.218)
|
|
2. Atualizar certificado SSL:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo certbot certonly --nginx -d carneirotech.com -d www.carneirotech.com --expand"
|
|
```
|
|
|
|
3. Atualizar nginx config:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo nano /etc/nginx/sites-available/carneirotech.com.conf"
|
|
```
|
|
Adicionar `www.carneirotech.com` no `server_name` de ambos os blocos server.
|
|
|
|
4. Recarregar nginx:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo nginx -t && sudo systemctl reload nginx"
|
|
```
|
|
|
|
---
|
|
|
|
## 🧹 Manutenção
|
|
|
|
### Limpar imagens Docker antigas
|
|
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker image prune -a"
|
|
```
|
|
|
|
### Limpar containers parados
|
|
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker container prune"
|
|
```
|
|
|
|
### Ver uso de disco
|
|
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "df -h"
|
|
```
|
|
|
|
### Ver uso de Docker
|
|
|
|
```bash
|
|
ssh ubuntu@129.146.218 "docker system df"
|
|
```
|
|
|
|
---
|
|
|
|
## 🐛 Troubleshooting
|
|
|
|
### Site não carrega (502 Bad Gateway)
|
|
|
|
1. Verificar se container está rodando:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker ps --filter name=carneirotech"
|
|
```
|
|
|
|
2. Ver logs do container:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker logs carneirotech-web --tail=100"
|
|
```
|
|
|
|
3. Reiniciar container:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "cd ~/apps/carneirotech && docker compose restart"
|
|
```
|
|
|
|
### Container não sobe (unhealthy)
|
|
|
|
1. Ver logs detalhados:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker logs carneirotech-web"
|
|
```
|
|
|
|
2. Verificar health check manualmente:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "curl http://localhost:5008/"
|
|
```
|
|
|
|
3. Entrar no container para debug:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker exec -it carneirotech-web bash"
|
|
```
|
|
|
|
### Build falha
|
|
|
|
1. Verificar se há espaço em disco:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "df -h"
|
|
```
|
|
|
|
2. Limpar cache do Docker:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker builder prune -a"
|
|
```
|
|
|
|
3. Fazer build com logs detalhados:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "cd ~/apps/carneirotech && docker compose build --no-cache --progress=plain"
|
|
```
|
|
|
|
### SSL expirado
|
|
|
|
Renovar manualmente:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "sudo certbot renew --force-renewal"
|
|
```
|
|
|
|
---
|
|
|
|
## 📊 Monitoramento
|
|
|
|
### Health Check Endpoint
|
|
|
|
O container tem health check automático configurado:
|
|
- **URL**: `http://localhost:5008/`
|
|
- **Intervalo**: 30s
|
|
- **Timeout**: 3s
|
|
- **Start Period**: 40s
|
|
|
|
### Ver status de saúde
|
|
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker inspect carneirotech-web | grep -A 10 Health"
|
|
```
|
|
|
|
---
|
|
|
|
## 🔄 Workflow de Desenvolvimento
|
|
|
|
1. **Desenvolver localmente** (Windows)
|
|
```bash
|
|
cd C:\Users\ricar\Nextcloud\CarneiroTech\Site\aspnet\CarneiroTech
|
|
dotnet run
|
|
```
|
|
|
|
2. **Testar mudanças** (http://localhost:5000)
|
|
|
|
3. **Fazer deploy para produção**
|
|
```bash
|
|
./deploy-to-oci.sh
|
|
```
|
|
|
|
4. **Verificar em produção** (https://carneirotech.com)
|
|
|
|
---
|
|
|
|
## 📝 Notas Importantes
|
|
|
|
- ⚠️ O servidor usa **ARM64** (Ampere). O Dockerfile está otimizado para isso.
|
|
- ⚠️ Não use `docker-compose` sem `deploy.sh` - pode causar downtime sem rollback.
|
|
- ⚠️ Sempre teste localmente antes de fazer deploy.
|
|
- ⚠️ O script de deploy faz backup automático - use sem medo!
|
|
- ⚠️ Arquivos Markdown (Content/Cases/*.md) são incluídos no build.
|
|
|
|
---
|
|
|
|
## ✅ Checklist de Deploy
|
|
|
|
Antes de fazer deploy, verifique:
|
|
|
|
- [ ] Código compilou localmente sem erros
|
|
- [ ] Testou localmente (dotnet run)
|
|
- [ ] Commitou mudanças no Git (quando configurar)
|
|
- [ ] Executou `./deploy-to-oci.sh`
|
|
- [ ] Verificou logs: `docker logs carneirotech-web`
|
|
- [ ] Testou site: `https://carneirotech.com`
|
|
- [ ] Verificou que cases Markdown aparecem corretamente
|
|
|
|
---
|
|
|
|
## 🆘 Suporte
|
|
|
|
Em caso de problemas críticos:
|
|
|
|
1. Ver logs em tempo real:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218 "docker logs carneirotech-web -f"
|
|
```
|
|
|
|
2. Rollback para versão anterior (automático no deploy.sh)
|
|
|
|
3. Se precisar voltar manualmente:
|
|
```bash
|
|
ssh ubuntu@129.146.116.218
|
|
cd ~/backups/carneirotech
|
|
# Ver backups disponíveis
|
|
docker images | grep carneirotech-web
|
|
# Usar backup específico
|
|
docker tag <BACKUP_IMAGE_ID> carneirotech-carneirotech-web
|
|
cd ~/apps/carneirotech
|
|
docker compose up -d
|
|
```
|
|
|
|
---
|
|
|
|
**Deployment criado em:** 21 de Dezembro de 2024
|
|
**Última atualização:** 21 de Dezembro de 2024
|
|
**Servidor:** OCI (Oracle Cloud) - ARM64 (Ampere)
|
|
**Status:** ✅ Produção
|