50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"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
|
|
|
|
func main() {
|
|
isProd := os.Getenv("ENV") == "prod"
|
|
config := cfg.NewConfig(isProd)
|
|
|
|
watcherIface = watcher.NewWatcher(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
|
|
}
|
|
}
|
|
}
|
|
}
|