This repository has been archived by the owner on Dec 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spooler.go
66 lines (53 loc) · 1.5 KB
/
spooler.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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"github.com/fsnotify/fsnotify"
"github.com/heptiolabs/healthcheck"
"github.com/op/go-logging"
"github.com/tliron/kubernetes-registry-spooler/common"
"github.com/tliron/kutil/util"
)
var log = logging.MustGetLogger("registry-spooler")
func RunSpooler(registryUrl string, path string) {
stopChannel := util.SetupSignalHandler()
var roundTripper http.RoundTripper
if certificatePath != "" {
log.Infof("certificate path: %s", certificatePath)
var err error
roundTripper, err = common.TLSRoundTripper(certificatePath)
util.FailOnError(err)
}
if username != "" {
log.Infof("username: %s", username)
log.Infof("password: %s", password)
} else if token != "" {
log.Infof("token: %s", token)
}
processor := NewPublisher(registryUrl, roundTripper, username, password, token, queue)
log.Info("starting processor")
go processor.Run()
defer processor.Close()
fileInfos, err := ioutil.ReadDir(path)
util.FailOnError(err)
for _, fileInfo := range fileInfos {
processor.Enqueue(filepath.Join(path, fileInfo.Name()))
}
watcher, err := NewWatcher()
util.FailOnError(err)
err = watcher.Add(path, fsnotify.Create, func(path string) {
processor.Enqueue(path)
})
util.FailOnError(err)
log.Info("starting watcher")
go watcher.Run()
go func() {
log.Info("starting health monitor")
health := healthcheck.NewHandler()
err := http.ListenAndServe(fmt.Sprintf(":%d", healthPort), health)
util.FailOnError(err)
}()
<-stopChannel
}