-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (52 loc) · 1.54 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
package main
import (
"fmt"
"os"
"github.com/IMEsec-USP/container-manager/adapters"
"github.com/IMEsec-USP/container-manager/applications"
"github.com/IMEsec-USP/container-manager/handlers"
"github.com/go-martini/martini"
"github.com/rs/zerolog"
"github.com/spf13/viper"
)
func main() {
logger := zerolog.New(os.Stdout).Output(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger()
logger.Info().Msg("started logger")
readConfigurations(logger)
err := applications.BuildApplicationsFromConfig(logger)
if err != nil {
logger.Fatal().Err(err).Msg("cannot continue without correct application configuration")
}
logger.Info().Msg("loaded configs")
dockerAdapter, err := adapters.NewDockerAdapter()
if err != nil {
logger.Fatal().Err(err).Msg("cannot continue without a docker client")
}
martini.Env = martini.Prod
h := handlers.NewHTTPHandler()
{
h.Map(dockerAdapter)
h.Map(logger)
h.RegisterHealthCheck()
h.RegisterRestart()
h.RegisterPull()
}
h.RunOnAddr(fmt.Sprintf("%v:%v", viper.GetString("host"), viper.GetInt("port")))
}
func readConfigurations(logger zerolog.Logger) {
viper.SetConfigType("yaml")
viper.AddConfigPath("./config")
viper.AddConfigPath("/configs")
{
viper.SetDefault("host", "0.0.0.0")
viper.SetDefault("port", 3000)
}
err := viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
logger.Warn().Err(err).Msg("could not find any config files. Continuing with defaults")
} else {
logger.Fatal().Err(err).Msg("could not read from config files")
}
}
}