From 33016268302360f4fedf7753b830365c6ded36c4 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Mon, 1 Dec 2014 17:36:20 -0800 Subject: [PATCH] Add registry main cmd --- cmd/registry/config.yml | 5 +++ cmd/registry/main.go | 85 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 cmd/registry/config.yml create mode 100644 cmd/registry/main.go diff --git a/cmd/registry/config.yml b/cmd/registry/config.yml new file mode 100644 index 000000000..2f9ad0a2e --- /dev/null +++ b/cmd/registry/config.yml @@ -0,0 +1,5 @@ +version: 0.1 +loglevel: debug +storage: inmemory +http: + addr: localhost:5000 \ No newline at end of file diff --git a/cmd/registry/main.go b/cmd/registry/main.go new file mode 100644 index 000000000..150c7d6bc --- /dev/null +++ b/cmd/registry/main.go @@ -0,0 +1,85 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + _ "net/http/pprof" + "os" + + "github.com/gorilla/handlers" + + log "github.com/Sirupsen/logrus" + + "github.com/docker/docker-registry" + "github.com/docker/docker-registry/configuration" + _ "github.com/docker/docker-registry/storagedriver/filesystem" + _ "github.com/docker/docker-registry/storagedriver/inmemory" + _ "github.com/docker/docker-registry/storagedriver/s3" +) + +func main() { + flag.Usage = usage + flag.Parse() + + config, err := resolveConfiguration() + if err != nil { + fatalf("configuration error: %v", err) + } + + app := registry.NewApp(*config) + handler := handlers.CombinedLoggingHandler(os.Stdout, app) + log.SetLevel(logLevel(config.Loglevel)) + + log.Infof("listening on %v", config.HTTP.Addr) + if err := http.ListenAndServe(config.HTTP.Addr, handler); err != nil { + log.Fatalln(err) + } +} + +func usage() { + fmt.Fprintln(os.Stderr, "usage:", os.Args[0], "") + flag.PrintDefaults() +} + +func fatalf(format string, args ...interface{}) { + fmt.Fprintf(os.Stderr, format+"\n", args...) + usage() + os.Exit(1) +} + +func resolveConfiguration() (*configuration.Configuration, error) { + var configurationPath string + + if flag.NArg() > 0 { + configurationPath = flag.Arg(0) + } else if os.Getenv("REGISTRY_CONFIGURATION_PATH") != "" { + configurationPath = os.Getenv("REGISTRY_CONFIGURATION_PATH") + } + + if configurationPath == "" { + return nil, fmt.Errorf("configuration path unspecified") + } + + fp, err := os.Open(configurationPath) + if err != nil { + return nil, err + } + + config, err := configuration.Parse(fp) + if err != nil { + return nil, fmt.Errorf("error parsing %s: %v", configurationPath, err) + } + + return config, nil +} + +func logLevel(level configuration.Loglevel) log.Level { + l, err := log.ParseLevel(string(level)) + if err != nil { + log.Warnf("error parsing level %q: %v", level, err) + l = log.InfoLevel + } + + return l +}