feat(pidproxy): read startsecs from env

chore: centralize env prefix
This commit is contained in:
Suyono 2023-12-10 22:23:43 +11:00
parent 8704f80d4b
commit ad8499daa5
6 changed files with 19 additions and 10 deletions

View File

@ -14,7 +14,6 @@ const (
// DummyPath = "/workspaces/wingmate/cmd/experiment/dummy/dummy" // DummyPath = "/workspaces/wingmate/cmd/experiment/dummy/dummy"
DummyPath = "/usr/local/bin/wmdummy" DummyPath = "/usr/local/bin/wmdummy"
EnvDummyPath = "DUMMY_PATH" EnvDummyPath = "DUMMY_PATH"
EnvPrefix = "WINGMATE"
EnvLog = "LOG" EnvLog = "LOG"
EnvLogMessage = "LOG_MESSAGE" EnvLogMessage = "LOG_MESSAGE"
EnvDefaultLogMessage = "oneshot executed" EnvDefaultLogMessage = "oneshot executed"
@ -23,7 +22,7 @@ const (
) )
func main() { func main() {
viper.SetEnvPrefix(EnvPrefix) viper.SetEnvPrefix(wingmate.EnvPrefix)
viper.BindEnv(EnvDummyPath) viper.BindEnv(EnvDummyPath)
viper.BindEnv(EnvLog) viper.BindEnv(EnvLog)
viper.BindEnv(EnvLogMessage) viper.BindEnv(EnvLogMessage)

View File

@ -5,11 +5,11 @@ import (
"os/exec" "os/exec"
"time" "time"
"gitea.suyono.dev/suyono/wingmate"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const ( const (
EnvPrefix = "WINGMATE"
EnvOneShotPath = "ONESHOT_PATH" EnvOneShotPath = "ONESHOT_PATH"
OneShotPath = "/usr/local/bin/wmoneshot" OneShotPath = "/usr/local/bin/wmoneshot"
) )
@ -20,7 +20,7 @@ func main() {
err error err error
t *time.Ticker t *time.Ticker
) )
viper.SetEnvPrefix(EnvPrefix) viper.SetEnvPrefix(wingmate.EnvPrefix)
viper.BindEnv(EnvOneShotPath) viper.BindEnv(EnvOneShotPath)
viper.SetDefault(EnvOneShotPath, OneShotPath) viper.SetDefault(EnvOneShotPath, OneShotPath)

View File

@ -7,6 +7,7 @@ import (
"os/exec" "os/exec"
"sync" "sync"
"gitea.suyono.dev/suyono/wingmate"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -14,7 +15,6 @@ const (
// DummyPath = "/workspaces/wingmate/cmd/experiment/dummy/dummy" // DummyPath = "/workspaces/wingmate/cmd/experiment/dummy/dummy"
DummyPath = "/usr/local/bin/wmdummy" DummyPath = "/usr/local/bin/wmdummy"
EnvDummyPath = "DUMMY_PATH" EnvDummyPath = "DUMMY_PATH"
EnvPrefix = "WINGMATE"
) )
func main() { func main() {
@ -25,7 +25,7 @@ func main() {
err error err error
exePath string exePath string
) )
viper.SetEnvPrefix(EnvPrefix) viper.SetEnvPrefix(wingmate.EnvPrefix)
viper.BindEnv(EnvDummyPath) viper.BindEnv(EnvDummyPath)
viper.SetDefault(EnvDummyPath, DummyPath) viper.SetDefault(EnvDummyPath, DummyPath)

View File

@ -8,6 +8,7 @@ import (
"syscall" "syscall"
"time" "time"
"gitea.suyono.dev/suyono/wingmate"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -15,6 +16,8 @@ import (
const ( const (
pidFileFlag = "pid-file" pidFileFlag = "pid-file"
EnvStartSecs = "STARTSECS"
EnvDefaultStartSecs = 1
) )
var ( var (
@ -34,6 +37,10 @@ func main() {
found bool found bool
) )
viper.SetEnvPrefix(wingmate.EnvPrefix)
viper.BindEnv(EnvStartSecs)
viper.SetDefault(EnvStartSecs, EnvDefaultStartSecs)
if len(os.Args) <= 2 { if len(os.Args) <= 2 {
log.Println("invalid argument") log.Println("invalid argument")
os.Exit(1) os.Exit(1)
@ -77,7 +84,8 @@ func pidProxy(cmd *cobra.Command, args []string) error {
} else { } else {
go startProcess(childArgs[0]) go startProcess(childArgs[0])
} }
time.Sleep(time.Second) initialWait := viper.GetInt(EnvStartSecs)
time.Sleep(time.Second * time.Duration(initialWait))
var ( var (
err error err error

View File

@ -15,8 +15,8 @@ COPY --from=builder /root/wingmate/cmd/experiment/starter/starter /usr/local/bin
COPY --from=builder /root/wingmate/cmd/experiment/oneshot/oneshot /usr/local/bin/wmoneshot COPY --from=builder /root/wingmate/cmd/experiment/oneshot/oneshot /usr/local/bin/wmoneshot
COPY --from=builder /root/wingmate/cmd/experiment/spawner/spawner /usr/local/bin/wmspawner COPY --from=builder /root/wingmate/cmd/experiment/spawner/spawner /usr/local/bin/wmspawner
COPY --from=builder /root/wingmate/cmd/pidproxy/pidproxy /usr/local/bin/wmpidproxy COPY --from=builder /root/wingmate/cmd/pidproxy/pidproxy /usr/local/bin/wmpidproxy
ADD --chmod=755 docker/alpine/entry.sh /usr/local/bin/entry.sh ADD --chmod=755 docker/bookworm/entry.sh /usr/local/bin/entry.sh
ADD --chmod=755 docker/alpine/etc /etc ADD --chmod=755 docker/bookworm/etc /etc
ENTRYPOINT [ "/usr/local/bin/entry.sh" ] ENTRYPOINT [ "/usr/local/bin/entry.sh" ]
CMD [ "/usr/local/bin/wingmate" ] CMD [ "/usr/local/bin/wingmate" ]

View File

@ -6,4 +6,6 @@ const (
Any CronTimeType = iota Any CronTimeType = iota
Exact Exact
MultipleOccurrence MultipleOccurrence
EnvPrefix = "WINGMATE"
) )