wip: created example files with new config and implementing new config in init
This commit is contained in:
parent
6032b6c0c1
commit
8f68c4ace9
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Golang Dev",
|
||||
"image": "golang-dev:1.21-bookworm-user",
|
||||
"image": "golang-dev:1.22-bookworm-user",
|
||||
"mounts": [
|
||||
{
|
||||
"source": "WingmateGoPath",
|
||||
|
|
|
@ -4,19 +4,43 @@ import (
|
|||
"gitea.suyono.dev/suyono/wingmate/config"
|
||||
wminit "gitea.suyono.dev/suyono/wingmate/init"
|
||||
"gitea.suyono.dev/suyono/wingmate/task"
|
||||
"github.com/spf13/viper"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type wConfig struct {
|
||||
tasks *task.Tasks
|
||||
tasks *task.Tasks
|
||||
config *config.Config
|
||||
viperMtx *sync.Mutex
|
||||
}
|
||||
|
||||
func (c *wConfig) Tasks() wminit.Tasks {
|
||||
return c.tasks
|
||||
}
|
||||
|
||||
func (c *wConfig) WMPidProxyPath() string {
|
||||
c.viperMtx.Lock()
|
||||
defer c.viperMtx.Unlock()
|
||||
|
||||
return viper.GetString(config.PidProxyPathConfig)
|
||||
}
|
||||
|
||||
func (c *wConfig) WMExecPath() string {
|
||||
c.viperMtx.Lock()
|
||||
defer c.viperMtx.Unlock()
|
||||
|
||||
return viper.GetString(config.ExecPathConfig)
|
||||
}
|
||||
|
||||
func (c *wConfig) Reload() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert(cfg *config.Config) *wConfig {
|
||||
retval := &wConfig{
|
||||
tasks: task.NewTasks(),
|
||||
tasks: task.NewTasks(),
|
||||
config: cfg,
|
||||
viperMtx: &sync.Mutex{},
|
||||
}
|
||||
|
||||
for _, s := range cfg.Service {
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestEntry_configPathEnv(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestEntry_configPathPFlag(t *testing.T) {
|
||||
os.Args = []string{"wingmate", "--config", "/Volumes/Source/go/src/gitea.suyono.dev/suyono/wingmate/docker/bookworm/etc/wingmate"}
|
||||
os.Args = []string{"wingmate", "--config", "/workspaces/wingmate/docker/bookworm-newconfig/etc/wingmate"}
|
||||
main()
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,12 @@ package config
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"gitea.suyono.dev/suyono/wingmate"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/sys/unix"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -38,7 +36,6 @@ type Config struct {
|
|||
CronV0 []*Cron
|
||||
Service []ServiceTask
|
||||
Cron []CronTask
|
||||
viperMtx *sync.Mutex
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
|
@ -108,7 +105,6 @@ func Read() (*Config, error) {
|
|||
serviceAvailable = false
|
||||
cronAvailable = false
|
||||
outConfig := &Config{
|
||||
viperMtx: &sync.Mutex{},
|
||||
ServiceV0: make([]string, 0),
|
||||
}
|
||||
configPath := viper.GetString(ConfigPath)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
FROM golang:1.21-bookworm as builder
|
||||
|
||||
ADD . /root/wingmate
|
||||
WORKDIR /root/wingmate/
|
||||
ARG TEST_BUILD
|
||||
RUN make all && make DESTDIR=/usr/local/bin/wingmate install
|
||||
|
||||
|
||||
|
||||
FROM debian:bookworm
|
||||
|
||||
RUN ln -sf /usr/share/zoneinfo/Australia/Sydney /etc/localtime && \
|
||||
apt update && apt install -y procps && \
|
||||
useradd -m -s /bin/bash user1
|
||||
COPY --from=builder /usr/local/bin/wingmate/ /usr/local/bin/
|
||||
ADD --chmod=755 docker/bookworm/entry.sh /usr/local/bin/entry.sh
|
||||
ADD --chmod=755 docker/bookworm/etc /etc
|
||||
|
||||
ENTRYPOINT [ "/usr/local/bin/entry.sh" ]
|
||||
CMD [ "/usr/local/bin/wingmate" ]
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
exec "$@"
|
||||
else
|
||||
exec /usr/local/bin/wingmate
|
||||
fi
|
|
@ -0,0 +1,5 @@
|
|||
service:
|
||||
one:
|
||||
command: [ "/workspace/wingmate/cmd/experiment/starter/starter" ]
|
||||
environ: [ "DUMMY_PATH=/workspace/wingmate/cmd/experiment/dummy/dummy" ]
|
||||
|
|
@ -29,11 +29,7 @@ cron:
|
|||
for {
|
||||
if cron.TimeToRun(time.Now()) {
|
||||
wingmate.Log().Info().Str(cronTag, cron.Name()).Msg("executing")
|
||||
if len(cron.Command()) == 1 {
|
||||
cmd = exec.Command(cron.Command()[0])
|
||||
} else {
|
||||
cmd = exec.Command(cron.Command()[0], cron.Command()[1:]...)
|
||||
}
|
||||
cmd = exec.Command(cron.Command(), cron.Arguments()...)
|
||||
iwg = &sync.WaitGroup{}
|
||||
|
||||
if stdout, err = cmd.StdoutPipe(); err != nil {
|
||||
|
|
|
@ -23,7 +23,8 @@ type TaskStatus interface {
|
|||
|
||||
type Task interface {
|
||||
Name() string
|
||||
Command() []string
|
||||
Command() string
|
||||
Arguments() []string
|
||||
Environ() []string
|
||||
Setsid() bool
|
||||
UserGroup() UserGroup
|
||||
|
@ -47,6 +48,8 @@ type ServiceTask interface {
|
|||
|
||||
type Config interface {
|
||||
Tasks() Tasks
|
||||
WMPidProxyPath() string
|
||||
WMExecPath() string
|
||||
}
|
||||
|
||||
type Init struct {
|
||||
|
|
|
@ -33,11 +33,7 @@ func (i *Init) service(wg *sync.WaitGroup, task ServiceTask, exitFlag <-chan any
|
|||
service:
|
||||
for {
|
||||
failStatus = false
|
||||
if len(task.Command()) == 1 {
|
||||
cmd = exec.Command(task.Command()[0])
|
||||
} else {
|
||||
cmd = exec.Command(task.Command()[0], task.Command()[1:]...)
|
||||
}
|
||||
cmd = exec.Command(task.Command(), task.Arguments()...)
|
||||
iwg = &sync.WaitGroup{}
|
||||
|
||||
if stdout, err = cmd.StdoutPipe(); err != nil {
|
||||
|
|
15
task/cron.go
15
task/cron.go
|
@ -126,9 +126,18 @@ func (c *CronTask) Name() string {
|
|||
return c.name
|
||||
}
|
||||
|
||||
func (c *CronTask) Command() []string {
|
||||
retval := make([]string, len(c.command))
|
||||
copy(retval, c.command)
|
||||
func (c *CronTask) Command() string {
|
||||
return c.command[0]
|
||||
}
|
||||
|
||||
func (c *CronTask) Arguments() []string {
|
||||
if len(c.command) == 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
retval := make([]string, len(c.command)-1)
|
||||
copy(retval, c.command[1:])
|
||||
|
||||
return retval
|
||||
}
|
||||
|
||||
|
|
30
task/task.go
30
task/task.go
|
@ -125,13 +125,27 @@ func (t *ServiceTask) SetPidFile(path string) *ServiceTask {
|
|||
return t
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Validate() error {
|
||||
// call this function for validate the field
|
||||
return validate( /* input the validators here */ )
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Name() string {
|
||||
return t.name
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Command() []string {
|
||||
retval := make([]string, len(t.command))
|
||||
copy(retval, t.command)
|
||||
func (t *ServiceTask) Command() string {
|
||||
return t.command[0]
|
||||
}
|
||||
|
||||
func (t *ServiceTask) Arguments() []string {
|
||||
if len(t.command) == 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
retval := make([]string, len(t.command)-1)
|
||||
copy(retval, t.command[1:])
|
||||
|
||||
return retval
|
||||
}
|
||||
|
||||
|
@ -199,3 +213,13 @@ func (ug *userGroup) String() string {
|
|||
|
||||
return ug.user
|
||||
}
|
||||
|
||||
func validate(validators ...func() error) error {
|
||||
var err error
|
||||
for _, v := range validators {
|
||||
if err = v(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue