-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (45 loc) · 1.58 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
package main
import (
"flag"
"net/http"
"github.com/alauda/oci-chartrepo/pkg"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
var registryOpts = &pkg.RegistryOptions{}
// flags
port := flag.String("port", "8080", "listen port")
//TODO: remove in chart args and here
flag.String("storage", "registry", "storage backend(only registry for now)")
flag.StringVar(®istryOpts.URL, "storage-registry-repo", "localhost:5000", "oci registry address")
flag.StringVar(®istryOpts.Scheme, "storage-registry-scheme", "", "oci registry address scheme, default is http")
flag.Parse()
// Get registry scheme, and get user info from secret config file(if it exists).
if err := registryOpts.FullfillRegistryOptions(); err != nil {
panic(err)
}
// Echo instance
e := echo.New()
pkg.GlobalBackend = pkg.NewBackend(registryOpts)
// When multiple instance of oci-chartrepo exist, this will make sure every instance
// has the internal cache before it gets requrest to individual chart. Of course this will slow down
// the startup process, we need to add heathcheck later
// TODO: add health check for pod
if _, err := pkg.GlobalBackend.ListObjects(); err != nil {
e.Logger.Fatal("init chart registry cache error", err)
}
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.GET("/", hello)
e.GET("/index.yaml", pkg.IndexHandler)
e.GET("/charts/:name", pkg.GetChartHandler)
// Start server
e.Logger.Fatal(e.Start(":" + *port))
}
// Handler
func hello(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}