# Remote Server Debug Commands
# Copy and paste these commands on the remote server (ssh deploy@141.136.35.199)

# 1. Check Docker is running
echo "=== Docker Version ==="
docker --version
docker info | head -20

# 2. Check Docker images
echo -e "\n=== Docker Images ==="
docker images | head -20

# 3. Check if logged in to Gitea
echo -e "\n=== Docker Login Status ==="
cat ~/.docker/config.json 2>/dev/null || echo "Not logged in to any registry"

# 4. Check Gitea container status
echo -e "\n=== Gitea Container ==="
docker ps -a | grep gitea

# 5. Check Gitea logs for errors
echo -e "\n=== Gitea Recent Logs ==="
docker logs --tail 50 gitea-server 2>&1 | grep -i error || echo "No errors in recent logs"

# 6. Test Gitea registry endpoint
echo -e "\n=== Gitea Registry Endpoint Test ==="
curl -I https://gitea.harkon.co.uk/v2/ 2>&1

# 7. Check disk space
echo -e "\n=== Disk Space ==="
df -h

# 8. Check if there's a build in progress
echo -e "\n=== Docker Build Processes ==="
ps aux | grep "docker build" | grep -v grep || echo "No docker build in progress"

# 9. Check Docker daemon logs
echo -e "\n=== Docker Daemon Status ==="
sudo systemctl status docker | head -20

# 10. Try to push a small test image
echo -e "\n=== Test Docker Push ==="
docker pull alpine:latest
docker tag alpine:latest gitea.harkon.co.uk/harkon/test:latest
docker push gitea.harkon.co.uk/harkon/test:latest

# 11. Check Gitea app.ini for upload limits
echo -e "\n=== Gitea Upload Limits ==="
docker exec gitea-server cat /data/gitea/conf/app.ini | grep -A 5 -i "max.*size" || echo "Could not read Gitea config"

# 12. Check if base-ml image exists
echo -e "\n=== Base ML Image Status ==="
docker images | grep base-ml

# 13. Check recent Docker push attempts
echo -e "\n=== Recent Docker Events ==="
docker events --since 1h --filter 'type=image' --filter 'event=push' || echo "No recent push events"

# 14. Check network connectivity to Gitea
echo -e "\n=== Network Test to Gitea ==="
ping -c 3 gitea.harkon.co.uk

# 15. Check if Traefik is running and configured
echo -e "\n=== Traefik Status ==="
docker ps | grep apa-traefik || docker ps | grep traefik
