Skip to content

Commit ab0480e

Browse files
init
1 parent dd8413b commit ab0480e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+8610
-21
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
# Publish semver tags as releases.
7+
tags: ["v*.*.*"]
8+
pull_request:
9+
branches: ["master"]
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ghcr.io/getstream/tikv-ui
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
id-token: write
22+
strategy:
23+
matrix:
24+
platform:
25+
- linux/amd64
26+
- linux/arm64
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Install cosign
33+
if: github.event_name != 'pull_request'
34+
uses: sigstore/cosign-installer@v3.5.0
35+
with:
36+
cosign-release: "v2.2.4"
37+
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v3
40+
41+
- name: Log into registry ${{ env.REGISTRY }}
42+
if: github.event_name != 'pull_request'
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ${{ env.REGISTRY }}
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Extract Docker metadata
50+
id: meta
51+
uses: docker/metadata-action@v5
52+
with:
53+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
54+
55+
- name: Build and push Docker image
56+
id: build-and-push
57+
uses: docker/build-push-action@v5
58+
with:
59+
context: .
60+
push: ${{ github.event_name != 'pull_request' }}
61+
tags: ${{ steps.meta.outputs.tags }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
cache-from: type=gha
64+
cache-to: type=gha,mode=max
65+
66+
- name: Sign the published Docker image
67+
if: ${{ github.event_name != 'pull_request' }}
68+
env:
69+
TAGS: ${{ steps.meta.outputs.tags }}
70+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
71+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

.gitignore

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
!.yarn/sdks
66
!.yarn/versions
77

8-
# Whether you use PnP or not, the node_modules folder is often used to store
9-
# build artifacts that should be gitignored
108
node_modules
119

12-
# Swap the comments on the following lines if you wish to use zero-installs
13-
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
14-
# Documentation here: https://yarnpkg.com/features/caching#zero-installs
1510

1611
#!.yarn/cache
1712
.pnp.*
13+
14+
.bin/
15+
16+
bin/

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Stage 1: Build Frontend
2+
FROM node:20-alpine AS frontend-builder
3+
WORKDIR /app
4+
COPY app/package.json app/yarn.lock* app/package-lock.json* ./
5+
RUN npm install
6+
COPY app .
7+
# Allow setting API URL at build time, default to relative for same-origin serving
8+
ENV NEXT_PUBLIC_API_URL=""
9+
RUN npm run build
10+
11+
# Stage 2: Build Backend
12+
FROM golang:1.23-alpine AS backend-builder
13+
WORKDIR /app
14+
COPY go.mod go.sum ./
15+
RUN go mod download
16+
COPY . .
17+
RUN CGO_ENABLED=0 GOOS=linux go build -o server cmd/main.go
18+
19+
# Stage 3: Final Image
20+
FROM alpine:latest
21+
WORKDIR /app
22+
RUN apk --no-cache add ca-certificates
23+
24+
COPY --from=backend-builder /app/server .
25+
# Copy static frontend files to ./public which the Go server expects
26+
COPY --from=frontend-builder /app/out ./public
27+
28+
EXPOSE 8081
29+
CMD ["./server"]

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: dev backend frontend
2+
3+
# Default target
4+
dev:
5+
$(MAKE) -j 2 backend frontend
6+
7+
backend:
8+
go run cmd/main.go
9+
10+
frontend:
11+
cd app && yarn dev

README.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# TiKV UI
2+
3+
A REST API server for exploring and managing TiKV key-value data with multi-cluster support.
4+
5+
## Project Structure
6+
7+
```
8+
tikv-ui/
9+
├── cmd/
10+
│ └── tikv-ui/
11+
│ └── main.go # Application entry point
12+
├── pkg/
13+
│ ├── handlers/ # HTTP request handlers
14+
│ │ ├── health.go # Health check endpoint
15+
│ │ ├── cluster.go # Cluster management
16+
│ │ ├── get.go # GET operation
17+
│ │ ├── put.go # PUT operation
18+
│ │ ├── delete.go # DELETE operation
19+
│ │ └── scan.go # SCAN operation
20+
│ ├── server/ # Server setup and middleware
21+
│ │ ├── server.go # Server struct with multi-cluster support
22+
│ │ └── middleware.go # HTTP middleware (logging, etc.)
23+
│ ├── types/ # Type definitions
24+
│ │ ├── requests.go # API request types
25+
│ │ └── responses.go # API response types
26+
│ └── utils/ # Utility functions
27+
│ ├── http.go # HTTP helpers (JSON responses, errors)
28+
│ ├── msgpack.go # Msgpack/JSON parsing
29+
│ └── string.go # String manipulation utilities
30+
├── go.mod
31+
├── go.sum
32+
└── README.md
33+
```
34+
35+
## Building
36+
37+
```bash
38+
go build -o bin/tikv-ui ./cmd/tikv-ui
39+
```
40+
41+
## Running
42+
43+
Set the `TIKV_PD_ADDRS` environment variable with comma-separated PD addresses for the default cluster:
44+
45+
```bash
46+
export TIKV_PD_ADDRS="127.0.0.1:2379,127.0.0.1:23790"
47+
./bin/tikv-ui
48+
```
49+
50+
The server will start on port 8081 and connect to the default cluster.
51+
52+
## API Endpoints
53+
54+
### Health Check
55+
```
56+
GET /health
57+
```
58+
59+
### Cluster Management
60+
61+
#### Connect to New Cluster
62+
```
63+
POST /api/clusters/connect
64+
Body: {
65+
"pd_addrs": ["127.0.0.1:2379", "127.0.0.1:23790"],
66+
"name": "production" // optional, auto-generated if not provided
67+
}
68+
```
69+
70+
#### List All Clusters
71+
```
72+
GET /api/clusters
73+
Response: {
74+
"clusters": [
75+
{
76+
"name": "default",
77+
"cluster_id": 123456,
78+
"pd_addrs": ["127.0.0.1:2379"],
79+
"active": true
80+
}
81+
]
82+
}
83+
```
84+
85+
#### Switch Active Cluster
86+
```
87+
POST /api/clusters/switch
88+
Body: {"name": "production"}
89+
```
90+
91+
### Raw KV Operations
92+
93+
All operations use the currently active cluster.
94+
95+
#### Get Value
96+
```
97+
POST /api/raw/get
98+
Body: {"key": "mykey"}
99+
Response: {
100+
"key": "mykey",
101+
"value": {...}, // parsed msgpack/JSON
102+
"raw_value": "...", // raw string
103+
"found": true
104+
}
105+
```
106+
107+
#### Put Value
108+
```
109+
POST /api/raw/put
110+
Body: {"key": "mykey", "value": "myvalue"}
111+
```
112+
113+
#### Delete Key
114+
```
115+
POST /api/raw/delete
116+
Body: {"key": "mykey"}
117+
```
118+
119+
#### Scan Range
120+
```
121+
POST /api/raw/scan
122+
Body: {"start_key": "a", "end_key": "z", "limit": 100}
123+
Response: {
124+
"items": [
125+
{
126+
"key": "key1",
127+
"value": {...}, // parsed msgpack/JSON
128+
"raw_value": "..." // raw string
129+
}
130+
]
131+
}
132+
```
133+
134+
## Features
135+
136+
### Multi-Cluster Support
137+
- Connect to multiple TiKV clusters dynamically via API
138+
- Switch between clusters without restarting the server
139+
- Each cluster maintains its own connection pool
140+
- Thread-safe cluster management
141+
142+
### Smart Value Parsing
143+
- Automatically detects and parses msgpack-encoded values
144+
- Falls back to JSON parsing if msgpack fails
145+
- Returns both parsed (structured) and raw (string) values
146+
- Handles plain text values correctly
147+
148+
### Graceful Shutdown
149+
- Properly closes all cluster connections on shutdown
150+
- Handles SIGINT and SIGTERM signals
151+
152+
## Architecture
153+
154+
The project follows a clean architecture pattern:
155+
156+
- **cmd/**: Application entry points (main packages)
157+
- **pkg/handlers/**: HTTP handlers organized by operation
158+
- **pkg/server/**: Server configuration, middleware, and multi-cluster management
159+
- **pkg/types/**: Shared type definitions
160+
- **pkg/utils/**: Reusable utility functions
161+
162+
This structure provides:
163+
- Clear separation of concerns
164+
- Easy testing (each handler can be tested independently)
165+
- Maintainability (changes are localized to specific packages)
166+
- Scalability (easy to add new handlers or utilities)

app/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts

app/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

0 commit comments

Comments
 (0)