feat(apk): 增加公开APK管理接口和CI/CD工作流
Some checks failed
Build Updates Server / build (push) Failing after 10s
Build Updates Server / build-docker (push) Has been skipped

- 新增获取最新APK版本信息和下载APK的公开接口
- 更新README文档,添加APK管理接口的使用说明
- 实现CI/CD工作流,支持自动构建和部署
- 优化APK存储逻辑,确保只保留最新APK文件
This commit is contained in:
lafay
2026-03-26 03:29:44 +08:00
parent fc09fdf8f2
commit 3ac1a2ccf5
8 changed files with 289 additions and 1 deletions

View File

@@ -46,6 +46,30 @@ https://updates.littlelan.cn
- 支持 `expo-expect-signature`
- `GET /api/assets?asset=...&runtimeVersion=...&platform=...`
## APK 管理接口(公开)
### 获取最新 APK 版本信息
`GET /api/apk/latest`
返回最新 APK 的版本信息,用于客户端检查更新。
```json
{
"runtimeVersion": "1.0.11",
"versionName": "1.0.11",
"size": 52428800,
"downloadUrl": "https://updates.littlelan.cn/api/apk/download?runtimeVersion=1.0.11",
"createdAt": "2026-03-26T00:00:00Z"
}
```
### 下载 APK
`GET /api/apk/download?runtimeVersion=<runtimeVersion>`
下载指定版本的 APK 文件。
## 管理接口(上传/CI
### 1) 发布 zip
@@ -83,6 +107,22 @@ curl "https://updates.littlelan.cn/admin/releases?runtimeVersion=2" \
-H "Authorization: Bearer dev-token"
```
### 4) 上传 APK
`POST /admin/apk/upload?runtimeVersion=<runtimeVersion>`
- Header`Authorization: Bearer <ADMIN_TOKEN>`
- Content-Type`application/vnd.android.package-archive``application/octet-stream`
- BodyAPK 二进制文件
```bash
curl -X POST \
"https://updates.littlelan.cn/admin/apk/upload?runtimeVersion=1.0.11" \
-H "Authorization: Bearer dev-token" \
-H "Content-Type: application/vnd.android.package-archive" \
--data-binary @app-release.apk
```
## CI 示例思路
1. 在客户端跑 `npx expo export`
@@ -91,6 +131,33 @@ curl "https://updates.littlelan.cn/admin/releases?runtimeVersion=2" \
可直接参考根目录新增工作流:`.github/workflows/go-updates-server-ci.yml`
## CI/CD
项目使用 Gitea Actions 进行持续集成和部署:
### Build Workflow (`.gitea/workflows/build.yml`)
- 触发条件push 到 master/main 分支,或 PR
- 步骤:
1. 编译 Go 二进制文件
2. 构建 Docker 镜像
3. 推送到私有镜像仓库 `code.littlelan.cn/carrot_bbs/updates-server`
### Deploy Workflow (`.gitea/workflows/deploy.yml`)
- 触发条件PR 合并到 master/main或手动触发
- 步骤:
1. SSH 到服务器
2. 拉取最新镜像
3. 重启容器
### 所需 Secrets
- `GIT_USERNAME` - Gitea 用户名
- `GIT_TOKEN` - Gitea Token用于推送镜像
- `SERVER_PASSWORD` - 服务器 SSH 密码
- `UPDATES_ADMIN_TOKEN` - 管理接口 Token
## Docker 打包与运行
### 1) 构建镜像并导出 tar