Backend: - Add image fetch handler using go-containerregistry - Support HTTP/HTTPS and SOCKS5 proxy protocols - Pull images from remote registries (Docker Hub, etc.) - Store fetched images as blobs and manifests - Add timeout handling (60s for descriptor fetch) - Add detailed logging for pull progress - Add /api/v1/registry/image/fetch endpoint Frontend: - Add registry proxy configuration field - Add "获取镜像" button and dialog - Add proxy checkbox and input in fetch dialog - Add LinearProgress feedback during fetch - Add multi-stage Snackbar notifications - Auto-refresh image list after successful fetch - Fix download filename regex (remove trailing quote) - Adjust button colors for better UI consistency Dependencies: - Add github.com/google/go-containerregistry for OCI operations - Add golang.org/x/net/proxy for SOCKS5 support 🤖 Generated with [Qoder](https://qoder.com)
78 lines
2.1 KiB
Go
78 lines
2.1 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))
|
|
registryAPI.Post("/image/fetch", registry.RegistryImageFetch(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
|
|
}
|