2024-04-29 21:29:05 +02:00
|
|
|
package pkg
|
2023-02-26 09:19:27 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2023-02-26 16:59:20 +01:00
|
|
|
|
|
|
|
"github.com/fsnotify/fsnotify"
|
2023-02-26 09:19:27 +01:00
|
|
|
)
|
|
|
|
|
2023-02-26 16:59:20 +01:00
|
|
|
type NotifyIface interface {
|
|
|
|
NewWatcher() (*fsnotify.Watcher, error)
|
|
|
|
}
|
|
|
|
|
2023-02-26 09:19:27 +01:00
|
|
|
type WatcherIface interface {
|
|
|
|
Monitor(path string) error
|
|
|
|
Listen(binaryPath, scriptPath string, outputErr chan<- error)
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeployFunc func(binaryPath, scriptPath string) error
|
|
|
|
|
|
|
|
func Deploy(binaryPath, scriptPath string) error {
|
|
|
|
err := execute(binaryPath, scriptPath)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("execute: %s", err)
|
|
|
|
}
|
|
|
|
log.Println("deploy done")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func execute(binaryPath, scriptPath string) error {
|
|
|
|
cmd := exec.Command(binaryPath, scriptPath)
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
return fmt.Errorf("cmd.Run %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|