d562b07027
+ add boilerplate
130 lines
3.4 KiB
Markdown
130 lines
3.4 KiB
Markdown
# Barotrauma Admin
|
|
|
|
Ktor + Exposed + PostgreSQL backend for managing game-server tasks and executing remote commands.
|
|
|
|
---
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
src/main/kotlin/com/nano/
|
|
├── main.kt # Application entry point + DI wiring
|
|
├── Routing.kt # HTTP routes (tasks, exec)
|
|
├── model/
|
|
│ ├── Task.kt # Task domain model + TaskStatus enum
|
|
│ └── ExecutorResult.kt
|
|
├── db/
|
|
│ ├── DatabaseConfig.kt # HikariCP + Exposed Database setup
|
|
│ └── Tables.kt # Exposed Table definitions (TaskTable)
|
|
├── repository/
|
|
│ └── TaskRepository.kt # CRUD operations on TaskTable, returns model objects
|
|
├── service/
|
|
│ └── TaskService.kt # Business logic: create, list, cancel tasks
|
|
└── executor/
|
|
└── Executor.kt # Bash command runner with log streaming
|
|
```
|
|
|
|
### Layer flow
|
|
```
|
|
Model → DB (connection + table) → Repository → Service → Route
|
|
```
|
|
|
|
---
|
|
|
|
## Local Development
|
|
|
|
```bash
|
|
# Start PostgreSQL + app
|
|
docker compose up --build
|
|
|
|
# Or run app without Docker (needs local Postgres)
|
|
./gradlew run
|
|
```
|
|
|
|
App is served at `http://localhost:8080`.
|
|
|
|
### Environment variables
|
|
|
|
| Variable | Default | Description |
|
|
|---|---|---|
|
|
| `DATABASE_JDBC_URL` | `jdbc:postgresql://localhost:5432/barotrauma-admin` | PostgreSQL JDBC URL |
|
|
| `DATABASE_USER` | `postgres` | DB user |
|
|
| `DATABASE_PASSWORD` | `postgres` | DB password |
|
|
| `DATABASE_POOL_SIZE` | `10` | HikariCP pool size |
|
|
|
|
---
|
|
|
|
## API Endpoints
|
|
|
|
| Method | Path | Description |
|
|
|---|---|---|
|
|
| GET | `/` | Health check |
|
|
| GET | `/tasks` | List all tasks (`?status=RUNNING` to filter) |
|
|
| GET | `/tasks/{id}` | Get task by UUID |
|
|
| POST | `/tasks` | Create task `{"name":"...", "payload":"..."}` |
|
|
| POST | `/tasks/{id}/cancel` | Cancel task |
|
|
| DELETE | `/tasks/{id}` | Delete task |
|
|
| POST | `/exec` | Run bash command `{"command":"ls -la"}` |
|
|
|
|
---
|
|
|
|
## CI/CD (Gitea Actions)
|
|
|
|
The pipeline in `.gitea/workflows/ci.yaml` does:
|
|
|
|
1. **Build** — compiles the project, runs tests
|
|
2. **Docker** — builds image, pushes to registry
|
|
3. **Deploy** — SSHes to target host, pulls image, restarts via `docker-compose.remote.yml`
|
|
|
|
### Required secrets in Gitea
|
|
|
|
| Secret | Description |
|
|
|---|---|
|
|
| `REGISTRY_URL` | Container registry host (e.g. `gitea.example.com`) |
|
|
| `REGISTRY_USER` | Registry username |
|
|
| `REGISTRY_PASSWORD` | Registry token / password |
|
|
| `DEPLOY_HOST` | Remote server hostname |
|
|
| `DEPLOY_PORT` | SSH port (default 22) |
|
|
| `DEPLOY_USER` | Remote SSH user |
|
|
| `DEPLOY_SSH_KEY` | Private SSH key for deployment |
|
|
| `DEPLOY_PATH` | Target directory on remote host |
|
|
| `DATABASE_JDBC_URL` | Production JDBC URL |
|
|
| `DATABASE_USER` | Production DB user |
|
|
| `DATABASE_PASSWORD` | Production DB password |
|
|
|
|
### Required variables in Gitea
|
|
|
|
| Variable | Default | Description |
|
|
|---|---|---|
|
|
| `DATABASE_POOL_SIZE` | `10` | Connection pool size |
|
|
| `HOST_PORT` | `8080` | Host port mapping |
|
|
|
|
### Runner tag
|
|
|
|
Pipeline uses `runs-on: ubuntu-24.04`. Register your Gitea runner with:
|
|
|
|
```bash
|
|
gitea actions runner register --labels "ubuntu-24.04:docker://node:20-bookworm"
|
|
```
|
|
|
|
---
|
|
|
|
## Remote deployment
|
|
|
|
On the target host, place `docker-compose.remote.yml` and a `.env` file with the variables listed above.
|
|
|
|
```bash
|
|
docker compose -f docker-compose.remote.yml pull
|
|
docker compose -f docker-compose.remote.yml up -d
|
|
```
|
|
|
|
---
|
|
|
|
## Building locally
|
|
|
|
```bash
|
|
./gradlew build
|
|
./gradlew test
|
|
./gradlew installDist
|
|
```
|