Backend: - Add registry_address configuration API (GET/POST) - Add tar image upload with OCI and Docker format support - Add image download with streaming optimization - Fix blob download using c.Send (Fiber v3 SendStream bug) - Add registry_address prefix stripping for all OCI v2 endpoints - Add AGENTS.md for project documentation Frontend: - Add settings store with Snackbar notifications - Add image upload dialog with progress bar - Add download state tracking with multi-stage feedback - Replace alert() with MUI Snackbar messages - Display image names without registry_address prefix 🤖 Generated with [Qoder](https://qoder.com)
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
|
|
"gitea.loveuer.com/loveuer/cluster/internal/middleware"
|
|
"gitea.loveuer.com/loveuer/cluster/internal/model"
|
|
"gitea.loveuer.com/loveuer/cluster/internal/module/registry"
|
|
"gitea.loveuer.com/loveuer/cluster/pkg/store"
|
|
"github.com/gofiber/fiber/v3"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func Init(ctx context.Context, address string, db *gorm.DB, store store.Store) (func(context.Context) error, error) {
|
|
var (
|
|
err error
|
|
ln net.Listener
|
|
cfg = fiber.Config{
|
|
BodyLimit: 1024 * 1024 * 1024 * 10, // 10GB limit for large image layers
|
|
}
|
|
fn func(context.Context) error
|
|
)
|
|
|
|
app := fiber.New(cfg)
|
|
|
|
app.Use(middleware.Logger())
|
|
app.Use(middleware.Recovery())
|
|
app.Use(middleware.CORS())
|
|
|
|
// Ensure database migration for RegistryConfig
|
|
// This is done here to ensure the table exists before config APIs are called
|
|
if err := db.AutoMigrate(&model.RegistryConfig{}); err != nil {
|
|
log.Printf("Warning: failed to migrate RegistryConfig: %v", err)
|
|
}
|
|
|
|
// oci image apis
|
|
{
|
|
app.All("/v2/*", registry.Registry(ctx, db, store))
|
|
}
|
|
|
|
// registry image apis
|
|
{
|
|
registryAPI := app.Group("/api/v1/registry")
|
|
registryAPI.Get("/image/list", registry.RegistryImageList(ctx, db, store))
|
|
registryAPI.Get("/image/download/*", registry.RegistryImageDownload(ctx, db, store))
|
|
registryAPI.Post("/image/upload", registry.RegistryImageUpload(ctx, db, store))
|
|
// registry config apis
|
|
registryAPI.Get("/config", registry.RegistryConfigGet(ctx, db, store))
|
|
registryAPI.Post("/config", registry.RegistryConfigSet(ctx, db, store))
|
|
}
|
|
|
|
ln, err = net.Listen("tcp", address)
|
|
if err != nil {
|
|
return fn, fmt.Errorf("failed to listen on %s: %w", address, err)
|
|
}
|
|
|
|
go func() {
|
|
if err = app.Listener(ln); err != nil {
|
|
log.Fatalf("Fiber server failed on %s: %v", address, err)
|
|
}
|
|
}()
|
|
|
|
fn = func(_ctx context.Context) error {
|
|
log.Println("[W] service shutdown...")
|
|
if err = app.ShutdownWithContext(_ctx); err != nil {
|
|
return fmt.Errorf("[E] service shutdown failed, err = %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
return fn, nil
|
|
}
|