From: Simon Ruderich Date: Sun, 22 Feb 2026 17:04:56 +0000 (+0100) Subject: Add Cache option X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=69613cf950bfc7a01e6f8939979c627d37dab0a6;p=punyci%2Fpunyci.git Add Cache option --- diff --git a/.punyci.toml b/.punyci.toml index b19845b..aa6c54c 100644 --- a/.punyci.toml +++ b/.punyci.toml @@ -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 95de35e..d4edd66 100644 --- 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 77efd34..a70dd4d 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ type Job struct { id int Image string Script string + Cache bool } func main() {