Revisão logo
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
# CI/CD - Avanzato Tecnologia
|
||||
|
||||
## Estrutura do Pipeline
|
||||
|
||||
```
|
||||
Push para main/master
|
||||
|
|
||||
v
|
||||
+------------------+ +------------------+ +------------------+
|
||||
| BUILD | --> | PRESERVAR ASSETS | --> | DEPLOY |
|
||||
| | | | | |
|
||||
| - Checkout | | - Logo | | - SCP para VPS |
|
||||
| - npm install | | - Imagens | | - Limpar cache |
|
||||
| - npm run build | | - Favicon | | - Notificar |
|
||||
+------------------+ +------------------+ +------------------+
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configurar Secrets no GitHub
|
||||
|
||||
Va em: **Settings > Secrets and variables > Actions > New repository secret**
|
||||
|
||||
| Secret | Descricao | Exemplo |
|
||||
|--------|-----------|---------|
|
||||
| `SSH_HOST` | IP ou dominio do servidor | `201.45.120.30` ou `avanzato.com.br` |
|
||||
| `SSH_USER` | Usuario SSH | `root` ou `deploy` |
|
||||
| `SSH_PRIVATE_KEY` | Chave SSH privada | `-----BEGIN OPENSSH PRIVATE KEY-----...` |
|
||||
| `SSH_PORT` | Porta SSH (opcional) | `22` |
|
||||
| `DEPLOY_PATH` | Caminho no servidor | `/var/www/avanzato` |
|
||||
| `STAGING_PATH` | Caminho staging (opcional) | `/var/www/avanzato-staging` |
|
||||
|
||||
### Como gerar a chave SSH:
|
||||
|
||||
```bash
|
||||
# No seu computador (NAO no servidor):
|
||||
ssh-keygen -t ed25519 -C "github-actions" -f ~/.ssh/github_actions
|
||||
|
||||
# Copiar publica para o servidor:
|
||||
ssh-copy-id -i ~/.ssh/github_actions.pub root@SEU_SERVIDOR
|
||||
|
||||
# Copiar privada para o GitHub Secret:
|
||||
cat ~/.ssh/github_actions
|
||||
# Cole o conteudo inteiro no secret SSH_PRIVATE_KEY
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Estrutura de Branches
|
||||
|
||||
```
|
||||
main/master --> Deploy automatico para producao
|
||||
staging --> Deploy automatico para staging (se existir)
|
||||
feature/* --> Apenas build (sem deploy)
|
||||
hotfix/* --> Apenas build (sem deploy)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Como Funciona
|
||||
|
||||
### Cenario 1: Deploy Automatico
|
||||
```
|
||||
1. Voce faz push para main
|
||||
2. GitHub Actions executa automaticamente
|
||||
3. Build + Deploy em ~2 minutos
|
||||
4. Site atualizado!
|
||||
```
|
||||
|
||||
### Cenario 2: Deploy Manual
|
||||
```
|
||||
1. Va em Actions > Build e Deploy
|
||||
2. Clique "Run workflow"
|
||||
3. Escolha: production ou staging
|
||||
4. Clique "Run"
|
||||
```
|
||||
|
||||
### Cenario 3: Pull Request
|
||||
```
|
||||
1. Cria PR para main
|
||||
2. CI executa build (testa se compila)
|
||||
3. NAO faz deploy
|
||||
4. Merge aprovado? Deploy automatico!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Assets Customizados (Logo, Imagens)
|
||||
|
||||
Para preservar assets apos o deploy automatico:
|
||||
|
||||
### 1. Commitar assets no repositorio
|
||||
|
||||
```bash
|
||||
git add custom-assets/logo/logo.png
|
||||
git add custom-assets/images/
|
||||
git commit -m "Adiciona logo e imagens customizadas"
|
||||
git push origin main
|
||||
```
|
||||
|
||||
### 2. O pipeline faz sozinho
|
||||
|
||||
O workflow executa automaticamente:
|
||||
```bash
|
||||
bash scripts/preserve-assets.sh dist/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Monitore os Deploys
|
||||
|
||||
- **GitHub Actions**: https://github.com/SEU_USUARIO/avanzato-site/actions
|
||||
- **Status**: Check verde = sucesso, X vermelho = falha
|
||||
- **Logs**: Clique no workflow para ver detalhes
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Deploy falhou?
|
||||
|
||||
1. **Verifique os secrets**: Settings > Secrets > Actions
|
||||
2. **Verifique a chave SSH**: `ssh -i ~/.ssh/github_actions root@SEU_SERVIDOR`
|
||||
3. **Verifique permissoes**: O usuario precisa de acesso de escrita no DEPLOY_PATH
|
||||
4. **Verifique logs**: Actions > Clique no workflow > Veja o passo que falhou
|
||||
|
||||
### Assets nao preservados?
|
||||
|
||||
1. Verifique se `custom-assets/` esta no repositorio
|
||||
2. Verifique se os arquivos estao comitados: `git ls-files custom-assets/`
|
||||
3. Verifique os logs do passo "Preservar assets customizados"
|
||||
|
||||
---
|
||||
|
||||
*Configurado em: Maio 2026*
|
||||
@@ -0,0 +1,162 @@
|
||||
# ============================================================================
|
||||
# CI/CD Pipeline - Avanzato Tecnologia
|
||||
# ============================================================================
|
||||
# Este workflow automatiza o build e deploy do site.
|
||||
#
|
||||
# TRIGGER: Push na branch main ou manual (workflow_dispatch)
|
||||
# ============================================================================
|
||||
|
||||
name: Build e Deploy
|
||||
|
||||
on:
|
||||
# Deploy automatico ao fazer push na main
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
|
||||
# Deploy manual pelo botao "Run workflow" no GitHub
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
environment:
|
||||
description: 'Ambiente'
|
||||
required: true
|
||||
default: 'production'
|
||||
type: choice
|
||||
options:
|
||||
- production
|
||||
- staging
|
||||
|
||||
# Pull Request (apenas build, sem deploy)
|
||||
pull_request:
|
||||
branches: [ main, master ]
|
||||
|
||||
# Permissoes necessarias
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
# ==========================================================================
|
||||
# JOB 1: Build
|
||||
# ==========================================================================
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# Passo 1: Checkout do codigo
|
||||
- name: Checkout codigo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Passo 2: Setup Node.js
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
# Passo 3: Instalar dependencias
|
||||
- name: Instalar dependencias
|
||||
run: npm ci
|
||||
|
||||
# Passo 4: Build
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
# Passo 5: Upload do artefato (para usar no job de deploy)
|
||||
- name: Upload artefato
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
retention-days: 1
|
||||
|
||||
# ==========================================================================
|
||||
# JOB 2: Deploy para Servidor (Producao)
|
||||
# ==========================================================================
|
||||
deploy-production:
|
||||
name: Deploy - Producao
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
# So executa na branch main/master ou manual com environment=production
|
||||
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.event.inputs.environment == 'production'
|
||||
|
||||
steps:
|
||||
# Passo 1: Download do artefato buildado
|
||||
- name: Download artefato
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
|
||||
# Passo 2: Preservar assets customizados (logo, imagens)
|
||||
- name: Preservar assets customizados
|
||||
run: |
|
||||
if [ -d "custom-assets" ]; then
|
||||
echo "Preservando assets customizados..."
|
||||
bash scripts/preserve-assets.sh dist/
|
||||
else
|
||||
echo "Nenhum asset customizado encontrado."
|
||||
fi
|
||||
|
||||
# Passo 3: Deploy via SCP (SSH)
|
||||
- name: Deploy para servidor
|
||||
uses: appleboy/scp-action@v0.1.7
|
||||
with:
|
||||
host: ${{ secrets.SSH_HOST }}
|
||||
username: ${{ secrets.SSH_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
port: ${{ secrets.SSH_PORT || '22' }}
|
||||
source: "dist/*"
|
||||
target: ${{ secrets.DEPLOY_PATH || '/var/www/avanzato' }}
|
||||
strip_components: 1
|
||||
rm: true # Remove arquivos antigos antes de copiar
|
||||
|
||||
# Passo 4: Notificar (opcional - webhook Discord/Slack)
|
||||
- name: Notificar sucesso
|
||||
if: success()
|
||||
run: |
|
||||
echo "Deploy para producao concluido com sucesso!"
|
||||
echo "Site: https://avanzato.com.br"
|
||||
|
||||
# ==========================================================================
|
||||
# JOB 3: Deploy para Staging (Opcional)
|
||||
# ==========================================================================
|
||||
deploy-staging:
|
||||
name: Deploy - Staging
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
# So executa em push para branch staging ou manual
|
||||
if: github.ref == 'refs/heads/staging' || github.event.inputs.environment == 'staging'
|
||||
|
||||
steps:
|
||||
- name: Download artefato
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
|
||||
- name: Deploy para staging
|
||||
uses: appleboy/scp-action@v0.1.7
|
||||
with:
|
||||
host: ${{ secrets.SSH_HOST }}
|
||||
username: ${{ secrets.SSH_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
port: ${{ secrets.SSH_PORT || '22' }}
|
||||
source: "dist/*"
|
||||
target: ${{ secrets.STAGING_PATH || '/var/www/avanzato-staging' }}
|
||||
strip_components: 1
|
||||
rm: true
|
||||
|
||||
# ==========================================================================
|
||||
# JOB 4: Notificacao de Falha
|
||||
# ==========================================================================
|
||||
notify-failure:
|
||||
name: Notificar Falha
|
||||
needs: [build, deploy-production]
|
||||
runs-on: ubuntu-latest
|
||||
if: failure()
|
||||
|
||||
steps:
|
||||
- name: Notificar falha
|
||||
run: |
|
||||
echo "ALERTA: O deploy falhou!"
|
||||
echo "Verifique os logs em: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
Reference in New Issue
Block a user