Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Python cache
__pycache__/
*.py[cod]
*$py.class

# Arquivos compilados
*.so
Expand Down
73 changes: 73 additions & 0 deletions Dockerfile.installer-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Dockerfile para testar o instalador do FazAI v2.0
# Simula ambiente limpo Ubuntu para validar processo de instalação completo

FROM ubuntu:22.04

# Evitar prompts interativos durante instalação
ENV DEBIAN_FRONTEND=noninteractive

# Instalar dependências básicas necessárias para o FazAI
RUN apt-get update && apt-get install -y \
# Utilitários básicos
sudo \
curl \
wget \
git \
lsb-release \
ca-certificates \
gnupg \
# Ferramentas de desenvolvimento
build-essential \
cmake \
pkg-config \
# Python e pip
python3 \
python3-pip \
python3-dev \
python3-venv \
# Node.js será instalado pelo installer do FazAI
# Bibliotecas de desenvolvimento
libssl-dev \
libffi-dev \
libcurl4-openssl-dev \
# Limpeza
&& rm -rf /var/lib/apt/lists/*

# Criar usuário não-root para simular ambiente real
RUN useradd -ms /bin/bash fazai && \
echo "fazai ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
usermod -aG sudo fazai

# Preparar diretórios do FazAI
RUN mkdir -p /opt/fazai /etc/fazai /var/log/fazai /var/lib/fazai && \
chown -R fazai:fazai /opt/fazai /etc/fazai /var/log/fazai /var/lib/fazai

# Definir diretório de trabalho
WORKDIR /workspace

# Copiar código fonte (quando usado com volume mount)
# COPY . /workspace/

# Ajustar permissões para o usuário fazai
RUN chown -R fazai:fazai /workspace

# Trocar para usuário não-root
USER fazai

# Variáveis de ambiente para o FazAI
ENV FAZAI_PORT=3120
ENV NODE_ENV=development
ENV FAZAI_LOG_LEVEL=debug

# Script de entrada para testes
COPY --chown=fazai:fazai docker-installer-test-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-installer-test-entrypoint.sh

# Comando padrão: entrar no bash para testes manuais
CMD ["bash"]

# Labels para organização
LABEL maintainer="Roger Luft <roger@fazai.dev>"
LABEL description="Container para testar instalador do FazAI v2.0"
LABEL version="2.0"
LABEL project="FazAI"
27 changes: 27 additions & 0 deletions bin/fazai-containers
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# FazAI Container Manager CLI
# Wrapper para a ferramenta TUI de gerenciamento de containers

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONTAINER_TUI="/opt/fazai/tools/container_manager_tui.py"

# Fallback para desenvolvimento
if [ ! -f "$CONTAINER_TUI" ]; then
CONTAINER_TUI="$SCRIPT_DIR/../opt/fazai/tools/container_manager_tui.py"
fi

# Verificar se o arquivo existe
if [ ! -f "$CONTAINER_TUI" ]; then
echo "Erro: Arquivo $CONTAINER_TUI não encontrado"
echo "Execute a instalação completa do FazAI primeiro"
exit 1
fi

# Verificar dependências
if ! python3 -c "import textual" >/dev/null 2>&1; then
echo "Instalando dependência textual..."
pip install textual
fi

# Executar TUI
exec python3 "$CONTAINER_TUI" "$@"
203 changes: 203 additions & 0 deletions docker-installer-test-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#!/bin/bash
# Entrypoint para container de teste do instalador FazAI
# Script para automatizar testes de instalação/desinstalação

set -e

# Cores para output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

log() {
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
}

log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}

log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}

log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}

# Função para testar instalação
test_installation() {
log "🚀 Iniciando teste de instalação do FazAI..."

# Verificar se estamos no diretório correto
if [ ! -f "install.sh" ]; then
log_error "Arquivo install.sh não encontrado no diretório atual"
log "Certifique-se de que o volume está montado corretamente"
return 1
fi

# Executar instalação
log "Executando: sudo ./install.sh"
if sudo ./install.sh; then
log_success "Instalação concluída com sucesso!"
else
log_error "Falha na instalação"
return 1
fi

# Verificar se o CLI foi instalado
if command -v fazai >/dev/null 2>&1; then
log_success "CLI 'fazai' encontrado no PATH"
fazai --version || log_warning "Falha ao obter versão do fazai"
else
log_warning "CLI 'fazai' não encontrado no PATH"
fi

# Verificar se o serviço está configurado
if systemctl list-unit-files | grep -q fazai; then
log_success "Serviço fazai encontrado no systemd"
else
log_warning "Serviço fazai não encontrado no systemd"
fi

# Verificar estrutura de diretórios
for dir in "/opt/fazai" "/etc/fazai" "/var/log/fazai"; do
if [ -d "$dir" ]; then
log_success "Diretório $dir criado"
else
log_warning "Diretório $dir não encontrado"
fi
done

log_success "Teste de instalação concluído!"
}

# Função para testar desinstalação
test_uninstallation() {
log "🧹 Iniciando teste de desinstalação do FazAI..."

if [ ! -f "uninstall.sh" ]; then
log_error "Arquivo uninstall.sh não encontrado"
return 1
fi

# Executar desinstalação
log "Executando: sudo ./uninstall.sh"
if sudo ./uninstall.sh; then
log_success "Desinstalação concluída com sucesso!"
else
log_error "Falha na desinstalação"
return 1
fi

# Verificar limpeza
if ! command -v fazai >/dev/null 2>&1; then
log_success "CLI 'fazai' removido do PATH"
else
log_warning "CLI 'fazai' ainda presente no PATH"
fi

log_success "Teste de desinstalação concluído!"
}

# Função para executar testes automatizados
run_automated_tests() {
log "🔄 Executando testes automatizados..."

# Teste completo: instalação + desinstalação
test_installation

log "Aguardando 5 segundos antes da desinstalação..."
sleep 5

test_uninstallation

log_success "Testes automatizados concluídos!"
}

# Função para modo interativo
interactive_mode() {
log "🎯 Modo interativo do container de teste FazAI"
echo ""
echo "Comandos disponíveis:"
echo " install - Testar instalação"
echo " uninstall - Testar desinstalação"
echo " auto - Executar testes automatizados"
echo " shell - Abrir shell bash"
echo " help - Mostrar esta ajuda"
echo ""

while true; do
read -p "fazai-test> " cmd

case "$cmd" in
"install")
test_installation
;;
"uninstall")
test_uninstallation
;;
"auto")
run_automated_tests
;;
"shell"|"bash")
log "Abrindo shell bash..."
exec bash
;;
"help"|"h")
interactive_mode
;;
"exit"|"quit"|"q")
log "Saindo..."
exit 0
;;
"")
# Enter vazio, apenas continuar
;;
*)
log_warning "Comando não reconhecido: $cmd"
echo "Digite 'help' para ver comandos disponíveis"
;;
esac
done
}

# Main
main() {
log "🐳 Container de teste do instalador FazAI v2.0"
log "Usuário atual: $(whoami)"
log "Diretório: $(pwd)"
log "Sistema: $(lsb_release -d | cut -f2)"
echo ""

# Verificar argumentos
case "${1:-interactive}" in
"install")
test_installation
;;
"uninstall")
test_uninstallation
;;
"auto")
run_automated_tests
;;
"interactive"|"")
interactive_mode
;;
*)
log_error "Argumento inválido: $1"
echo "Uso: $0 [install|uninstall|auto|interactive]"
exit 1
;;
esac
}

# Trap para limpeza
trap 'log "Interrompido pelo usuário"' INT TERM

# Executar main se chamado diretamente
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi
Loading