Files
cluster/internal/cmd/cmd.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

50 lines
1.3 KiB
Go

package cmd
import (
"context"
"gitea.loveuer.com/loveuer/cluster/internal/api"
"gitea.loveuer.com/loveuer/cluster/internal/opt"
"gitea.loveuer.com/loveuer/cluster/pkg/database/db"
"gitea.loveuer.com/loveuer/cluster/pkg/store"
"github.com/spf13/cobra"
)
func Run(ctx context.Context) error {
_cmd := &cobra.Command{
Use: "cluster",
Short: "Cluster is a lightweight OCI registry implementation written in Go using Fiber v3.",
RunE: func(cmd *cobra.Command, args []string) error {
var (
err error
)
if err = opt.Init(cmd.Context()); err != nil {
return err
}
if err = db.Init(cmd.Context(), opt.GlobalDataDir); err != nil {
return err
}
if err = store.Init(cmd.Context(), opt.GlobalDataDir); err != nil {
return err
}
if err = api.Init(cmd.Context(), opt.GlobalAddress, db.Default, store.Default); err != nil {
return err
}
<-cmd.Context().Done()
return nil
},
}
_cmd.PersistentFlags().BoolVar(&opt.GlobalDebug, "debug", false, "Enable debug mode")
_cmd.PersistentFlags().StringVarP(&opt.GlobalAddress, "address", "A", "0.0.0.0:9119", "API server listen address")
_cmd.PersistentFlags().StringVarP(&opt.GlobalDataDir, "data-dir", "D", "./x-storage", "Data directory for storing all data")
return _cmd.Execute()
}