Skip to content

Commit bd5255d

Browse files
committed
chore: update command description, clean up flags
1 parent f0b4e1d commit bd5255d

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

cmd/unregistry/main.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,43 @@ import (
1616
func main() {
1717
var cfg registry.Config
1818
cmd := &cobra.Command{
19-
Use: "unregistry",
20-
Short: "A container registry backed by the local Docker/containerd image store.",
19+
Use: "unregistry",
20+
Short: "A container registry that uses local Docker/containerd for storing images.",
21+
Long: `Unregistry is a lightweight OCI-compliant container registry that uses the local Docker (containerd)
22+
image store as its backend. It provides a standard registry API interface for pushing and pulling
23+
container images without requiring a separate storage backend.
24+
25+
Key use cases:
26+
- Push built images straight to remote servers without an external registry such as Docker Hub
27+
as intermediary
28+
- Pull images once and serve them to multiple nodes in a cluster environment
29+
- Distribute images in air-gapped environments
30+
- Development and testing workflows that need a local registry
31+
- Expose pre-loaded images through a standard registry API`,
2132
SilenceUsage: true,
2233
SilenceErrors: true,
2334
PreRun: func(cmd *cobra.Command, args []string) {
2435
bindEnvToFlag(cmd, "addr", "UNREGISTRY_ADDR")
36+
bindEnvToFlag(cmd, "log-format", "UNREGISTRY_LOG_FORMAT")
2537
bindEnvToFlag(cmd, "log-level", "UNREGISTRY_LOG_LEVEL")
2638
bindEnvToFlag(cmd, "namespace", "UNREGISTRY_CONTAINERD_NAMESPACE")
27-
bindEnvToFlag(cmd, "sock", "UNREGISTRY_CONTAINERD_SOCK")
39+
bindEnvToFlag(cmd, "socket", "UNREGISTRY_CONTAINERD_SOCK")
2840
},
2941
RunE: func(cmd *cobra.Command, args []string) error {
3042
return run(cfg)
3143
},
3244
}
3345

34-
cmd.Flags().StringVarP(&cfg.Addr, "listen", "l", ":5000", "Address to listen on.")
35-
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.")
37-
cmd.Flags().StringVar(&cfg.ContainerdSock, "sock", "/run/containerd/containerd.sock", "Path to containerd socket.")
38-
//cmd.Flags().String("secret", "", "HTTP secret key")
46+
cmd.Flags().StringVarP(&cfg.Addr, "addr", "a", ":5000",
47+
"Address and port to listen on (e.g., 0.0.0.0:5000)")
48+
cmd.Flags().StringVarP(&cfg.LogFormatter, "log-format", "f", "text",
49+
"Log output format (text or json)")
50+
cmd.Flags().StringVarP(&cfg.LogLevel, "log-level", "l", "info",
51+
"Log verbosity level (debug, info, warn, error)")
52+
cmd.Flags().StringVarP(&cfg.ContainerdNamespace, "namespace", "n", "moby",
53+
"Containerd namespace to use for image storage")
54+
cmd.Flags().StringVarP(&cfg.ContainerdSock, "sock", "s", "/run/containerd/containerd.sock",
55+
"Path to containerd socket file")
3956

4057
if err := cmd.Execute(); err != nil {
4158
logrus.WithError(err).Fatal("Registry server failed.")

internal/registry/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ type Config struct {
66
Addr string
77
// ContainerdSock is the path to the containerd.sock socket.
88
ContainerdSock string
9-
// ContainerdNamespace is the containerd namespace to use.
9+
// ContainerdNamespace is the containerd namespace to use for storing images.
1010
ContainerdNamespace string
11-
LogLevel string
12-
//HTTPSecret string
11+
// LogLevel is one of "debug", "info", "warn", "error".
12+
LogLevel string
13+
// LogFormatter to use for the logs. Either "text" or "json".
14+
LogFormatter string
1315
}

internal/registry/registry.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"net/http"
8+
79
"github.com/distribution/distribution/v3/configuration"
810
"github.com/distribution/distribution/v3/registry/handlers"
911
_ "github.com/distribution/distribution/v3/registry/storage/driver/filesystem"
1012
"github.com/sirupsen/logrus"
1113
"github.com/uncloud/unregistry/internal/storage/containerd"
1214
_ "github.com/uncloud/unregistry/internal/storage/containerd"
13-
"net/http"
1415
)
1516

1617
// Registry represents a complete instance of the registry.
@@ -27,8 +28,15 @@ func NewRegistry(cfg Config) (*Registry, error) {
2728
return nil, fmt.Errorf("invalid log level: %w", err)
2829
}
2930
logrus.SetLevel(level)
30-
// TODO: expose a flag and env var to configure the log formatter, e.g. JSON one for log aggregators.
31-
logrus.SetFormatter(&logrus.TextFormatter{})
31+
32+
switch cfg.LogFormatter {
33+
case "json":
34+
logrus.SetFormatter(&logrus.JSONFormatter{})
35+
case "text":
36+
logrus.SetFormatter(&logrus.TextFormatter{})
37+
default:
38+
return nil, fmt.Errorf("invalid log formatter: '%s'; expected 'json' or 'text'", cfg.LogFormatter)
39+
}
3240

3341
distConfig := &configuration.Configuration{
3442
Storage: configuration.Storage{

0 commit comments

Comments
 (0)