From 9423d5fd6d2aab36e5a683e47e01d4baca86fd51 Mon Sep 17 00:00:00 2001
From: SeanOMik <seanomik@gmail.com>
Date: Thu, 2 Jan 2025 13:19:20 -0500
Subject: [PATCH] fix(forgejo-runner): add init container to fix cache
 permissions

---
 .../main/apps/dev/forgejo-runner/app/config.yaml   |  2 +-
 .../apps/dev/forgejo-runner/app/runner-dep.yaml    | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/kubernetes/main/apps/dev/forgejo-runner/app/config.yaml b/kubernetes/main/apps/dev/forgejo-runner/app/config.yaml
index e5fdc202..9128046a 100644
--- a/kubernetes/main/apps/dev/forgejo-runner/app/config.yaml
+++ b/kubernetes/main/apps/dev/forgejo-runner/app/config.yaml
@@ -59,7 +59,7 @@ data:
       enabled: true
       # The directory to store the cache data.
       # If it's empty, the cache data will be stored in $HOME/.cache/actcache.
-      dir: "/cache"
+      dir: ""
       # The host of the cache server.
       # It's not for the address to listen, but the address to connect from job containers.
       # So 0.0.0.0 is a bad choice, leave it empty to detect automatically.
diff --git a/kubernetes/main/apps/dev/forgejo-runner/app/runner-dep.yaml b/kubernetes/main/apps/dev/forgejo-runner/app/runner-dep.yaml
index 8b7f02d1..49c9dce2 100644
--- a/kubernetes/main/apps/dev/forgejo-runner/app/runner-dep.yaml
+++ b/kubernetes/main/apps/dev/forgejo-runner/app/runner-dep.yaml
@@ -50,10 +50,20 @@ spec:
           volumeMounts:
             - name: runner-data
               mountPath: /data
+        # fix permissions of cache pvc
+        - command: ["sh", "-c", "chown -R 1000:1000 /data/.cache"]
+          image: busybox
+          volumeMounts:
+          - mountPath: /data/.cache/actcache
+            name: forgejo-runner-cache
+          name: fix-permissions
       containers:
       - name: runner
         image: *runnerImg
-        command: ["sh", "-c", "while ! nc -z localhost 2376 </dev/null; do echo 'waiting for docker daemon...'; sleep 5; done; forgejo-runner daemon --config /data/config.yml"]
+        command:
+          - "sh"
+          - "-c"
+          - "while ! nc -z localhost 2376 </dev/null; do echo 'waiting for docker daemon...'; sleep 5; done; forgejo-runner daemon --config /data/config.yml"
         env:
         - name: DOCKER_HOST
           value: tcp://localhost:2376
@@ -70,7 +80,7 @@ spec:
           mountPath: /data/config.yml
           subPath: config.yml
         - name: forgejo-runner-cache
-          mountPath: /cache
+          mountPath: /data/.cache/actcache
       - name: daemon
         image: docker:27.4.1-dind
         env: