Deploy / Build and deploy (dev) (push) Successful in 1m40s
.gitea/workflows/deploy.yml:push 到 dev 分支(或 workflow_dispatch)→ dev 开发机 runner (标签 srv1563674)→ checkout → docker build → docker rm -f → docker run(env 走 --env-file .env, 内容来自 gitea repo secret CH_ENV_FILE)→ healthz 检查 → image prune。只触发 dev,master/prod 不碰。 部署参数(端口 8019 / 网络 ai-admin-cuiyue_default / 卷 content-harvester-profile / mem 2g)在 yml 的 env 块里。 DEPLOY.md / README.md 同步更新(dev 自动、prod 仍手动;前置:配 CH_ENV_FILE secret)。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
2.9 KiB
YAML
91 lines
2.9 KiB
YAML
name: Deploy
|
|
|
|
# push 到 dev 分支 → 在 dev 开发机上重新 build 镜像、重建 content-harvester 容器。
|
|
# (只管 dev;prod 仍手动部署 —— 见 DEPLOY.md。)
|
|
on:
|
|
push:
|
|
branches:
|
|
- dev
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
name: Build and deploy (dev)
|
|
# dev 开发机的 gitea runner 标签(与主站 AIautomation 的 deploy.yml 一致)
|
|
runs-on: srv1563674
|
|
|
|
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
|