2014-12-02 01:36:20 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
_ "net/http/pprof"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
2014-12-24 00:01:38 +00:00
|
|
|
"github.com/docker/distribution/configuration"
|
2015-08-20 20:56:36 +00:00
|
|
|
"github.com/docker/distribution/registry"
|
2015-06-11 02:40:05 +00:00
|
|
|
_ "github.com/docker/distribution/registry/auth/htpasswd"
|
2015-02-11 02:14:23 +00:00
|
|
|
_ "github.com/docker/distribution/registry/auth/silly"
|
|
|
|
_ "github.com/docker/distribution/registry/auth/token"
|
2015-07-29 18:12:01 +00:00
|
|
|
_ "github.com/docker/distribution/registry/proxy"
|
2015-06-11 22:30:18 +00:00
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/azure"
|
2015-02-11 02:14:23 +00:00
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/filesystem"
|
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/inmemory"
|
2015-03-03 16:57:52 +00:00
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/middleware/cloudfront"
|
2015-05-11 15:26:51 +00:00
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/oss"
|
2015-02-11 02:14:23 +00:00
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/s3"
|
2015-05-11 16:11:47 +00:00
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/swift"
|
2015-01-29 23:32:49 +00:00
|
|
|
"github.com/docker/distribution/version"
|
2015-08-20 20:56:36 +00:00
|
|
|
"golang.org/x/net/context"
|
2014-12-02 01:36:20 +00:00
|
|
|
)
|
|
|
|
|
2015-01-29 23:32:49 +00:00
|
|
|
var showVersion bool
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.BoolVar(&showVersion, "version", false, "show the version and exit")
|
|
|
|
}
|
|
|
|
|
2014-12-02 01:36:20 +00:00
|
|
|
func main() {
|
|
|
|
flag.Usage = usage
|
|
|
|
flag.Parse()
|
|
|
|
|
2015-01-29 23:32:49 +00:00
|
|
|
if showVersion {
|
2015-01-29 23:53:26 +00:00
|
|
|
version.PrintVersion()
|
2015-01-29 23:32:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-02 01:36:20 +00:00
|
|
|
config, err := resolveConfiguration()
|
|
|
|
if err != nil {
|
|
|
|
fatalf("configuration error: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-08-20 20:56:36 +00:00
|
|
|
registry, err := registry.NewRegistry(context.Background(), config)
|
2015-03-25 00:12:04 +00:00
|
|
|
if err != nil {
|
2015-08-20 20:56:36 +00:00
|
|
|
log.Fatalln(err)
|
2015-05-05 08:25:42 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 20:56:36 +00:00
|
|
|
err = registry.Serve()
|
2015-05-05 08:25:42 +00:00
|
|
|
if err != nil {
|
2015-08-20 20:56:36 +00:00
|
|
|
log.Fatalln(err)
|
2014-12-02 01:36:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func usage() {
|
|
|
|
fmt.Fprintln(os.Stderr, "usage:", os.Args[0], "<config>")
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-06-12 02:41:00 +00:00
|
|
|
defer fp.Close()
|
|
|
|
|
2014-12-02 01:36:20 +00:00
|
|
|
config, err := configuration.Parse(fp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing %s: %v", configurationPath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|