Compare commits
4 commits
2f27ecda45
...
db0c4f1af0
Author | SHA1 | Date | |
---|---|---|---|
db0c4f1af0 | |||
da941d82b8 | |||
c52c707530 | |||
0320f9f88f |
4 changed files with 18 additions and 6 deletions
5
cli.go
5
cli.go
|
@ -8,12 +8,15 @@ import (
|
||||||
|
|
||||||
"gitea.nulo.in/Nulo/repro-run/runner"
|
"gitea.nulo.in/Nulo/repro-run/runner"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config, err := readConfig()
|
config, err := readConfig()
|
||||||
must(err)
|
must(err)
|
||||||
|
|
||||||
|
dontDeleteTemp := slices.Contains(os.Args, "--dont-delete-temp")
|
||||||
|
|
||||||
env, err := godotenv.Read()
|
env, err := godotenv.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Couldn't load env file: %v", err)
|
log.Printf("Couldn't load env file: %v", err)
|
||||||
|
@ -22,7 +25,7 @@ func main() {
|
||||||
env[k] = strings.ReplaceAll(v, "\\n", "\n")
|
env[k] = strings.ReplaceAll(v, "\\n", "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
must(runner.Run(config, "rootfs/", "cache/", ".", nil, false, env))
|
must(runner.Run(config, "rootfs/", "cache/", ".", nil, dontDeleteTemp, env))
|
||||||
}
|
}
|
||||||
|
|
||||||
func must(err error, where ...string) {
|
func must(err error, where ...string) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
defer c.Close(websocket.StatusInternalError, "the sky is falling")
|
defer c.Close(websocket.StatusInternalError, "the sky is falling")
|
||||||
|
|
||||||
ch := make(chan *[]byte)
|
ch := make(chan *[]byte, 1000)
|
||||||
err = run.addWriter(conn{ch: ch})
|
err = run.addWriter(conn{ch: ch})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("addWriter", err)
|
log.Println("addWriter", err)
|
||||||
|
@ -38,7 +38,10 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if payload == nil {
|
if payload == nil {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
c.Write(context.Background(), websocket.MessageBinary, *payload)
|
err = c.Write(context.Background(), websocket.MessageBinary, *payload)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Close(websocket.StatusNormalClosure, "")
|
c.Close(websocket.StatusNormalClosure, "")
|
||||||
|
|
|
@ -23,12 +23,12 @@ import (
|
||||||
|
|
||||||
type run struct {
|
type run struct {
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
|
finished bool
|
||||||
previous []byte
|
previous []byte
|
||||||
writers []io.WriteCloser
|
writers []io.WriteCloser
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *run) Write(p []byte) (n int, err error) {
|
func (r *run) Write(p []byte) (n int, err error) {
|
||||||
log.Println(string(p))
|
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
r.previous = append(r.previous, p...)
|
r.previous = append(r.previous, p...)
|
||||||
|
@ -45,13 +45,18 @@ func (r *run) addWriter(w io.WriteCloser) (err error) {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
|
|
||||||
go w.Write(slices.Clone(r.previous))
|
w.Write(slices.Clone(r.previous))
|
||||||
|
if r.finished {
|
||||||
|
w.Close()
|
||||||
|
} else {
|
||||||
r.writers = append(r.writers, w)
|
r.writers = append(r.writers, w)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (r *run) finishRun() {
|
func (r *run) finishRun() {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
|
r.finished = true
|
||||||
for _, c := range r.writers {
|
for _, c := range r.writers {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,7 @@ https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600); err != nil {
|
||||||
[]string{"--bind", rootfs, "/",
|
[]string{"--bind", rootfs, "/",
|
||||||
"--ro-bind", src, "/src",
|
"--ro-bind", src, "/src",
|
||||||
"--dev-bind", "/dev", "/dev",
|
"--dev-bind", "/dev", "/dev",
|
||||||
|
"--dev-bind", "/proc", "/proc",
|
||||||
"--bind", tmp, "/work",
|
"--bind", tmp, "/work",
|
||||||
"--unshare-user", "--uid", "1000", "--gid", "1000",
|
"--unshare-user", "--uid", "1000", "--gid", "1000",
|
||||||
"--setenv", "HOME", "/home/repro",
|
"--setenv", "HOME", "/home/repro",
|
||||||
|
|
Loading…
Reference in a new issue