git-webhook-ci/main.go

56 lines
1.1 KiB
Go
Raw Normal View History

2023-02-25 22:32:10 +01:00
package main
import (
"log"
"os"
"os/signal"
"syscall"
2023-02-25 22:32:10 +01:00
"gitea.urkob.com/urko/git-webhook-ci/internal/watcher"
2024-04-29 21:50:16 +02:00
"gitea.urkob.com/urko/git-webhook-ci/kit/config"
2024-04-29 21:29:05 +02:00
"gitea.urkob.com/urko/git-webhook-ci/pkg"
2023-02-25 22:32:10 +01:00
)
2023-02-26 16:59:20 +01:00
var (
2024-04-29 21:29:05 +02:00
watcherIface pkg.WatcherIface
notifierIface pkg.NotifyIface
2023-02-26 16:59:20 +01:00
)
2023-02-25 22:32:10 +01:00
func main() {
2024-05-02 08:46:36 +02:00
config, err := config.LoadConfig("./configs/app.yaml")
2024-04-29 21:50:16 +02:00
if err != nil {
panic(err)
}
2023-02-25 22:32:10 +01:00
2023-02-26 16:59:20 +01:00
notifierIface = watcher.NewNotifier()
2024-04-29 21:29:05 +02:00
watcherIface = watcher.NewWatcher(notifierIface, pkg.Deploy)
defer func() {
if err := watcherIface.Close(); err != nil {
log.Fatalf("watcherIface.Close: %s\n", err)
}
}()
if err := watcherIface.Monitor(config.FileToWatchPath); err != nil {
log.Fatalf("watcherIface.Monitor: %s\n", err)
2023-02-25 22:32:10 +01:00
}
errors := make(chan error)
watcherIface.Listen(config.ScriptBinaryPath, config.WebhookScriptPath, errors)
// Handle termination on ctrl+signalChan
2023-02-26 10:59:33 +01:00
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
2023-02-26 16:19:12 +01:00
for {
select {
case <-signalChan:
os.Exit(1)
case err := <-errors:
if err != nil {
log.Printf("watcherIface.Monitor: %s\n", err)
continue
2023-02-25 22:32:10 +01:00
}
}
2023-02-26 16:19:12 +01:00
}
2023-02-25 22:32:10 +01:00
}