Pull-Only: Assume Rust/Node/Python já instalados (v12)
Mudanças: - Remove setup do Rust (assume já instalado no runner) - Remove instalação de sccache (opcional) - Verifica dependências no inÃcio do build - Foco: apenas clone + build + deploy - Mais rápido (~3-4 min total) Pré-requisitos no runner: - Rust (cargo, rustc) já instalado - Git já configurado - SSH keys já configuradas - Acesso ao repositório ALM Fluxo: 1. Clone limpo do repositório gb 2. Inicializa submodules botserver + botlib 3. cargo build -p botserver 4. Deploy automático 5. Cleanup Tempo estimado: ~3-4 minutos
This commit is contained in:
parent
7115cb3e19
commit
4b8e19d9e9
1 changed files with 25 additions and 57 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
# HASH-BUSTER-20260418-COMPLETO-v11
|
# HASH-BUSTER-20260418-PULLONLY-v12
|
||||||
# COMPLETO: Rust setup + Clone limpo + Build + Deploy
|
# PULL-ONLY: Assume Rust, Node, Python já instalados no runner
|
||||||
name: BotServer CI/CD
|
name: BotServer CI/CD
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
|
@ -13,62 +13,27 @@ env:
|
||||||
CARGO_TARGET_DIR: /opt/gbo/work/target
|
CARGO_TARGET_DIR: /opt/gbo/work/target
|
||||||
RUSTUP_HOME: /opt/gbo/work/.rustup
|
RUSTUP_HOME: /opt/gbo/work/.rustup
|
||||||
CARGO_HOME: /opt/gbo/work/.cargo
|
CARGO_HOME: /opt/gbo/work/.cargo
|
||||||
|
PATH: /opt/gbo/work/.cargo/bin:/opt/gbo/work/.rustup/bin:$PATH
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: gbo
|
runs-on: gbo
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Rust
|
|
||||||
run: |
|
|
||||||
echo "=== Setup do Rust ==="
|
|
||||||
export RUSTUP_HOME=/opt/gbo/work/.rustup
|
|
||||||
export CARGO_HOME=/opt/gbo/work/.cargo
|
|
||||||
export PATH="/opt/gbo/work/.cargo/bin:$PATH"
|
|
||||||
|
|
||||||
# Verificar se Rust já está instalado
|
|
||||||
if [ ! -f /opt/gbo/work/.cargo/bin/cargo ]; then
|
|
||||||
echo "Instalando Rust..."
|
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
|
|
||||||
echo "Rust instalado!"
|
|
||||||
else
|
|
||||||
echo "Rust já está instalado"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Atualizar rustup
|
|
||||||
rustup update stable || true
|
|
||||||
|
|
||||||
# Instalar sccache
|
|
||||||
echo "Instalando sccache..."
|
|
||||||
cargo install sccache || true
|
|
||||||
|
|
||||||
# Configurar ambiente
|
|
||||||
echo "export PATH=/opt/gbo/work/.cargo/bin:\$PATH" >> /home/gbuser/.bashrc
|
|
||||||
echo "export RUSTUP_HOME=/opt/gbo/work/.rustup" >> /home/gbuser/.bashrc
|
|
||||||
echo "export CARGO_HOME=/opt/gbo/work/.cargo" >> /home/gbuser/.bashrc
|
|
||||||
|
|
||||||
# Iniciar sccache
|
|
||||||
sccache --start-server || true
|
|
||||||
|
|
||||||
echo "Setup do Rust concluído!"
|
|
||||||
cargo --version
|
|
||||||
rustc --version
|
|
||||||
|
|
||||||
- name: Clone Limpo
|
- name: Clone Limpo
|
||||||
run: |
|
run: |
|
||||||
echo "=== Clone Limpo do Workspace ==="
|
echo "=== Clone Limpo do Workspace ==="
|
||||||
export PATH="/opt/gbo/work/.cargo/bin:$PATH"
|
|
||||||
|
|
||||||
# Limpar diretório de trabalho anterior
|
# Limpar diretório de trabalho anterior
|
||||||
rm -rf /opt/gbo/work/build
|
rm -rf /opt/gbo/work/build
|
||||||
mkdir -p /opt/gbo/work/build
|
mkdir -p /opt/gbo/work/build
|
||||||
cd /opt/gbo/work/build
|
cd /opt/gbo/work/build
|
||||||
|
|
||||||
# Clonar repositório gb (workspace raiz)
|
# Clonar repositório gb (workspace raiz)
|
||||||
git clone --depth 1 --branch main https://alm.pragmatismo.com.br/GeneralBots/gb.git workspace
|
git clone --depth 1 --branch main https://alm.pragmatismo.com.br/GeneralBots/gb.git workspace
|
||||||
cd workspace
|
cd workspace
|
||||||
|
|
||||||
# Inicializar APENAS submodules necessários
|
# Inicializar APENAS submodules necessários
|
||||||
echo "Inicializando submodules necessários..."
|
echo "Inicializando submodules necessários..."
|
||||||
git config -f .gitmodules submodule.botserver.url https://alm.pragmatismo.com.br/GeneralBots/BotServer.git
|
git config -f .gitmodules submodule.botserver.url https://alm.pragmatismo.com.br/GeneralBots/BotServer.git
|
||||||
git config -f .gitmodules submodule.botlib.url https://alm.pragmatismo.com.br/GeneralBots/botlib.git
|
git config -f .gitmodules submodule.botlib.url https://alm.pragmatismo.com.br/GeneralBots/botlib.git
|
||||||
git submodule update --init --depth 1 botserver
|
git submodule update --init --depth 1 botserver
|
||||||
|
|
@ -81,7 +46,7 @@ jobs:
|
||||||
echo "botlib/:"
|
echo "botlib/:"
|
||||||
ls -la botlib/ | head -15
|
ls -la botlib/ | head -15
|
||||||
|
|
||||||
# Preparar Cargo.toml (remover members desnecessários)
|
# Preparar Cargo.toml (remover members desnecessários)
|
||||||
echo "Preparando Cargo.toml..."
|
echo "Preparando Cargo.toml..."
|
||||||
grep -v '"botapp\|"botdevice\|"bottest\|"botui\|"botbook\|"botmodels\|"botplugin\|"bottemplates"' Cargo.toml > Cargo.toml.clean || true
|
grep -v '"botapp\|"botdevice\|"bottest\|"botui\|"botbook\|"botmodels\|"botplugin\|"bottemplates"' Cargo.toml > Cargo.toml.clean || true
|
||||||
if [ -s Cargo.toml.clean ]; then
|
if [ -s Cargo.toml.clean ]; then
|
||||||
|
|
@ -93,40 +58,43 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
echo "=== Build (Debug) ==="
|
echo "=== Build (Debug) ==="
|
||||||
export PATH="/opt/gbo/work/.cargo/bin:$PATH"
|
|
||||||
export RUSTUP_HOME=/opt/gbo/work/.rustup
|
|
||||||
export CARGO_HOME=/opt/gbo/work/.cargo
|
|
||||||
cd /opt/gbo/work/build/workspace
|
cd /opt/gbo/work/build/workspace
|
||||||
|
|
||||||
|
# Verificar dependências
|
||||||
|
echo "Verificando dependências..."
|
||||||
|
cargo --version || { echo "ERRO: cargo não encontrado"; exit 1; }
|
||||||
|
rustc --version || { echo "ERRO: rustc não encontrado"; exit 1; }
|
||||||
|
node --version || echo "AVISO: node não disponÃvel"
|
||||||
|
python3 --version || echo "AVISO: python3 não disponÃvel"
|
||||||
|
|
||||||
# Verificar estrutura
|
# Verificar estrutura
|
||||||
if [ ! -f Cargo.toml ]; then
|
if [ ! -f Cargo.toml ]; then
|
||||||
echo "ERRO: Cargo.toml não encontrado"
|
echo "ERRO: Cargo.toml não encontrado"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f botserver/Cargo.toml ]; then
|
if [ ! -f botserver/Cargo.toml ]; then
|
||||||
echo "ERRO: botserver/Cargo.toml não encontrado"
|
echo "ERRO: botserver/Cargo.toml não encontrado"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build com sccache
|
# Build
|
||||||
echo "Iniciando build com sccache..."
|
echo "Iniciando build..."
|
||||||
RUSTC_WRAPPER=sccache cargo build -p botserver
|
cargo build -p botserver
|
||||||
|
|
||||||
echo "Build concluído!"
|
echo "Build concluÃdo!"
|
||||||
ls -lh target/debug/botserver
|
ls -lh target/debug/botserver
|
||||||
sccache --show-stats
|
|
||||||
|
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
run: |
|
run: |
|
||||||
echo "=== Deploy ==="
|
echo "=== Deploy ==="
|
||||||
SSH="-i /home/gbuser/.ssh/id_ed25519 -o StrictHostKeyChecking=no"
|
SSH="-i /home/gbuser/.ssh/id_ed25519 -o StrictHostKeyChecking=no"
|
||||||
|
|
||||||
# Parar serviço atual
|
# Parar serviço atual
|
||||||
ssh $SSH system "sudo systemctl stop botserver || true"
|
ssh $SSH system "sudo systemctl stop botserver || true"
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
# Copiar binário
|
# Copiar binário
|
||||||
scp $SSH /opt/gbo/work/build/workspace/target/debug/botserver system:/tmp/botserver
|
scp $SSH /opt/gbo/work/build/workspace/target/debug/botserver system:/tmp/botserver
|
||||||
|
|
||||||
# Instalar e reiniciar
|
# Instalar e reiniciar
|
||||||
|
|
@ -137,11 +105,11 @@ jobs:
|
||||||
sudo systemctl start botserver
|
sudo systemctl start botserver
|
||||||
"
|
"
|
||||||
|
|
||||||
# Aguardar inicialização
|
# Aguardar inicializaçãoo
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
# Verificar deploy
|
# Verificar deploy
|
||||||
ssh $SSH system "curl -sf http://localhost:8080/health && echo '✅ Deploy OK'" || echo "⚠️ Health check falhou"
|
ssh $SSH system "curl -sf http://localhost:8080/health && echo '✅ Deploy OK'" || echo "â ï¸ Health check falhou"
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue