No description
  • Go 86.7%
  • Dockerfile 13.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
ling ebf65ea412
All checks were successful
ci / build (push) Successful in 15s
ci: 修正注释里的仓库名笔误
2026-11-04 17:36:49 +00:00
.forgejo/workflows ci: 修正注释里的仓库名笔误 2026-11-04 17:36:49 +00:00
vendor build: vendor 依赖,构建不联网 2026-11-04 22:08:19 +08:00
.dockerignore feat: 初始版本(todo CI/CD 案例) 2026-11-04 18:09:18 +08:00
.gitignore feat: 初始版本(todo CI/CD 案例) 2026-11-04 18:09:18 +08:00
Dockerfile build: 运行层不再 apk add(底座已有 certs/tzdata) 2026-11-04 22:14:26 +08:00
go.mod feat: 初始版本(todo CI/CD 案例) 2026-11-04 18:09:18 +08:00
go.sum feat: 初始版本(todo CI/CD 案例) 2026-11-04 18:09:18 +08:00
main.go feat: 初始版本(todo CI/CD 案例) 2026-11-04 18:09:18 +08:00
README.md feat: 初始版本(todo CI/CD 案例) 2026-11-04 18:09:18 +08:00

todo-backend

CI/CD 案例里的后端。Go + database/sql + lib/pq,零传递依赖(集群出网很慢, 多一个间接依赖就多一层 go mod download 的风险)。

接口

方法 路径 说明
GET /healthz 探活,顺便 Ping 数据库
GET /api/todos 列表(按 id 倒序)
POST /api/todos 建一条,body {"title": "..."}
PATCH /api/todos/{id} 改,body {"title"?: ..., "done"?: ...}
DELETE /api/todos/{id} 删

环境变量

变量 默认 说明
PORT 8080 监听端口
DATABASE_URL 空 给了就用它(完整 DSN)
DB_HOST / DB_PORT todo-db.todo-data.svc.cluster.local / 5432 共享数据库
DB_USER / DB_PASSWORD todo_app / 空 来自 Secret todo-db-app
DB_NAME todo_prod 每个环境一个库,由 pipeline 写进 Secret

DB_* 这五个 key 就是 Secret todo-db-app 的 key,一一对应;todo-env-setup Pipeline 建环境时会把 todo-data 里的这份 Secret 复制进新命名空间,只改 dbname。

表结构

表由 todo-gitops 的 db-init Job 用 sql/0001_init.sql 建(todo_app 有 CREATEDB, 每个环境自己 CREATE DATABASE)。后端启动时 waitForDB 会一直等到表存在, 所以「Job 还没跑完」不会导致 CrashLoopBackOff。

schema 变更不走这个仓:改 DDL 请走 Bytebase 工单(SQL review + 审批 + 历史), 这也是案例里「审计」那一环。

CI

与 todo-web 同一套规则(见 .forgejo/workflows/ci.yaml): dev → :dev、release/v1.2 → :release-v1.2、hotfix/x → :hotfix-x、v1.2.3 → :v1.2.3, 另推 :sha-<12位> 不可变 tag。