name: 部署到群晖 on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - name: 安装 Docker CLI run: | if command -v docker >/dev/null 2>&1; then echo "Docker 已预装:$(docker --version)" exit 0 fi echo "=== 1. 系统信息 ===" cat /etc/os-release | head -5 || true echo "" echo "=== 2. 换源前 sources 文件 ===" ls -la /etc/apt/sources.list /etc/apt/sources.list.d/ 2>&1 || true grep -h -E 'ubuntu|debian|http' /etc/apt/sources.list /etc/apt/sources.list.d/*.sources /etc/apt/sources.list.d/*.list 2>/dev/null | grep -v '^#' | head -10 || true echo "" echo "=== 3. 换源到阿里云 ===" sed -i 's|archive.ubuntu.com|mirrors.aliyun.com|g;s|security.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list 2>/dev/null || true sed -i 's|archive.ubuntu.com|mirrors.aliyun.com|g;s|security.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list.d/*.sources 2>/dev/null || true sed -i 's|archive.ubuntu.com|mirrors.aliyun.com|g;s|security.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list.d/*.list 2>/dev/null || true echo "--- 换源后 sources 内容:" grep -h -E 'aliyun|ubuntu|debian|http' /etc/apt/sources.list /etc/apt/sources.list.d/*.sources /etc/apt/sources.list.d/*.list 2>/dev/null | grep -v '^#' | head -10 || true echo "" echo "=== 4. 网络探测 ===" echo "--- DNS 解析 mirrors.aliyun.com:" timeout 5 getent hosts mirrors.aliyun.com || echo "DNS 解析失败" echo "--- HTTP 探测 mirrors.aliyun.com:" timeout 10 curl -s -o /dev/null -w "http_code=%{http_code} time=%{time_total}s\n" http://mirrors.aliyun.com/ || echo "curl 阿里云失败" echo "" echo "=== 5. apt-get update ===" timeout 90 apt-get update || { echo "apt-get update 失败,看上面日志定位"; exit 1; } echo "=== 6. 安装 docker.io ===" timeout 240 apt-get install -y docker.io || { echo "docker.io 安装超时"; exit 1; } docker --version - name: 拉取代码 uses: actions/checkout@v4 - name: 构建镜像 run: docker build -f Dockerfile.prod -t dysync:latest . - name: 停止旧容器 run: | docker stop dysync 2>/dev/null || true docker rm dysync 2>/dev/null || true - name: 启动新容器 run: | docker run -d \ --name dysync \ --restart unless-stopped \ -p 10101:10101 \ -e TZ=Asia/Shanghai \ -e ASPNETCORE_ENVIRONMENT=Production \ -v /volume1/docker/apps/dysync/db:/app/db \ -v /volume1/docker/apps/dysync/logs:/app/logs \ -v /volume2/save/dysync/collect:/app/collect \ -v /volume2/save/dysync/favorite:/app/favorite \ -v /volume2/save/dysync/uper:/app/uper \ dysync:latest - name: 部署完成提示 run: | echo "✅ 部署完成,浏览器访问 http://192.168.1.66:10101 查看"