]> ruderich.org/simon Gitweb - punyci/punyci.git/commitdiff
Add Cache option
authorSimon Ruderich <simon@ruderich.org>
Sun, 22 Feb 2026 17:04:56 +0000 (18:04 +0100)
committerSimon Ruderich <simon@ruderich.org>
Sun, 22 Feb 2026 17:04:56 +0000 (18:04 +0100)
.punyci.toml
job.go
main.go

index b19845bb1be0a133fbdc22482241b655bc34ffbe..aa6c54c389052d7d67a507ff72f9578b6ba886fa 100644 (file)
@@ -1,3 +1,8 @@
 [[Jobs]]
 Image = "golang:1.26"
-Script = "./ci/run"
+Script = """
+mkdir -p /punyci-cache/pkg
+ln -s /punyci-cache/pkg /go/pkg
+./ci/run
+"""
+Cache = true
diff --git a/job.go b/job.go
index 95de35edbbec1be3f45360900049763a860151f3..d4edd6643ca041cce182309fbf2946970c487caf 100644 (file)
--- a/job.go
+++ b/job.go
@@ -39,20 +39,37 @@ func RunJob(wg *sync.WaitGroup, tmp string, info Info, job Job,
                return err
        }
 
+       cachePath := filepath.Join(cwd, "punyci-cache-"+strconv.Itoa(job.id))
+       if job.Cache {
+               err := os.MkdirAll(cachePath, 0700)
+               if err != nil {
+                       return err
+               }
+       }
+
        // Start container but do not run the script yet. We need a way to a)
        // sleep in case of an error so the user can analyze the failure and b)
        // detect when the script terminates. The simplest solution is to run the
        // script using exec while the container just sleeps forever.
-       cmd := exec.Command("podman", "run", "--rm", "--detach",
+       args := []string{
+               "run", "--rm", "--detach",
                "--pull", "newer",
                "--log-driver", "none", // don't log to journal
-               "--volume", repoPath+":/punyci-repo",
-               "--volume", scriptPath+":/punyci-script:ro",
+               "--volume", repoPath + ":/punyci-repo",
+               "--volume", scriptPath + ":/punyci-script:ro",
+       }
+       if job.Cache {
+               args = append(args,
+                       "--volume", cachePath+":/punyci-cache",
+               )
+       }
+       args = append(args,
                "--entrypoint", "sh", // overwrite if set
                "--",
                job.Image,
                "-c", "while :; do sleep 86400; done", // sleep forever
        )
+       cmd := exec.Command("podman", args...)
        out, err := cmd.Output()
        if err != nil {
                return err
diff --git a/main.go b/main.go
index 77efd3473c177e42007490d8d1f926650b3b11db..a70dd4d259fb693a1b9819f0a424d415742dd41a 100644 (file)
--- a/main.go
+++ b/main.go
@@ -27,6 +27,7 @@ type Job struct {
        id     int
        Image  string
        Script string
+       Cache  bool
 }
 
 func main() {