Skip to content

Commit ff52e0a

Browse files
committed
feat: web app, CI, and GitHub Actions multi-platform release
Made-with: Cursor
1 parent af42014 commit ff52e0a

33 files changed

Lines changed: 2018 additions & 311 deletions

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
22+
- name: go mod verify
23+
run: go mod verify
24+
25+
- name: go vet
26+
run: go vet ./...
27+
28+
- name: go test
29+
run: go test ./...
30+
31+
- name: Verify offline static assets
32+
run: go run ./scripts/check_offline_urls.go

.github/workflows/release.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
env:
15+
VERSION: ${{ github.ref_name }}
16+
LDFLAGS: -s -w
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: go.mod
27+
28+
- name: Verify offline static assets
29+
run: go run ./scripts/check_offline_urls.go
30+
31+
- name: Build and archive
32+
run: |
33+
set -euo pipefail
34+
mkdir -p dist build
35+
pack_tar() {
36+
local goos=$1 goarch=$2
37+
local slug="mini-dba-${VERSION}-${goos}-${goarch}"
38+
local dir="build/${slug}"
39+
rm -rf "${dir}"
40+
mkdir -p "${dir}"
41+
GOOS="${goos}" GOARCH="${goarch}" CGO_ENABLED=0 \
42+
go build -ldflags="${LDFLAGS}" -o "${dir}/mini-dba" .
43+
cp LICENSE README.md config.example.yaml "${dir}/"
44+
tar -czf "dist/${slug}.tar.gz" -C "${dir}" .
45+
}
46+
pack_zip() {
47+
local goos=$1 goarch=$2
48+
local slug="mini-dba-${VERSION}-${goos}-${goarch}"
49+
local dir="build/${slug}"
50+
rm -rf "${dir}"
51+
mkdir -p "${dir}"
52+
GOOS="${goos}" GOARCH="${goarch}" CGO_ENABLED=0 \
53+
go build -ldflags="${LDFLAGS}" -o "${dir}/mini-dba.exe" .
54+
cp LICENSE README.md config.example.yaml "${dir}/"
55+
(cd "${dir}" && zip -q -r "../../dist/${slug}.zip" .)
56+
}
57+
pack_tar linux amd64
58+
pack_tar linux arm64
59+
pack_zip windows amd64
60+
pack_zip windows arm64
61+
pack_tar darwin amd64
62+
pack_tar darwin arm64
63+
( cd dist && sha256sum *.tar.gz *.zip > "mini-dba_${VERSION}_checksums.txt" )
64+
65+
- name: Publish GitHub Release
66+
uses: softprops/action-gh-release@v2
67+
with:
68+
name: ${{ github.ref_name }}
69+
files: |
70+
dist/*.tar.gz
71+
dist/*.zip
72+
dist/mini-dba_*_checksums.txt
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

AGENT.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,52 @@
44

55
## 产品定位
66

7-
- **Go 单二进制**,内网轻量 MySQL 运维 Web:**执行 SQL**表元数据、分页浏览、多连接(DSN)配置
8-
- **`config.yaml`**`secret_key`网页登录 / 后续 API 放行)、`databases`(DSN)、`readonly` 等。
9-
- **前端**MUI 取向的 Material 风,服务端模板 + 随包静态资源(无公网 CDN);当前 **`web/demo/`** 为定稿用静态 Demo,**`cmd/demo`** 提供登录与静态托管
7+
- **Go 单二进制**,内网轻量 MySQL 运维 Web:**执行 SQL**表列表、表结构、分页浏览、多连接(DSN)**`/settings` 保存写回 `config.yaml`**
8+
- **`config.yaml`**`secret_key``/login` 与会话 Cookie;亦可 **`X-MiniDBA-Secret`** / **`Authorization: Bearer`**)、`databases`(DSN)、`readonly``max_result_rows` 等。
9+
- **前端**`html/template` + [`web/static/css/theme.css`](web/static/css/theme.css)**`go:embed`** 打包 `web/templates``web/static`。历史目录 **`web/demo/`** 仅作可选参考,正式路由以主程序为准
1010

11-
## 仓库结构(预期演进)
11+
## 仓库结构
1212

1313
```text
14-
main.go # 正式入口(当前占位)
15-
cmd/demo/ # UI 预览:secret_key 登录 + 静态页
16-
internal/ # 正式开发:handler / service / dao / config(待建)
17-
web/demo/ # 静态 Demo HTML
18-
web/static/css/ # theme.css,可迁模板后复用
19-
docs/DESIGN.md # 设计规格
20-
config.example.yaml # 可提交的示例配置(复制为 config.yaml)
14+
main.go # 入口:-config 指定 yaml
15+
internal/
16+
auth/ # HMAC 会话、Header 放行
17+
csrf/ # Double-submit Cookie
18+
config/ # 加载/校验/原子保存
19+
dbmgr/ # 连接池与热重载
20+
server/ # 路由与页面
21+
sqlrun/ # 只读/黑名单/执行
22+
web/templates/ # 布局与各页
23+
web/static/ # 主题 CSS
24+
docs/DESIGN.md
25+
config.example.yaml
2126
```
2227

2328
## 本地命令
2429

2530
| 用途 | 命令 |
2631
|------|------|
27-
| UI Demo | 根目录:复制 `config.example.yaml``config.yaml` 并设 `secret_key`,再 `task demo``go run ./cmd/demo` |
28-
| Demo 监听 / 配置 | `MINIDBA_DEMO_ADDR``MINIDBA_CONFIG`(默认 `config.yaml` |
29-
| 格式化 | `task golangci:fmt``go fmt ./...` |
30-
| 主程序占位 | `task run` `go run main.go` |
32+
| 运行 | 复制 `config.example.yaml``config.yaml``task run``go run . -config config.yaml` |
33+
| 测试 | `go test ./...` |
34+
| Linux 构建 | `task build``./release/minidba` |
35+
| 格式化 | `task golangci:fmt` / `go fmt ./...` |
3136

32-
## 配置与密钥
37+
## 配置说明
3338

34-
- **`config.yaml` 已加入 `.gitignore`,勿提交。** 团队仅用 **`config.example.yaml`** 入库。
35-
- 含真实 `secret_key`、DSN 密码的文件限制权限,与设计文档 §7 一致。
39+
- **`config.yaml` 勿提交**(见 `.gitignore`);团队以 **`config.example.yaml`** 为范本。
40+
- **`config.Save` 整文件重写后 YAML 注释会丢失**(MVP 已知限制)。
41+
- 修改 **`secret_key` 仅手改文件并重启进程**,设置页不轮换该字段。
3642

3743
## 编码约定
3844

39-
- **Go 版本**:见 `go.mod`
40-
- **改动范围**:与设计/MVP 相关;避免无关大范围重构。
41-
- **依赖**:新增依赖保持理由清晰;离线构建与设计 §4 一致。
42-
- **正式 HTTP**:设计文档 §9(`/login``/logout``/query``/settings` 等);Demo 路由以 `cmd/demo` 为准直至合并进主程序。
45+
- 改动与设计/MVP 对齐;避免无关大范围重构。
46+
- 所有 **POST**(除 `/login`)需 **CSRF**;业务接口需 **`secret_key` 会话或 Header**
4347

4448
## 代理工作协议(建议)
4549

46-
1. 接到需求时先核对 **`docs/DESIGN.md`** 对应章节
50+
1. 接到需求时先核对 **`docs/DESIGN.md`**
4751
2. 改配置模型或安全行为时,同步更新 **设计文档 + `config.example.yaml`**
48-
3. UI 变更可先对齐 **`web/demo`****`web/static/css/theme.css`**,再接入 `html/template`
52+
3. 样式以 **`theme.css`** 与现有模板块为准
4953

5054
---
5155

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 MiniDBA contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MiniDBA
2+
3+
内网场景下的轻量 MySQL Web 运维小工具(Go,单二进制 + 本地配置)。设计说明见 [docs/DESIGN.md](docs/DESIGN.md)
4+
5+
## 运行(开发)
6+
7+
```bash
8+
go run . -config config.yaml
9+
```
10+
11+
或使用 [Task](https://taskfile.dev/)
12+
13+
```bash
14+
task run
15+
```
16+
17+
`config.example.yaml` 复制为 `config.yaml`,设置 `secret_key``databases`
18+
19+
## 构建与发版
20+
21+
- 本地 Linux amd64:`task build`
22+
- 发版流程(GitHub Actions,推送 `v*` tag):见 [docs/RELEASE.md](docs/RELEASE.md)
23+
24+
预编译包见 **GitHub Releases**

Taskfile.yaml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
version: "3"
44

55
tasks:
6-
demo:
7-
desc: "预览 UI 静态 Demo(127.0.0.1:18899,须在仓库根目录)"
8-
cmds:
9-
- go run ./cmd/demo
10-
116
run:
12-
desc: "启动应用"
7+
desc: "启动 MiniDBA(默认读取 ./config.yaml)"
138
cmds:
149
- task golangci:fmt
15-
- go run main.go
16-
10+
- go run . -config config.yaml
1711

1812
build:
19-
desc: "构建 Linux 二进制(从任意平台交叉编译"
13+
desc: "构建 Linux 单二进制(嵌入模板与静态资源"
2014
env:
2115
CGO_ENABLED: "0"
2216
GOOS: "linux"
2317
GOARCH: "amd64"
2418
cmds:
2519
- task: golangci:fmt
2620
- go env GOOS GOARCH CGO_ENABLED
27-
- go build -ldflags="-s -w" -o ./release ./main.go
28-
# - docker build -t backend_admin:latest .
29-
# - docker save -o ./docker/registry/images/backend_admin.tar backend_admin:latest
21+
- go build -ldflags="-s -w" -o ./release/mini-dba .
22+
23+
release:verify-offline:
24+
desc: "检查 web 模板与静态资源是否引用公网字体 CDN(与 CI 门禁一致)"
25+
cmds:
26+
- go run ./scripts/check_offline_urls.go
27+
28+
release:tag:
29+
desc: "创建并推送版本 tag(触发 GitHub Release);用法 task release:tag VERSION=v0.1.0"
30+
requires:
31+
vars: [VERSION]
32+
cmds:
33+
- git tag -a {{.VERSION}} -m "Release {{.VERSION}}"
34+
- git push origin {{.VERSION}}
3035

31-
# golangci-lint 检查
3236
golangci:lint:
3337
desc: "运行 golangci-lint 检查"
3438
cmds:
3539
- golangci-lint run
3640

37-
# golangci-lint 检查
3841
golangci:fmt:
3942
desc: "运行 golangci-lint 格式化"
4043
cmds:
4144
- go fmt ./...
42-
43-
44-

0 commit comments

Comments
 (0)