-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update from main * Add basic docker compose config * Implement env parser * Implement config load for hadesAPI * Implement config load for hadesScheduler * Add env variables * Add API port to env variables * Remove hardcoded queue value in API * Improve log messages
- Loading branch information
Showing
7 changed files
with
102 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RABBITMQ_URL=localhost:5672 | ||
RABBITMQ_DEFAULT_USER=admin | ||
RABBITMQ_DEFAULT_PASS=admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"fmt" | ||
|
||
"github.com/Mtze/HadesCI/shared/queue" | ||
"github.com/Mtze/HadesCI/shared/utils" | ||
"github.com/gin-gonic/gin" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var BuildQueue *queue.Queue | ||
|
||
type HadesAPIConfig struct { | ||
APIPort uint `env:"API_PORT,notEmpty" envDefault:"8080"` | ||
RabbitMQConfig utils.RabbitMQConfig | ||
} | ||
|
||
func main() { | ||
if is_debug := os.Getenv("DEBUG"); is_debug == "true" { | ||
log.SetLevel(log.DebugLevel) | ||
log.Warn("DEBUG MODE ENABLED") | ||
} | ||
|
||
// var err error | ||
// BuildQueue, err = queue.Init("builds", "amqp://admin:admin@localhost:5672/") | ||
// if err != nil { | ||
// log.Panic(err) | ||
// } | ||
var cfg HadesAPIConfig | ||
utils.LoadConfig(&cfg) | ||
|
||
log.Info("Starting HadesAPI") | ||
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", rabbitmqURL) | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
|
||
log.Infof("Starting HadesAPI on port %d", cfg.APIPort) | ||
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))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package utils | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/caarlos0/env/v9" | ||
"github.com/joho/godotenv" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type RabbitMQConfig struct { | ||
Url string `env:"RABBITMQ_URL,notEmpty"` | ||
User string `env:"RABBITMQ_DEFAULT_USER,notEmpty"` | ||
Password string `env:"RABBITMQ_DEFAULT_PASS,notEmpty"` | ||
} | ||
|
||
func LoadConfig(cfg interface{}) { | ||
|
||
if is_debug := os.Getenv("DEBUG"); is_debug == "true" { | ||
log.SetLevel(log.DebugLevel) | ||
log.Warn("DEBUG MODE ENABLED") | ||
} | ||
|
||
err := godotenv.Load() | ||
if err != nil { | ||
log.WithError(err).Warn("Error loading .env file") | ||
} | ||
|
||
err = env.Parse(cfg) | ||
if err != nil { | ||
log.WithError(err).Fatal("Error parsing environment variables") | ||
} | ||
|
||
log.Debug("Config loaded: ", cfg) | ||
} |