wiki/.forgejo/workflows/deploy.yml
vickytechkey 90ce89fb30
All checks were successful
Deploy Docmost Wiki / Deploy to cisystem (push) Successful in 26s
fix(ci): add SSH connect timeout and host discovery fallback to deploy workflow
2026-09-27 16:02:40 +05:30

86 lines
2.9 KiB
YAML

name: Deploy Docmost Wiki
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
name: Deploy to cisystem
runs-on: ubuntu-latest
container:
image: node:22-alpine
steps:
- name: Install git and openssh
run: apk add --no-cache git openssh-client curl
- name: Checkout Code
uses: https://github.com/actions/checkout@v4
- name: Deploy via SSH
env:
SSH_KEY: ${{ secrets.CISYSTEM_SSH_KEY }}
REMOTE_HOST: ${{ secrets.CISYSTEM_HOST }}
REMOTE_USER: ${{ secrets.CISYSTEM_USER }}
run: |
mkdir -p ~/.ssh
echo "$SSH_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
TARGET_USER="${REMOTE_USER:-ubuntu}"
DEFAULT_GATEWAY=$(ip route 2>/dev/null | awk '/default/ {print $3}' || true)
SSH_OPTS="-o StrictHostKeyChecking=no -o ConnectTimeout=5 -i ~/.ssh/id_rsa"
TARGET_HOST=""
for H in "${REMOTE_HOST}" "16.113.106.152" "$DEFAULT_GATEWAY" "172.17.0.1" "host.docker.internal"; do
if [ -n "$H" ]; then
echo "Testing SSH connection to $H..."
if ssh $SSH_OPTS "$TARGET_USER@$H" "echo connection_ok" 2>/dev/null | grep -q "connection_ok"; then
TARGET_HOST="$H"
echo "Successfully connected to target host: $TARGET_HOST"
break
fi
fi
done
if [ -z "$TARGET_HOST" ]; then
echo "Error: Unable to connect via SSH to any target host candidate."
exit 1
fi
# Create target directories
ssh $SSH_OPTS $TARGET_USER@$TARGET_HOST "mkdir -p /home/ubuntu/docmost/patches"
# Copy compose configuration and patches
scp $SSH_OPTS docker-compose.yml $TARGET_USER@$TARGET_HOST:/home/ubuntu/docmost/docker-compose.yml
scp $SSH_OPTS patches/* $TARGET_USER@$TARGET_HOST:/home/ubuntu/docmost/patches/
# Restart containers cleanly
ssh $SSH_OPTS $TARGET_USER@$TARGET_HOST 'bash -s' << 'EOF'
set -e
cd /home/ubuntu/docmost
docker compose pull docmost redis
docker compose up -d --remove-orphans
echo "Verifying Docmost service health..."
HEALTHY=false
for i in $(seq 1 30); do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:3001/ || true)
if [ "$STATUS" = "200" ] || [ "$STATUS" = "302" ]; then
echo "Docmost is healthy! HTTP Status: $STATUS"
HEALTHY=true
break
fi
sleep 2
done
if [ "$HEALTHY" != "true" ]; then
echo "Docmost did not respond with 200/302 within 60s. Inspecting logs:"
docker compose logs --tail=50 docmost
exit 1
fi
echo "Deployment successful!"
EOF