Skip to content

Commit

Permalink
Add API port to env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Mtze committed Sep 22, 2023
1 parent e8e93b7 commit 20c8b1f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
23 changes: 16 additions & 7 deletions HadesAPI/main.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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")
}
4 changes: 2 additions & 2 deletions HadesScheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 4 additions & 6 deletions shared/utils/cli.go → shared/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 20c8b1f

Please sign in to comment.