lol
This commit is contained in:
commit
8c7b36c07b
9 changed files with 167 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
cache/
|
||||
rootfs/
|
||||
test
|
|
@ -0,0 +1,9 @@
|
|||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1yHJxQgsHQREclQu4Ohe
|
||||
qxTxd1tHcNnvnQTu/UrTky8wWvgXT+jpveroeWWnzmsYlDI93eLI2ORakxb3gA2O
|
||||
Q0Ry4ws8vhaxLQGC74uQR5+/yYrLuTKydFzuPaS1dK19qJPXB8GMdmFOijnXX4SA
|
||||
jixuHLe1WW7kZVtjL7nufvpXkWBGjsfrvskdNA/5MfxAeBbqPgaq0QMEfxMAn6/R
|
||||
L5kNepi/Vr4S39Xvf2DzWkTLEK8pcnjNkt9/aafhWqFVW7m3HCAII6h/qlQNQKSo
|
||||
GuH34Q8GsFG30izUENV9avY7hSLq7nggsvknlNBZtFUcmGoQrtx3FmyYsIC8/R+B
|
||||
ywIDAQAB
|
||||
-----END PUBLIC KEY-----
|
|
@ -0,0 +1,9 @@
|
|||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvNijDxJ8kloskKQpJdx+
|
||||
mTMVFFUGDoDCbulnhZMJoKNkSuZOzBoFC94omYPtxnIcBdWBGnrm6ncbKRlR+6oy
|
||||
DO0W7c44uHKCFGFqBhDasdI4RCYP+fcIX/lyMh6MLbOxqS22TwSLhCVjTyJeeH7K
|
||||
aA7vqk+QSsF4TGbYzQDDpg7+6aAcNzg6InNePaywA6hbT0JXbxnDWsB+2/LLSF2G
|
||||
mnhJlJrWB1WGjkz23ONIWk85W4S0XB/ewDefd4Ly/zyIciastA7Zqnh7p3Ody6Q0
|
||||
sS2MJzo7p3os1smGjUF158s6m/JbVh4DN6YIsxwl2OjDO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OMggmd90s3xIbEujA6HKNP/gwzO6CDJ+nHFDEqoF
|
||||
SkxRdTkEqjTjVKieURW7Swv7zpfu5PrsrrkyGnsRrBJJzXlm2FOOxnbI2iSL1B5F
|
||||
rO5kbUxFeZUIDq+7Yv4kLWcCAwEAAQ==
|
||||
-----END PUBLIC KEY-----
|
16
config.go
Normal file
16
config.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Command string
|
||||
Cache []string
|
||||
}
|
||||
|
||||
func readConfig() (config Config, err error) {
|
||||
err = json.NewDecoder(os.Stdin).Decode(&config)
|
||||
return
|
||||
}
|
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module gitea.nulo.in/Nulo/repro-run
|
||||
|
||||
go 1.19
|
90
main.go
Normal file
90
main.go
Normal file
|
@ -0,0 +1,90 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed alpine/keys
|
||||
var alpineKeys embed.FS
|
||||
|
||||
func main() {
|
||||
config, err := readConfig()
|
||||
must(err)
|
||||
|
||||
must(os.MkdirAll("rootfs/etc/apk/keys", 0700))
|
||||
must(os.WriteFile("rootfs/etc/apk/repositories", []byte(
|
||||
`https://dl-cdn.alpinelinux.org/alpine/v3.17/main
|
||||
https://dl-cdn.alpinelinux.org/alpine/v3.17/community`), 0600))
|
||||
must(os.WriteFile("rootfs/etc/resolv.conf", []byte(
|
||||
`nameserver 8.8.8.8`), 0644))
|
||||
keys, err := alpineKeys.ReadDir("alpine/keys")
|
||||
must(err)
|
||||
for _, entry := range keys {
|
||||
o, err := os.Create(path.Join("rootfs/etc/apk/keys/", entry.Name()))
|
||||
must(err)
|
||||
s, err := alpineKeys.Open(path.Join("alpine/keys", entry.Name()))
|
||||
must(err)
|
||||
_, err = io.Copy(o, s)
|
||||
must(err)
|
||||
}
|
||||
|
||||
must(os.MkdirAll("cache/_var_cache_apk", 0700))
|
||||
os.Remove("rootfs/etc/apk/cache")
|
||||
must(os.Symlink("/var/cache/apk", "rootfs/etc/apk/cache"))
|
||||
// must(os.MkdirAll("rootfs/var/cache", 0700))
|
||||
// must(os.RemoveAll("rootfs/var/cache/apk"))
|
||||
// must(os.Symlink("../../../cache/apk", "rootfs/var/cache/apk"))
|
||||
cmd := exec.Command("apk", "add",
|
||||
"--root", "rootfs",
|
||||
"--initdb",
|
||||
"--cache-dir", "../cache/_var_cache_apk",
|
||||
"apk-tools")
|
||||
must(cmd.Run(), "apk add apk-tools")
|
||||
// must(os.Remove("rootfs/var/cache/apk"))
|
||||
|
||||
cached := append(config.Cache, "/var/cache/apk")
|
||||
var cachedParams []string
|
||||
for _, c := range cached {
|
||||
cacheDir := path.Join("./cache", strings.ReplaceAll(c, "/", "_"))
|
||||
must(os.MkdirAll(cacheDir, 0700))
|
||||
cachedParams = append(cachedParams, "--bind", cacheDir, c)
|
||||
}
|
||||
|
||||
tmp, err := os.MkdirTemp("", "repro-run-")
|
||||
must(err)
|
||||
|
||||
params := append(
|
||||
[]string{"--bind", "./rootfs", "/",
|
||||
"--ro-bind", ".", "/src",
|
||||
"--bind", tmp, "/work",
|
||||
"--chdir", "/work",
|
||||
},
|
||||
cachedParams...)
|
||||
|
||||
log.Println(strings.Join(params, " "))
|
||||
|
||||
cmd = exec.Command("bwrap", append(params,
|
||||
"apk", "add", "busybox", "busybox-suid", "libc-utils", "alpine-baselayout", "alpine-conf", "alpine-release")...)
|
||||
// cmd.Stdout = os.Stdout
|
||||
// cmd.Stderr = os.Stderr
|
||||
must(cmd.Run())
|
||||
|
||||
cmd = exec.Command("bwrap", append(params, strings.Split(config.Command, " ")...)...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
must(cmd.Run())
|
||||
|
||||
}
|
||||
|
||||
func must(err error, where ...string) {
|
||||
if err != nil {
|
||||
log.Fatal(err, where)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue