Compare commits
No commits in common. "db0c4f1af0a86ed4f108281c5d2720367fcd1468" and "2f27ecda4528fab8aa67375e6df89cbc25599c96" have entirely different histories.
db0c4f1af0
...
2f27ecda45
4 changed files with 6 additions and 18 deletions
5
cli.go
5
cli.go
|
@ -8,15 +8,12 @@ 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)
|
||||||
|
@ -25,7 +22,7 @@ func main() {
|
||||||
env[k] = strings.ReplaceAll(v, "\\n", "\n")
|
env[k] = strings.ReplaceAll(v, "\\n", "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
must(runner.Run(config, "rootfs/", "cache/", ".", nil, dontDeleteTemp, env))
|
must(runner.Run(config, "rootfs/", "cache/", ".", nil, false, 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, 1000)
|
ch := make(chan *[]byte)
|
||||||
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,10 +38,7 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if payload == nil {
|
if payload == nil {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
err = c.Write(context.Background(), websocket.MessageBinary, *payload)
|
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,18 +45,13 @@ func (r *run) addWriter(w io.WriteCloser) (err error) {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
|
|
||||||
w.Write(slices.Clone(r.previous))
|
go 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,7 +85,6 @@ 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