Files
content-harvester/.gitea/workflows/deploy.yml
T
huyueandClaude Opus 4.7 9ddad90891
Deploy / Build and deploy (push) Successful in 8s
ci: deploy.yml 按分支分流(dev→srv1563674 / main·master→sf5-gpu-01)
prod 也接入自动部署:push main/master 在 prod GPU 机重建 content-harvester 容器。
对应在 sf5-gpu-01 上新增了实例级 gitea runner(label sf5-gpu-01)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 10:46:02 +08:00

93 lines
3.0 KiB
YAML

name: Deploy
# push dev → dev 开发机(srv1563674)重建 content-harvester 容器
# push main/master → prod GPU 机(sf5-gpu-01)重建 content-harvester 容器
# (与主站 AIautomation 的 deploy.yml 一致的分支→机器分流)
on:
push:
branches:
- dev
- main
- master
workflow_dispatch:
jobs:
deploy:
name: Build and deploy
runs-on: ${{ github.ref == 'refs/heads/dev' && 'srv1563674' || 'sf5-gpu-01' }}
env:
IMAGE: content-harvester
CONTAINER: content-harvester
HOST_PORT: "8019" # 主机端口(主要给本机调试用)
DOCKER_NETWORK: ai-admin-cuiyue_default # 跟主站 backend 同一个 docker 网络
PROFILE_VOLUME: content-harvester-profile # 持久浏览器资料目录(过 Cloudflare 用)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare env file
env:
CH_ENV_FILE: ${{ secrets.CH_ENV_FILE }}
run: |
set -euo pipefail
if [ -n "${CH_ENV_FILE:-}" ]; then
printf '%s\n' "$CH_ENV_FILE" > .env
fi
test -f .env || {
echo "Missing .env — 请在该仓库的 Gitea Actions secrets 里加一个 'CH_ENV_FILE',内容形如:"
echo " HARVESTER_TOKEN=..."
echo " MINIO_ENDPOINT=https://minio.aidfxn.com"
echo " MINIO_BUCKET=clawlerdata"
echo " MINIO_ACCESS_KEY=..."
echo " MINIO_SECRET_KEY=..."
exit 1
}
# 只打 key 名,不打值
echo "env keys: $(grep -oE '^[A-Za-z_][A-Za-z0-9_]*' .env | paste -sd, -)"
- name: Show docker info
run: docker --version
- name: Build image
run: docker build -t "$IMAGE:latest" .
- name: Recreate container
run: |
set -euo pipefail
docker rm -f "$CONTAINER" >/dev/null 2>&1 || true
docker run -d \
--name "$CONTAINER" \
--restart unless-stopped \
--network "$DOCKER_NETWORK" \
-p "${HOST_PORT}:8000" \
--env-file .env \
-v "${PROFILE_VOLUME}:/data/browser_profile" \
--memory=2g --cpus=2 \
"$IMAGE:latest"
- name: Health check
run: |
set -e
for i in $(seq 1 20); do
if docker exec "$CONTAINER" python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=3).read()" >/dev/null 2>&1; then
echo "healthz ok"
docker ps --filter "name=$CONTAINER" --format '{{.Names}} | {{.Status}} | {{.Ports}}'
exit 0
fi
echo "waiting for healthz... ($i/20)"
sleep 3
done
echo "health check failed"
docker logs --tail 80 "$CONTAINER" || true
exit 1
- name: Cleanup env file
if: always()
run: rm -f .env
- name: Prune dangling images
if: always()
run: docker image prune -f >/dev/null 2>&1 || true