Compare commits
No commits in common. "85f1a81eccd60bca7c218d808856fb9d28b4b809" and "5077c6509be9d1f6d78c61144d8f19df6fa34e59" have entirely different histories.
85f1a81ecc
...
5077c6509b
8 changed files with 18 additions and 89 deletions
13
cli.go
13
cli.go
|
@ -4,25 +4,14 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitea.nulo.in/Nulo/repro-run/runner"
|
"gitea.nulo.in/Nulo/repro-run/runner"
|
||||||
"github.com/joho/godotenv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config, err := readConfig()
|
config, err := readConfig()
|
||||||
must(err)
|
must(err)
|
||||||
|
must(runner.Run(config, "rootfs/", "cache/", ".", nil, false))
|
||||||
env, err := godotenv.Read()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Couldn't load env file: %v", err)
|
|
||||||
}
|
|
||||||
for k, v := range env {
|
|
||||||
env[k] = strings.ReplaceAll(v, "\\n", "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
must(runner.Run(config, "rootfs/", "cache/", ".", nil, false, env))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func must(err error, where ...string) {
|
func must(err error, where ...string) {
|
||||||
|
|
|
@ -1,42 +1,14 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
|
<pre></pre>
|
||||||
<h1>Build a webhook!</h1>
|
|
||||||
|
|
||||||
<form>
|
|
||||||
<input type="text" name="k1" placeholder="k1" />
|
|
||||||
<textarea name="v1" placeholder="v1"></textarea><br />
|
|
||||||
<input type="text" name="k2" placeholder="k2" />
|
|
||||||
<textarea name="v2" placeholder="v2"></textarea><br />
|
|
||||||
<input type="text" name="k3" placeholder="k3" />
|
|
||||||
<textarea name="v3" placeholder="v3"></textarea><br />
|
|
||||||
<input type="text" name="k4" placeholder="k4" />
|
|
||||||
<textarea name="v4" placeholder="v4"></textarea><br />
|
|
||||||
<input type="text" name="k5" placeholder="k5" />
|
|
||||||
<textarea name="v5" placeholder="v5"></textarea><br />
|
|
||||||
<button>Build URL</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<input id="output" readonly />
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const form = document.querySelector("form");
|
const el = document.querySelector("pre");
|
||||||
const output = document.querySelector("#output");
|
const id = location.hash.slice(1);
|
||||||
form.addEventListener("submit", (event) => {
|
const ws = new WebSocket(
|
||||||
event.preventDefault();
|
location.origin.replace(/^http/, "ws") + "/logs/socket/" + id
|
||||||
|
);
|
||||||
let url = new URL(location.href);
|
window.ws = ws;
|
||||||
url.pathname = "/webhook";
|
ws.addEventListener("message", async (event) => {
|
||||||
for (let i = 1; i < 6; i++) {
|
el.append(await event.data.text());
|
||||||
const [key, value] = [
|
|
||||||
event.target[`k${i}`].value,
|
|
||||||
event.target[`v${i}`].value,
|
|
||||||
];
|
|
||||||
if (key) url.searchParams.set(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
output.value = url;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -12,10 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed index.html
|
//go:embed index.html
|
||||||
var indexHtml []byte
|
var index []byte
|
||||||
|
|
||||||
//go:embed run.html
|
|
||||||
var runHtml []byte
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config := parseConfig()
|
config := parseConfig()
|
||||||
|
@ -39,8 +36,7 @@ func main() {
|
||||||
|
|
||||||
http.Handle("/webhook", webhook{config: config, gitea: g})
|
http.Handle("/webhook", webhook{config: config, gitea: g})
|
||||||
http.Handle("/logs/socket/", logWebsocket{})
|
http.Handle("/logs/socket/", logWebsocket{})
|
||||||
http.Handle("/", staticRoute{file: indexHtml, mime: "text/html; charset=utf-8"})
|
http.Handle("/", staticRoute{file: index, mime: "text/html; charset=utf-8"})
|
||||||
http.Handle("/run", staticRoute{file: runHtml, mime: "text/html; charset=utf-8"})
|
|
||||||
log.Fatal(http.ListenAndServe(port, nil))
|
log.Fatal(http.ListenAndServe(port, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<pre></pre>
|
|
||||||
<script>
|
|
||||||
const el = document.querySelector("pre");
|
|
||||||
const id = location.hash.slice(1);
|
|
||||||
const ws = new WebSocket(
|
|
||||||
location.origin.replace(/^http/, "ws") + "/logs/socket/" + id
|
|
||||||
);
|
|
||||||
window.ws = ws;
|
|
||||||
ws.addEventListener("message", async (event) => {
|
|
||||||
el.append(await event.data.text());
|
|
||||||
});
|
|
||||||
</script>
|
|
|
@ -140,7 +140,7 @@ func (h webhook) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
runId := req.Header.Get("X-Gitea-Delivery")
|
runId := req.Header.Get("X-Gitea-Delivery")
|
||||||
runUrl := h.config.publicUrl + "/run#" + runId
|
runUrl := h.config.publicUrl + "/#" + runId
|
||||||
log.Printf("New run: %s", runUrl)
|
log.Printf("New run: %s", runUrl)
|
||||||
run := runss.newRun(runId)
|
run := runss.newRun(runId)
|
||||||
defer run.finishRun()
|
defer run.finishRun()
|
||||||
|
@ -213,14 +213,7 @@ func (h webhook) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
query := req.URL.Query()
|
err = runner.Run(*runnerConfig, rootfs, cache, src, run, h.config.doNotDeleteTmp)
|
||||||
env := make(map[string]string)
|
|
||||||
for key := range query {
|
|
||||||
val := query.Get(key)
|
|
||||||
env[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
err = runner.Run(*runnerConfig, rootfs, cache, src, run, h.config.doNotDeleteTmp, env)
|
|
||||||
state := "success"
|
state := "success"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("runner.Run", err)
|
log.Println("runner.Run", err)
|
||||||
|
|
5
go.mod
5
go.mod
|
@ -7,7 +7,4 @@ require (
|
||||||
nhooyr.io/websocket v1.8.7
|
nhooyr.io/websocket v1.8.7
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require github.com/klauspost/compress v1.10.3 // indirect
|
||||||
github.com/joho/godotenv v1.4.0 // indirect
|
|
||||||
github.com/klauspost/compress v1.10.3 // indirect
|
|
||||||
)
|
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -25,8 +25,6 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
|
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
|
||||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
|
||||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
|
||||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eTO0Q8=
|
github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eTO0Q8=
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
//go:embed alpine/keys
|
//go:embed alpine/keys
|
||||||
var alpineKeys embed.FS
|
var alpineKeys embed.FS
|
||||||
|
|
||||||
func Run(config Config, rootfs string, cache string, src string, w io.Writer, dontDeleteTemp bool, env map[string]string) (err error) {
|
func Run(config Config, rootfs string, cache string, src string, w io.Writer, dontDeleteTemp bool) (err error) {
|
||||||
if err = os.RemoveAll(rootfs); err != nil {
|
if err = os.RemoveAll(rootfs); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600); err != nil {
|
||||||
cmd := exec.Command("apk", "add",
|
cmd := exec.Command("apk", "add",
|
||||||
"--root", rootfs,
|
"--root", rootfs,
|
||||||
"--initdb",
|
"--initdb",
|
||||||
"--cache-dir", path.Join("..", cache, "_var_cache_apk"),
|
"--cache-dir", path.Join(cache, "_var_cache_apk"),
|
||||||
"apk-tools")
|
"apk-tools")
|
||||||
if err = cmd.Run(); err != nil {
|
if err = cmd.Run(); err != nil {
|
||||||
return fmt.Errorf("apk add apk-tools: %w", err)
|
return fmt.Errorf("apk add apk-tools: %w", err)
|
||||||
|
@ -92,9 +92,7 @@ https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600); err != nil {
|
||||||
},
|
},
|
||||||
cachedParams...)
|
cachedParams...)
|
||||||
|
|
||||||
for k, v := range env {
|
log.Println(strings.Join(params, " "))
|
||||||
params = append(params, "--setenv", k, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = exec.Command("bwrap", append(params,
|
cmd = exec.Command("bwrap", append(params,
|
||||||
"apk", "add", "--quiet", "busybox", "busybox-suid", "libc-utils", "alpine-baselayout", "alpine-conf", "alpine-release")...)
|
"apk", "add", "--quiet", "busybox", "busybox-suid", "libc-utils", "alpine-baselayout", "alpine-conf", "alpine-release")...)
|
||||||
|
|
Loading…
Reference in a new issue