small pixel drawing of a pufferfish lilp

*
Jes Olson jolson@digitalocean.com
Wed, 09 Feb 2022 19:53:54 -0600
commit

79350fdb3e314f98027dcf353ee03b526f1764c8

parent

79fcbd8da1c42cb1b55e80eaf0d4386bd5d1e805

6 files changed, 82 insertions(+), 14 deletions(-)

jump to
A .gitignore

@@ -0,0 +1,1 @@

+lilp
M READMEREADME

@@ -47,12 +47,10 @@ definitions

clone = the git url to clone & watch. takes the ref argument. ref = the git ref (branch or tag) to clone + watch for changes *run = command to run (order matters) - use this to start your service / job -every = how often to run this command (use this only when the process is expected to exit) * at least 1 "run" statement is required, everything else is optional if you leave "clone" out, no repo will be cloned or watched if you leave "ref" out, the default ref will be "main" -if you leave "every" out, processes will restart 1s after they exit the config format is very strict. it goes:

@@ -70,15 +68,13 @@ run "go build"

run "GITEA_PORT=8086 ./gitea" process "backup" - clone "https://git.j3s.sh/dotfiles" + clone "https://git.j3s.sh/backup-stuff" ref "main" - run "apt install rsync -y" # a little wasteful but who cares tbh - run "./my-backup-script" - every "1d" + run "apt install rsync -y" + run "./my-backup-script && sleep 8600" process "loldockerino" run "docker run redis" process "loldockerino" run "echo hi mom" - every "1s"
A config.go

@@ -0,0 +1,53 @@

+package main + +import ( + "log" + "os" + "strings" +) + +type Config struct { + Processes []Process +} + +type Process struct { + Name string + Clone string + Ref string + RunCmds []string +} + +func shittilyParseConfig(file string) Config { + var conf Config + data, err := os.ReadFile(file) + if err != nil { + log.Fatal(err) + } + // ty forest + configPieces := strings.Split(string(data), "\n") + var process Process + for _, chunk := range configPieces { + if chunk == "" { + conf.Processes = append(conf.Processes, process) + continue + } + parts := strings.Split(chunk, "\"") + if parts[0] == "process " { + // we can assume the previous process is complete, so + // if it exists, we add it to the broader array + process = Process{} + process.Name = parts[1] + } else if parts[0] == " clone " { + process.Clone = parts[1] + } else if parts[0] == " ref " { + process.Ref = parts[1] + } else if parts[0] == " run " { + process.RunCmds = append(process.RunCmds, parts[1]) + } else { + log.Fatal("idfk lol") + } + } + + // read file + return conf +}
A contrib/example-config

@@ -0,0 +1,11 @@

+process "lil-shell-example" + clone "https://git.j3s.sh/whatever" + ref "main" + run "echo hi mom && sleep 1" + run "whatever" + +process "docker-example" + clone "https://git.j3s.sh/dockerstuff" + ref "master" + run "docker build ." + run "docker run ."
A go.mod

@@ -0,0 +1,3 @@

+module git.j3s.sh/lilp + +go 1.17
M main.gomain.go

@@ -1,11 +1,15 @@

package main -type Config struct { - Processes []Process +import ( + "errors" + "log" +) + +func startProc(p Process) error { + return errors.New("what") } -type Process struct { - RunCmds = []string - Clone = string - Ref = string -}+func main() { + lilpConfig := shittilyParseConfig("./contrib/example-config") + log.Printf("config: %+v", lilpConfig) +}