Skip to content

Commit 5008a63

Browse files
committed
chore: update registry app to use containerd backend
1 parent e335fd0 commit 5008a63

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

cmd/unregistry/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func main() {
2323
PreRun: func(cmd *cobra.Command, args []string) {
2424
bindEnvToFlag(cmd, "addr", "UNREGISTRY_ADDR")
2525
bindEnvToFlag(cmd, "log-level", "UNREGISTRY_LOG_LEVEL")
26+
bindEnvToFlag(cmd, "namespace", "UNREGISTRY_CONTAINERD_NAMESPACE")
2627
bindEnvToFlag(cmd, "sock", "UNREGISTRY_CONTAINERD_SOCK")
27-
bindEnvToFlag(cmd, "namespace", "UNREGISTRY_NAMESPACE")
2828
},
2929
RunE: func(cmd *cobra.Command, args []string) error {
3030
return run(cfg)
@@ -33,8 +33,8 @@ func main() {
3333

3434
cmd.Flags().StringVarP(&cfg.Addr, "listen", "l", ":5000", "Address to listen on.")
3535
cmd.Flags().StringVar(&cfg.LogLevel, "log-level", "info", "Log level (debug, info, warn, error).")
36+
cmd.Flags().StringVar(&cfg.ContainerdNamespace, "namespace", "moby", "containerd namespace to use.")
3637
cmd.Flags().StringVar(&cfg.ContainerdSock, "sock", "/run/containerd/containerd.sock", "Path to containerd socket.")
37-
cmd.Flags().StringVar(&cfg.Namespace, "namespace", "moby", "containerd namespace to use.")
3838
//cmd.Flags().String("secret", "", "HTTP secret key")
3939

4040
if err := cmd.Execute(); err != nil {

internal/registry/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ type Config struct {
66
Addr string
77
// ContainerdSock is the path to the containerd.sock socket.
88
ContainerdSock string
9-
// Namespace is the containerd namespace to use.
10-
Namespace string
11-
LogLevel string
9+
// ContainerdNamespace is the containerd namespace to use.
10+
ContainerdNamespace string
11+
LogLevel string
1212
//HTTPSecret string
1313
}

internal/registry/registry.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/distribution/distribution/v3/registry/handlers"
99
_ "github.com/distribution/distribution/v3/registry/storage/driver/filesystem"
1010
"github.com/sirupsen/logrus"
11+
"github.com/uncloud/unregistry/internal/storage/containerd"
12+
_ "github.com/uncloud/unregistry/internal/storage/containerd"
1113
"net/http"
1214
)
1315

@@ -28,19 +30,27 @@ func NewRegistry(cfg Config) (*Registry, error) {
2830
// TODO: expose a flag and env var to configure the log formatter, e.g. JSON one for log aggregators.
2931
logrus.SetFormatter(&logrus.TextFormatter{})
3032

31-
// Create distribution configuration
3233
distConfig := &configuration.Configuration{
33-
// TODO: replace the storage with containerd one.
3434
Storage: configuration.Storage{
3535
"filesystem": configuration.Parameters{
36-
"rootdirectory": "/var/lib/unregistry",
36+
"rootdirectory": "/tmp/registry", // Dummy storage driver
37+
},
38+
},
39+
Middleware: map[string][]configuration.Middleware{
40+
"registry": {
41+
{
42+
Name: containerd.MiddlewareName,
43+
Options: configuration.Parameters{
44+
"namespace": cfg.ContainerdNamespace,
45+
"sock": cfg.ContainerdSock,
46+
},
47+
},
3748
},
3849
},
3950
}
40-
4151
app := handlers.NewApp(context.Background(), distConfig)
4252
server := &http.Server{
43-
Addr: cfg.HTTPAddr,
53+
Addr: cfg.Addr,
4454
Handler: app,
4555
}
4656

0 commit comments

Comments
 (0)