diff --git a/HadesAPI/main.go b/HadesAPI/main.go index 526598d..4342c74 100644 --- a/HadesAPI/main.go +++ b/HadesAPI/main.go @@ -1,6 +1,8 @@ package main import ( + "fmt" + "github.com/Mtze/HadesCI/shared/queue" "github.com/Mtze/HadesCI/shared/utils" "github.com/gin-gonic/gin" @@ -9,21 +11,28 @@ import ( var BuildQueue *queue.Queue +type HadesAPIConfig struct { + APIPort uint `env:"API_PORT,notEmpty" envDefault:"8080"` + RabbitMQConfig utils.RabbitMQConfig +} + func main() { - var cfg utils.Config + var cfg HadesAPIConfig utils.LoadConfig(&cfg) - // var err error - // BuildQueue, err = queue.Init("builds", "amqp://admin:admin@localhost:5672/") - // if err != nil { - // log.Panic(err) - // } + var err error + rabbitmqURL := fmt.Sprintf("amqp://%s:%s@%s/", cfg.RabbitMQConfig.User, cfg.RabbitMQConfig.Password, cfg.RabbitMQConfig.Url) + log.Debug("Connecting to RabbitMQ: ", rabbitmqURL) + BuildQueue, err = queue.Init("builds", "amqp://admin:admin@localhost:5672/") + if err != nil { + log.Panic(err) + } log.Info("Starting HadesAPI") gin.SetMode(gin.ReleaseMode) r := gin.Default() r.GET("/ping", ping) r.POST("/build", AddBuildToQueue) - log.Panic(r.Run(":8080")) // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") + log.Panic(r.Run(fmt.Sprintf(":%d", cfg.APIPort))) // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") } diff --git a/HadesScheduler/main.go b/HadesScheduler/main.go index ed4bfb8..553f85c 100644 --- a/HadesScheduler/main.go +++ b/HadesScheduler/main.go @@ -49,11 +49,11 @@ func initializeKubeconfig() *kubernetes.Clientset { } func main() { - var cfg utils.Config + var cfg utils.RabbitMQConfig utils.LoadConfig(&cfg) var err error - rabbitmqURL := fmt.Sprintf("amqp://%s:%s@%s/", cfg.RabbitMQUser, cfg.RabbitMQPassword, cfg.RabbitMQUrl) + rabbitmqURL := fmt.Sprintf("amqp://%s:%s@%s/", cfg.User, cfg.Password, cfg.Url) log.Debug("Connecting to RabbitMQ: ", rabbitmqURL) BuildQueue, err = queue.Init("builds", rabbitmqURL) diff --git a/shared/utils/cli.go b/shared/utils/config.go similarity index 70% rename from shared/utils/cli.go rename to shared/utils/config.go index 7e3dfbc..7b3e561 100644 --- a/shared/utils/cli.go +++ b/shared/utils/config.go @@ -8,14 +8,12 @@ import ( log "github.com/sirupsen/logrus" ) -type Config struct { - RabbitMQUrl string `env:"RABBITMQ_URL,notEmpty"` - RabbitMQUser string `env:"RABBITMQ_DEFAULT_USER,notEmpty"` - RabbitMQPassword string `env:"RABBITMQ_DEFAULT_PASS,notEmpty"` +type RabbitMQConfig struct { + Url string `env:"RABBITMQ_URL,notEmpty"` + User string `env:"RABBITMQ_DEFAULT_USER,notEmpty"` + Password string `env:"RABBITMQ_DEFAULT_PASS,notEmpty"` } -var Cfg Config - func LoadConfig(cfg interface{}) { if is_debug := os.Getenv("DEBUG"); is_debug == "true" {