docs: update README for .env-optional deployment and first-time setup flow
- .env is now optional — deployment works with docker compose up --build directly - First user registers as admin through initial setup page - Add verification steps for auth/status and auth/setup endpoints
This commit is contained in:
40
README.md
40
README.md
@ -120,28 +120,22 @@ GOSUMDB=sum.golang.google.cn
|
||||
|
||||
## 推荐部署流程
|
||||
|
||||
当前只有一个推荐启动入口:在项目根目录执行 `make up`。它会启动同一套完整 Docker Compose 栈:
|
||||
|
||||
- `postgres`:数据库,常驻服务。
|
||||
- `backend`:Go API,常驻服务,宿主机默认端口 `18081`。
|
||||
- `frontend-build`:一次性构建任务,构建完成后退出是正常现象。
|
||||
- `nginx`:统一 Web 入口,常驻服务,宿主机默认端口 `18080`;前端静态文件和 `/api/*` 都从这里访问。
|
||||
|
||||
所以看到 `frontend-build` 处于 `Exited (0)` 不代表前端没运行;前端由 `nginx` 服务。正常运行时至少应看到 `postgres`、`backend`、`nginx` 三个容器为 `Up`。
|
||||
`.env` 文件为可选配置。不提供 `.env` 时,系统以空白状态启动,首次访问时展示管理员注册页面(Setup),第一个注册用户即为管理员。
|
||||
|
||||
```bash
|
||||
# 1. 在根目录检查 .env
|
||||
ls .env
|
||||
# 1. 克隆代码
|
||||
git clone https://gitea.bwgdi.com/OCDP/ocdp-go.git
|
||||
cd ocdp-go
|
||||
|
||||
# 2. 如果默认高位端口被其他项目占用,先换端口;不要杀其他项目进程
|
||||
export WEB_HTTP_PORT=18080
|
||||
export WEB_HTTPS_PORT=18443
|
||||
export BACKEND_PORT=18081
|
||||
export POSTGRES_PORT=15432
|
||||
|
||||
# 3. 构建并后台启动完整平台
|
||||
# 2. 构建并后台启动完整平台(无需 .env)
|
||||
make up
|
||||
|
||||
# 3. 打开浏览器访问 http://<host>:18080
|
||||
# 首次访问会看到 Initial Setup 页面,创建管理员账号和密码即可开始使用
|
||||
```
|
||||
|
||||
有 `.env` 时,可以预注入初始管理员账号、Registry 和 Cluster(用于开发/测试):
|
||||
|
||||
# 4. 查看服务;postgres/backend/nginx 应为 Up,frontend-build Exited(0) 正常
|
||||
make docker-ps
|
||||
```
|
||||
@ -178,10 +172,18 @@ docker compose ps -a
|
||||
curl http://localhost:${BACKEND_PORT:-18081}/health
|
||||
curl http://localhost:${WEB_HTTP_PORT:-18080}/healthz
|
||||
|
||||
# 登录,返回 token。把 password 替换成 .env 里的 BOOTSTRAP_ADMIN_PASS。
|
||||
# 检查是否需要初始化管理员(无 .env 部署时返回 needsSetup: true)
|
||||
curl http://localhost:${BACKEND_PORT:-18081}/api/v1/auth/status
|
||||
|
||||
# 初始化管理员账号(仅限尚无管理员时可用)
|
||||
curl -s -X POST http://localhost:${BACKEND_PORT:-18081}/api/v1/auth/setup \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"admin","password":"your-password"}'
|
||||
|
||||
# 登录
|
||||
curl -s -X POST http://localhost:${BACKEND_PORT:-18081}/api/v1/auth/login \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"admin","password":"<BOOTSTRAP_ADMIN_PASS>"}'
|
||||
-d '{"username":"admin","password":"your-password"}'
|
||||
|
||||
# 查看 bootstrap 是否生效,需要带 Bearer token
|
||||
curl http://localhost:${BACKEND_PORT:-18081}/api/v1/registries \
|
||||
|
||||
Reference in New Issue
Block a user