github-actions-cache-server icon indicating copy to clipboard operation
github-actions-cache-server copied to clipboard

Container action is missing ACTIONS_RESULTS_URL

Open saez0pub opened this issue 10 months ago • 10 comments

Hello,

As we patch the binary for ACTIONS_RESULTS_URL, the container action are missing the ACTIONS_RESULTS_URL variable.

I had this error in actions/upload step:

Error: Unable to get the ACTIONS_RESULTS_URL env variable

Here is the test I've setup: https://github.com/saez0pub/testing-self-hosted-cache

I ended up to patch the runner and rebuild it.

diff --git a/src/Runner.Worker/Handlers/ContainerActionHandler.cs b/src/Runner.Worker/Handlers/ContainerActionHandler.cs
index 775ce2f0..0d306016 100644
--- a/src/Runner.Worker/Handlers/ContainerActionHandler.cs
+++ b/src/Runner.Worker/Handlers/ContainerActionHandler.cs
@@ -219,7 +219,12 @@ namespace GitHub.Runner.Worker.Handlers
             var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
             Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri;
             Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
-            if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
+            string customActionCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL");
+            string customActionsResultsUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_RESULTS_URL");
+            if (!string.IsNullOrEmpty(customActionCacheUrl))
+            {
+                Environment["ACTIONS_CACHE_URL"] = customActionCacheUrl;
+            } else if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
             {
                 Environment["ACTIONS_CACHE_URL"] = cacheUrl;
             }
@@ -232,7 +237,10 @@ namespace GitHub.Runner.Worker.Handlers
                 Environment["ACTIONS_ID_TOKEN_REQUEST_URL"] = generateIdTokenUrl;
                 Environment["ACTIONS_ID_TOKEN_REQUEST_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
             }
-            if (systemConnection.Data.TryGetValue("ResultsServiceUrl", out var resultsUrl) && !string.IsNullOrEmpty(resultsUrl))
+            if (!string.IsNullOrEmpty(customActionsResultsUrl))
+            {
+                Environment["ACTIONS_RESULTS_URL"] = customActionsResultsUrl;
+            } else if (systemConnection.Data.TryGetValue("ResultsServiceUrl", out var resultsUrl) && !string.IsNullOrEmpty(resultsUrl))
             {
                 Environment["ACTIONS_RESULTS_URL"] = resultsUrl;
             }
diff --git a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs
index a399f13d..7106d144 100644
--- a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs
+++ b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs
@@ -54,7 +54,12 @@ namespace GitHub.Runner.Worker.Handlers
             var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
             Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri;
             Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
-            if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
+            string customActionCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL");
+            string customActionsResultsUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_RESULTS_URL");
+            if (!string.IsNullOrEmpty(customActionCacheUrl))
+            {
+                Environment["ACTIONS_CACHE_URL"] = customActionCacheUrl;
+            } else if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
             {
                 Environment["ACTIONS_CACHE_URL"] = cacheUrl;
             }
@@ -67,7 +72,10 @@ namespace GitHub.Runner.Worker.Handlers
                 Environment["ACTIONS_ID_TOKEN_REQUEST_URL"] = generateIdTokenUrl;
                 Environment["ACTIONS_ID_TOKEN_REQUEST_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
             }
-            if (systemConnection.Data.TryGetValue("ResultsServiceUrl", out var resultsUrl) && !string.IsNullOrEmpty(resultsUrl))
+            if (!string.IsNullOrEmpty(customActionsResultsUrl))
+            {
+                Environment["ACTIONS_RESULTS_URL"] = customActionsResultsUrl;
+            } else if (systemConnection.Data.TryGetValue("ResultsServiceUrl", out var resultsUrl) && !string.IsNullOrEmpty(resultsUrl))
             {
                 Environment["ACTIONS_RESULTS_URL"] = resultsUrl;
             }

And using these variables:

CUSTOM_ACTIONS_CACHE_URL=http://yourip:3000/
CUSTOM_ACTIONS_RESULTS_URL=http://yourip:3000/

saez0pub avatar Mar 18 '25 18:03 saez0pub

I just faced similar issue when switched to local cache for github runners. Any plans to fix that without recompiling the code?

dawidmalina avatar May 23 '25 16:05 dawidmalina

I currently don't see a way other than compiling a patched version of the runner. Maybe we could provide a drop-in replacement runner binary with the mentioned patches so you don't have to compile your own?

Feel free to share any other ideas. 🙏

LouisHaftmann avatar May 23 '25 16:05 LouisHaftmann

I like the idea of having drop in replacement!

dawidmalina avatar May 23 '25 17:05 dawidmalina

You can check out the image here https://github.com/falcondev-oss/runner/pkgs/container/actions-runner

use CUSTOM_ACTIONS_RESULTS_URL

LouisHaftmann avatar May 23 '25 20:05 LouisHaftmann

I will try to verify that image today. Should I only configure one variable CUSTOM_ACTIONS_RESULTS_URL or both variablesCUSTOM_ACTIONS_RESULTS_URL and CUSTOM_ACTIONS_CACHE_URL?

dawidmalina avatar May 26 '25 09:05 dawidmalina

only CUSTOM_ACTIONS_RESULTS_URL, ACTIONS_CACHE_URL is not used anymore if you're not using old cache actions

LouisHaftmann avatar May 26 '25 13:05 LouisHaftmann

Ok. I was able to setup simple workflow and confirmed that in both cases everything is working. Pure ubuntu runner and runner with node container are successful. Now I need to figured out how to use your runner as I am already using my custom base image that use latest ubuntu 24 plus few other packages that are useful for our builds:

          # workarround: https://github.com/actions/runner/issues/3623
          sed -i 's/8.0-jammy/9.0-noble/g' runner-${{ github.event.inputs.github_runner_version }}/images/Dockerfile
          sed -i 's/ubuntu22/ubuntu24/g' runner-${{ github.event.inputs.github_runner_version }}/images/Dockerfile

are you able to publish runner.tar.gz as well?

dawidmalina avatar May 26 '25 14:05 dawidmalina

https://github.com/falcondev-oss/runner/releases/tag/v2.324.0

LouisHaftmann avatar May 26 '25 14:05 LouisHaftmann

That appears to have worked until Github released 2.235.0. Watching my @falcondev-oss/runners immediately update themselves on boot and (apparently) lose the override and revert to github centralized caching.

gotwalt avatar Jun 16 '25 22:06 gotwalt

You need to disable auto update when using the cache server. Freeze the runner image and manually update.

kuhnroyal avatar Jun 16 '25 23:06 kuhnroyal