You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3 KiB

package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"gitea.urkob.com/urko/git-webhook-ci/cfg"
"gitea.urkob.com/urko/git-webhook-ci/internal/watcher"
pkgwatcher "gitea.urkob.com/urko/git-webhook-ci/pkg/watcher"
)
var (
watcherIface pkgwatcher.WatcherIface
notifierIface pkgwatcher.NotifyIface
)
func main() {
envFilePath := ""
if os.Getenv("ENV") != "prod" {
flag.StringVar(&envFilePath, ".env path", "/", "provide .env path file as an absolute path")
flag.Parse()
}
config := cfg.NewConfig(envFilePath)
notifierIface = watcher.NewNotifier()
watcherIface = watcher.NewWatcher(notifierIface, pkgwatcher.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)
}
errors := make(chan error)
watcherIface.Listen(config.ScriptBinaryPath, config.WebhookScriptPath, errors)
// Handle termination on ctrl+signalChan
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
for {
select {
case <-signalChan:
os.Exit(1)
case err := <-errors:
if err != nil {
log.Printf("watcherIface.Monitor: %s\n", err)
continue
}
}
}
}