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"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"gitea.nulo.in/Nulo/repro-run/runner"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config, err := readConfig()
|
||||
must(err)
|
||||
|
||||
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))
|
||||
must(runner.Run(config, "rootfs/", "cache/", ".", nil, false))
|
||||
}
|
||||
|
||||
func must(err error, where ...string) {
|
||||
|
|
|
@ -1,42 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8" />
|
||||
|
||||
<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 />
|
||||
|
||||
<pre></pre>
|
||||
<script>
|
||||
const form = document.querySelector("form");
|
||||
const output = document.querySelector("#output");
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
let url = new URL(location.href);
|
||||
url.pathname = "/webhook";
|
||||
for (let i = 1; i < 6; i++) {
|
||||
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;
|
||||
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>
|
||||
|
|
|
@ -12,10 +12,7 @@ import (
|
|||
)
|
||||
|
||||
//go:embed index.html
|
||||
var indexHtml []byte
|
||||
|
||||
//go:embed run.html
|
||||
var runHtml []byte
|
||||
var index []byte
|
||||
|
||||
func main() {
|
||||
config := parseConfig()
|
||||
|
@ -39,8 +36,7 @@ func main() {
|
|||
|
||||
http.Handle("/webhook", webhook{config: config, gitea: g})
|
||||
http.Handle("/logs/socket/", logWebsocket{})
|
||||
http.Handle("/", staticRoute{file: indexHtml, mime: "text/html; charset=utf-8"})
|
||||
http.Handle("/run", staticRoute{file: runHtml, mime: "text/html; charset=utf-8"})
|
||||
http.Handle("/", staticRoute{file: index, mime: "text/html; charset=utf-8"})
|
||||
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")
|
||||
runUrl := h.config.publicUrl + "/run#" + runId
|
||||
runUrl := h.config.publicUrl + "/#" + runId
|
||||
log.Printf("New run: %s", runUrl)
|
||||
run := runss.newRun(runId)
|
||||
defer run.finishRun()
|
||||
|
@ -213,14 +213,7 @@ func (h webhook) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
query := req.URL.Query()
|
||||
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)
|
||||
err = runner.Run(*runnerConfig, rootfs, cache, src, run, h.config.doNotDeleteTmp)
|
||||
state := "success"
|
||||
if err != nil {
|
||||
log.Println("runner.Run", err)
|
||||
|
|
5
go.mod
5
go.mod
|
@ -7,7 +7,4 @@ require (
|
|||
nhooyr.io/websocket v1.8.7
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/joho/godotenv v1.4.0 // indirect
|
||||
github.com/klauspost/compress v1.10.3 // indirect
|
||||
)
|
||||
require 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/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/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/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eTO0Q8=
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
//go:embed alpine/keys
|
||||
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 {
|
||||
return
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600); err != nil {
|
|||
cmd := exec.Command("apk", "add",
|
||||
"--root", rootfs,
|
||||
"--initdb",
|
||||
"--cache-dir", path.Join("..", cache, "_var_cache_apk"),
|
||||
"--cache-dir", path.Join(cache, "_var_cache_apk"),
|
||||
"apk-tools")
|
||||
if err = cmd.Run(); err != nil {
|
||||
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...)
|
||||
|
||||
for k, v := range env {
|
||||
params = append(params, "--setenv", k, v)
|
||||
}
|
||||
log.Println(strings.Join(params, " "))
|
||||
|
||||
cmd = exec.Command("bwrap", append(params,
|
||||
"apk", "add", "--quiet", "busybox", "busybox-suid", "libc-utils", "alpine-baselayout", "alpine-conf", "alpine-release")...)
|
||||
|
|
Loading…
Reference in a new issue