feat: basic firmware registry

This commit is contained in:
2025-10-21 14:27:21 +02:00
commit 986745d8c8
20 changed files with 1831 additions and 0 deletions

129
README.md Normal file
View File

@@ -0,0 +1,129 @@
# SPORE Registry
The SPORE registry is a storage backend and update server for managing versioned firmware binaries in the SPORE embedded system ecosystem.
## Overview
The registry provides:
- **Hierarchical Storage**: Firmware binaries stored as `registry/{name}/{version}/firmware.bin`
- **SQLite Database**: Metadata storage with labels for flexible querying
- **REST API**: Simple HTTP endpoints for upload, listing, and download
- **Version Management**: Semantic versioning support
## Quick Start
### Prerequisites
- Go 1.22 or later
### Installation
1. Clone the repository:
```bash
git clone <repository-url>
cd spore-registry
```
2. Install dependencies:
```bash
go mod download
```
3. Run the server:
```bash
go run main.go
```
The server will start on port 8080 by default (or use `PORT` environment variable to change it).
## API Endpoints
### Upload Firmware
```bash
curl -X POST http://localhost:8080/firmware \
-F "metadata={\"name\":\"base\",\"version\":\"1.0.0\",\"labels\":{\"app\":\"base\"}}" \
-F "firmware=@firmware.bin"
```
### List Firmware
```bash
# Get all firmware
curl http://localhost:8080/firmware
# Filter by name
curl "http://localhost:8080/firmware?name=base"
# Filter by version
curl "http://localhost:8080/firmware?version=1.0.0"
```
### Download Firmware
```bash
curl http://localhost:8080/firmware/base/1.0.0 -o firmware.bin
```
### Health Check
```bash
curl http://localhost:8080/health
```
## Storage Structure
Firmware binaries are stored hierarchically:
```
registry/
├── base/
│ ├── 1.0.0/
│ │ └── firmware.bin
│ └── 1.1.0/
│ └── firmware.bin
└── sensor/
└── 2.0.0/
└── firmware.bin
```
## Configuration
The registry uses the following environment variables:
- `PORT`: Server port (default: 8080)
## Database Schema
The SQLite database contains a `firmware` table:
```sql
CREATE TABLE firmware (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
version TEXT NOT NULL,
size INTEGER NOT NULL,
labels TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE(name, version)
);
```
## API Documentation
Full OpenAPI specification is available in `api/openapi.yaml`.
## Development
### Building
```bash
go build -o spore-registry main.go
```
### Testing
```bash
go test ./...
```
### Code Structure
- `main.go` - Main application with HTTP server and API handlers
- `api/openapi.yaml` - OpenAPI specification
- `registry/` - Firmware storage directory (created automatically)
- `registry.db` - SQLite database (created automatically)
## License
MIT License - see LICENSE file for details.