forked from lukaszbudnik/migrator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrator.go
66 lines (52 loc) · 1.87 KB
/
migrator.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 (
"bytes"
"context"
"flag"
"os"
"github.com/gin-gonic/gin"
"github.com/lukaszbudnik/migrator/common"
"github.com/lukaszbudnik/migrator/config"
"github.com/lukaszbudnik/migrator/coordinator"
"github.com/lukaszbudnik/migrator/db"
"github.com/lukaszbudnik/migrator/loader"
"github.com/lukaszbudnik/migrator/metrics"
"github.com/lukaszbudnik/migrator/notifications"
"github.com/lukaszbudnik/migrator/server"
"github.com/lukaszbudnik/migrator/types"
)
const (
// DefaultConfigFile defines default file name of migrator configuration file
DefaultConfigFile = "migrator.yaml"
)
// GitRef stores git branch/tag, value injected during production build
var GitRef string
// GitSha stores git commit sha, value injected during production build
var GitSha string
func main() {
versionInfo := &types.VersionInfo{Release: GitRef, Sha: GitSha, APIVersions: []types.APIVersion{types.APIV2}}
common.Log("INFO", "migrator %+v", versionInfo)
flag := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
buf := new(bytes.Buffer)
flag.SetOutput(buf)
var configFile string
flag.StringVar(&configFile, "configFile", DefaultConfigFile, "path to migrator configuration yaml file")
if err := flag.Parse(os.Args[1:]); err != nil {
common.Log("ERROR", buf.String())
os.Exit(1)
}
cfg, err := config.FromFile(configFile)
if err != nil {
common.Log("ERROR", "Error reading config file: %v", err)
os.Exit(1)
}
var createCoordinator = func(ctx context.Context, config *config.Config, metrics metrics.Metrics) coordinator.Coordinator {
coordinator := coordinator.New(ctx, config, metrics, db.New, loader.New, notifications.New)
return coordinator
}
gin.SetMode(gin.ReleaseMode)
g := server.CreateRouterAndPrometheus(versionInfo, cfg, createCoordinator)
if err := g.Run(":" + server.GetPort(cfg)); err != nil {
common.Log("ERROR", "Error starting migrator: %v", err)
}
}