Files
cluster/internal/api/api.go
loveuer 29088a6b54 feat: complete OCI registry implementation with docker push/pull support
A lightweight OCI (Open Container Initiative) registry implementation written in Go.
2025-11-09 22:50:13 +08:00

62 lines
1.2 KiB
Go

package api
import (
"context"
"fmt"
"log"
"net"
"gitea.loveuer.com/loveuer/cluster/internal/middleware"
"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 {
var (
err error
ln net.Listener
cfg = fiber.Config{
BodyLimit: 1024 * 1024 * 1024 * 10, // 10GB limit for large image layers
}
)
app := fiber.New(cfg)
app.Use(middleware.Logger())
app.Use(middleware.Recovery())
app.Use(middleware.CORS())
// 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))
}
ln, err = net.Listen("tcp", address)
if err != nil {
return 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)
}
}()
go func() {
<-ctx.Done()
if err := app.Shutdown(); err != nil {
log.Fatalf("Failed to shutdown: %v", err)
}
}()
return nil
}