name: Deploy API Server on: push: branches: [main] jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout latest code run: | if [ -d /tmp/api-server ]; then cd /tmp/api-server && git pull else git clone http://localhost:3000/suche-Hermes/api-server.git /tmp/api-server fi - name: Build Docker image run: cd /tmp/api-server && docker build -t zhixi-api:latest . - name: Stop old container run: docker stop zhixi-api 2>/dev/null || true - name: Remove old container run: docker rm zhixi-api 2>/dev/null || true - name: Start new container run: | docker run -d \ --name zhixi-api \ --network zhixi-net \ --restart unless-stopped \ -p 3001:3000 \ --env-file /etc/zhixi/.env.production \ zhixi-api:latest - name: Health check run: | sleep 8 curl -f http://localhost:3001/health || (docker logs zhixi-api --tail 30 && exit 1)