feat: add registry config, image upload/download, and OCI format support
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)
This commit is contained in:
@@ -7,19 +7,21 @@ import (
|
||||
"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) error {
|
||||
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)
|
||||
@@ -28,6 +30,12 @@ func Init(ctx context.Context, address string, db *gorm.DB, store store.Store) e
|
||||
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))
|
||||
@@ -37,25 +45,32 @@ func Init(ctx context.Context, address string, db *gorm.DB, store store.Store) e
|
||||
{
|
||||
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 fmt.Errorf("failed to listen on %s: %w", address, err)
|
||||
return fn, fmt.Errorf("failed to listen on %s: %w", address, err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := app.Listener(ln); err != nil {
|
||||
if err = app.Listener(ln); err != nil {
|
||||
log.Fatalf("Fiber server failed on %s: %v", address, err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if err := app.Shutdown(); err != nil {
|
||||
log.Fatalf("Failed to shutdown: %v", 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 nil
|
||||
}
|
||||
|
||||
return fn, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user