ci: 修复 Gitea Actions 数据库连接(用服务名 postgres) #2

Merged
lixu merged 1 commits from devin/1781859199-ci-fix-postgres-host into main 2026-06-19 17:47:41 +08:00
Owner

背景

仓库 CI(Actions run #3)一直显示失败:三个 job 均 0s 被取消,根因是 该仓库没有注册任何 Actions Runner(设置→运行器 总计 0),任务排队后被取消。

注册 Runner 后重跑,又暴露出工作流本身的可移植性问题:

dial tcp [::1]:5432: connect: connection refused
(postgres://opengoods:opengoods@localhost:5432/opengoods)

原因

Gitea Actions 的 job 运行在容器内,service 容器需通过服务名postgres)访问;localhost:5432 是 GitHub Actions(job 直接跑在宿主机上)的约定,在 Gitea 容器化运行下连不通。此外 ports: 5432:5432 的宿主机端口映射既无必要,又会与宿主机已占用端口冲突(port already allocated)。

改动

gomigrations 两个 job:

  • 数据库 host localhostpostgres(service 名)
  • 移除多余的 ports: - "5432:5432" 映射

python job 不连库(DB 测试在无库时自动跳过),无需改动。

验证

本地已通过全部 CI 步骤:Go gofmt/vet/build/test、Python ruff+pytest(33 passed)、migrate up/down 可逆。本 PR 会在 Gitea Runner 上触发 CI 以验证修复。

## 背景 仓库 CI(Actions run #3)一直显示失败:三个 job 均 0s 被取消,根因是 **该仓库没有注册任何 Actions Runner**(设置→运行器 总计 0),任务排队后被取消。 注册 Runner 后重跑,又暴露出工作流本身的可移植性问题: ``` dial tcp [::1]:5432: connect: connection refused (postgres://opengoods:opengoods@localhost:5432/opengoods) ``` ## 原因 Gitea Actions 的 job 运行在**容器内**,service 容器需通过**服务名**(`postgres`)访问;`localhost:5432` 是 GitHub Actions(job 直接跑在宿主机上)的约定,在 Gitea 容器化运行下连不通。此外 `ports: 5432:5432` 的宿主机端口映射既无必要,又会与宿主机已占用端口冲突(`port already allocated`)。 ## 改动 `go` 和 `migrations` 两个 job: - 数据库 host `localhost` → `postgres`(service 名) - 移除多余的 `ports: - "5432:5432"` 映射 `python` job 不连库(DB 测试在无库时自动跳过),无需改动。 ## 验证 本地已通过全部 CI 步骤:Go gofmt/vet/build/test、Python ruff+pytest(33 passed)、migrate up/down 可逆。本 PR 会在 Gitea Runner 上触发 CI 以验证修复。
lixu added 1 commit 2026-06-19 16:55:04 +08:00
ci: connect to postgres via service hostname for Gitea Actions
CI / Go (api) (pull_request) Successful in 30s
CI / Python (ingestion) (pull_request) Successful in 7s
CI / Migrations (postgres) (pull_request) Successful in 16s
19b7c43f37
Gitea Actions runs jobs inside a container, so a service container is reachable by its service name (postgres), not localhost; localhost:5432 yields connection refused. Also drop the unnecessary 5432:5432 host port mapping that caused 'port already allocated' collisions.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
lixu merged commit e3e5c7979c into main 2026-06-19 17:47:41 +08:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lixu/goods#2