Compare commits

...

4 commits

Author SHA1 Message Date
Cat /dev/Nulo db0c4f1af0 cli: poder no borrar temp
Some checks failed
repro-run Corre repro-run.json
2023-01-30 16:01:29 -03:00
Cat /dev/Nulo da941d82b8 runner: bind /proc
esto arregla npm install que a veces se rompe
2023-01-30 15:59:22 -03:00
Cat /dev/Nulo c52c707530 gitea-ci: no printear el log de los comandos 2023-01-29 22:03:37 -03:00
Cat /dev/Nulo 0320f9f88f gitea-ci: cerrar conexiones 2023-01-29 22:03:18 -03:00
4 changed files with 18 additions and 6 deletions

5
cli.go
View file

@ -8,12 +8,15 @@ import (
"gitea.nulo.in/Nulo/repro-run/runner"
"github.com/joho/godotenv"
"golang.org/x/exp/slices"
)
func main() {
config, err := readConfig()
must(err)
dontDeleteTemp := slices.Contains(os.Args, "--dont-delete-temp")
env, err := godotenv.Read()
if err != nil {
log.Printf("Couldn't load env file: %v", err)
@ -22,7 +25,7 @@ func main() {
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) {

View file

@ -27,7 +27,7 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
defer c.Close(websocket.StatusInternalError, "the sky is falling")
ch := make(chan *[]byte)
ch := make(chan *[]byte, 1000)
err = run.addWriter(conn{ch: ch})
if err != nil {
log.Println("addWriter", err)
@ -38,7 +38,10 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if payload == nil {
break
} else {
c.Write(context.Background(), websocket.MessageBinary, *payload)
err = c.Write(context.Background(), websocket.MessageBinary, *payload)
if err != nil {
return
}
}
}
c.Close(websocket.StatusNormalClosure, "")

View file

@ -23,12 +23,12 @@ import (
type run struct {
mutex sync.Mutex
finished bool
previous []byte
writers []io.WriteCloser
}
func (r *run) Write(p []byte) (n int, err error) {
log.Println(string(p))
r.mutex.Lock()
defer r.mutex.Unlock()
r.previous = append(r.previous, p...)
@ -45,13 +45,18 @@ func (r *run) addWriter(w io.WriteCloser) (err error) {
r.mutex.Lock()
defer r.mutex.Unlock()
go w.Write(slices.Clone(r.previous))
r.writers = append(r.writers, w)
w.Write(slices.Clone(r.previous))
if r.finished {
w.Close()
} else {
r.writers = append(r.writers, w)
}
return
}
func (r *run) finishRun() {
r.mutex.Lock()
defer r.mutex.Unlock()
r.finished = true
for _, c := range r.writers {
c.Close()
}

View file

@ -85,6 +85,7 @@ https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600); err != nil {
[]string{"--bind", rootfs, "/",
"--ro-bind", src, "/src",
"--dev-bind", "/dev", "/dev",
"--dev-bind", "/proc", "/proc",
"--bind", tmp, "/work",
"--unshare-user", "--uid", "1000", "--gid", "1000",
"--setenv", "HOME", "/home/repro",