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