-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (73 loc) · 2.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import(
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/ricallinson/forgery"
"github.com/ricallinson/stackr"
"github.com/spacedock-io/registry/db"
"github.com/spacedock-io/registry/router"
"github.com/spacedock-io/registry/config"
"github.com/spacedock-io/registry/models"
"github.com/spacedock-io/registry/session"
"github.com/spacedock-io/registry/cloudfiles"
"github.com/Southern/logger"
"github.com/Southern/middleware"
)
const VERSION = "0.0.1"
func main() {
app := cli.NewApp()
app.Name = "Registry"
app.Usage = "Run a standalone Docker registry"
app.Version = "0.0.1"
app.Flags = []cli.Flag {
cli.StringFlag{"port, p", "", "Port number"},
cli.StringFlag{"index, i", "", "Index URL"},
cli.StringFlag{"env, e", "dev", "Environment"},
cli.StringFlag{"config, c", "", "Configuration directory"},
}
app.Action = func(c *cli.Context) {
env := c.String("env")
dir := c.String("config")
index := c.String("index")
if len(env) == 0 {
env = "dev"
}
if len(dir) > 0 {
config.Dir = dir
}
config.Global = config.Load(env)
config.Logger = logger.New()
if len(index) > 0 {
config.Global = config.Global.Set("index", index)
}
server := f.CreateServer()
server.Use(func(req *stackr.Request, res *stackr.Response, next func()) {
config.Logger.Log(fmt.Sprintf("%s %s", req.Method, req.Url))
next()
})
server.Use(middleware.BodyParser)
server.Use(func (req *stackr.Request, res *stackr.Response, next func()) {
defer next()
res.SetHeader("X-Docker-Registry-Version", VERSION)
res.SetHeader("X-Docker-Registry-Config", "dev")
})
server.Use(sx.Middleware("SECRETVERYSECRET"))
server.Use(f.ErrorHandler())
port := c.Int("port")
if port == 0 {
// Bug(Colton): Not quite sure why port is being picked up as Float64 at
// the moment. Still looking into this. It may be intended functionality.
port = int(config.Global.Get("port").Float64())
}
db.New(config.Global)
db.DB.AutoMigrate(&models.Image{})
db.DB.AutoMigrate(&models.Tag{})
// db.DB.AutoMigrate(&models.Ancestor{})
cloudfiles.New(config.Global)
router.Routes(server)
config.Logger.Log("Registry listening on port " + fmt.Sprint(port))
server.Listen(port)
}
app.Run(os.Args)
}