diff --git a/.gitea/workflows/deploy-bcards.yml b/.gitea/workflows/deploy-bcards.yml index f59b2fb..6a0d99f 100644 --- a/.gitea/workflows/deploy-bcards.yml +++ b/.gitea/workflows/deploy-bcards.yml @@ -184,7 +184,7 @@ jobs: deploy-production: name: Deploy to Production (ARM - OCI) - runs-on: [self-hosted, arm64, bcards] + runs-on: ubuntu-latest needs: [build-and-push] if: github.ref_name == 'main' environment: production @@ -538,7 +538,7 @@ jobs: ssh -o StrictHostKeyChecking=no ubuntu@129.146.116.218 'curl -f http://localhost:8080/health || echo "⚠️ Servidor 2 pode nΓ£o estar respondendo"' deploy-test: - name: Deploy to Test (x86 - Local) + name: Deploy to Release Swarm (ARM) runs-on: [self-hosted, arm64, bcards] needs: [build-and-push] if: startsWith(github.ref_name, 'Release/') @@ -554,60 +554,26 @@ jobs: echo "version=$VERSION" >> $GITHUB_OUTPUT echo "πŸ“¦ Deploying version: $VERSION" - - name: Deploy to Test Server + - name: Prepare release stack manifest run: | - echo "πŸš€ Deploying to test server (x86)..." + mkdir -p artifacts + export BCARDS_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} + envsubst '$BCARDS_IMAGE' < deploy/docker-stack.release.yml > artifacts/docker-stack.release.yml + + - name: Deploy to release swarm + run: | + echo "πŸš€ Deploying release stack to Orange Pi swarm..." - # Configura SSH (igual ao QRRapido) mkdir -p ~/.ssh echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - - # Adiciona hosts conhecidos ssh-keyscan -H 141.148.162.114 >> ~/.ssh/known_hosts ssh-keyscan -H 129.146.116.218 >> ~/.ssh/known_hosts - # Testa a chave SSH - ssh-add ~/.ssh/id_rsa 2>/dev/null || echo "SSH key loaded" + scp -o StrictHostKeyChecking=no artifacts/docker-stack.release.yml ubuntu@141.148.162.114:/home/ubuntu/docker-stack.release.yml - # Deploy no Servidor Local x86 - ssh -o StrictHostKeyChecking=no ubuntu@192.168.0.100 << EOF - echo "πŸ”„ Atualizando Servidor Teste..." - - # Remove containers bcards-infrastructure se existirem - docker stop bcards-infrastructure bcards-test-app || true - docker rm bcards-infrastructure bcards-test-app || true - - # Para o container BCards atual se existir - docker stop bcards-test || true - docker rm bcards-test || true - - # Remove imagem antiga - docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} || true - - # Puxa nova imagem - docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} - - # Executa novo container BCards - docker run -d \ - --name bcards-test \ - --restart unless-stopped \ - --network host \ - -e ASPNETCORE_ENVIRONMENT=Testing \ - -e ASPNETCORE_URLS=http://+:8080 \ - -e Serilog__OpenSearchUrl="http://192.168.0.100:9200" \ - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} - - echo "βœ… Servidor Teste atualizado" - EOF - - - name: Health Check Test - run: | - echo "πŸ₯ Verificando saΓΊde do servidor de teste..." - sleep 30 - - echo "Verificando Servidor Teste (x86)..." - ssh -o StrictHostKeyChecking=no ubuntu@192.168.0.100 'curl -f http://localhost:8080/health || echo "⚠️ Servidor teste pode nΓ£o estar respondendo"' + ssh -o StrictHostKeyChecking=no ubuntu@141.148.162.114 \ + '/home/ubuntu/scripts/swarm_deploy.sh bcards-release bcards-release /home/ubuntu/docker-stack.release.yml http://localhost:28080/health 2' cleanup: name: Cleanup Old Resources @@ -636,7 +602,7 @@ jobs: if [ "${{ github.ref_name }}" = "main" ]; then SERVERS=("141.148.162.114" "129.146.116.218") else - SERVERS=("192.168.0.100") + SERVERS=("141.148.162.114" "129.146.116.218") fi # Limpeza em cada servidor @@ -672,14 +638,14 @@ jobs: echo "πŸ—οΈ Registry: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" if [ "${{ github.ref_name }}" = "main" ]; then - echo "🌍 Environment: Production (ARM64)" + echo "🌍 Environment: Production (Swarm ARM)" echo "πŸ–₯️ Servers: 141.148.162.114, 129.146.116.218" echo "πŸ“¦ Tag: latest" echo "πŸ”— Status: ${{ needs.deploy-production.result }}" else - echo "🌍 Environment: Testing (x86)" - echo "πŸ–₯️ Server: 192.168.0.100" - echo "πŸ“¦ Tag: ${{ github.ref_name }}" + echo "🌍 Environment: Release (Swarm ARM)" + echo "πŸ–₯️ Servers: 141.148.162.114, 129.146.116.218" + echo "πŸ“¦ Branch Tag: ${{ github.ref_name }}" echo "πŸ”— Status: ${{ needs.deploy-test.result }}" fi diff --git a/deploy/docker-stack.release.yml b/deploy/docker-stack.release.yml new file mode 100644 index 0000000..3e06b54 --- /dev/null +++ b/deploy/docker-stack.release.yml @@ -0,0 +1,47 @@ +version: '3.8' + +services: + bcards-release: + image: ${BCARDS_IMAGE} + networks: + - bcards-net + deploy: + replicas: 2 + placement: + max_replicas_per_node: 1 + update_config: + parallelism: 1 + delay: 10s + order: start-first + monitor: 60s + failure_action: rollback + rollback_config: + parallelism: 0 + delay: 5s + environment: + ASPNETCORE_ENVIRONMENT: Release + ASPNETCORE_URLS: http://+:8080 + ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true" + MongoDb__ConnectionString: mongodb://192.168.0.100:27017/BCardsDB + MongoDb__DatabaseName: BCardsDB + DataProtection__Mongo__ConnectionString: mongodb://192.168.0.100:27017/BCardsDB + DataProtection__Mongo__DatabaseName: BCardsDB + DataProtection__Mongo__CollectionName: DataProtectionKeys + Serilog__OpenSearchUrl: http://141.148.162.114:19201 + Serilog__OpenSearchFallback: http://129.146.116.218:19202 + Logging__LogLevel__Default: Debug + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + ports: + - published: 28080 + target: 8080 + protocol: tcp + mode: ingress + +networks: + bcards-net: + external: true