From 6bdb7ed9c793b3cf93341c95a0b6629bd1381b34 Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Fri, 26 Sep 2025 07:02:45 +0000 Subject: [PATCH] fix: Correctly override the value of `Forgejo-Cache-Host` when ACTIONS_CACHE_URL is overridden. (#1027) This fixes a bug currently preventing use of an external cache server in the Codeberg runner setup. - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1027): fix: Correctly override the value of `Forgejo-Cache-Host` when ACTIONS_CACHE_URL is overridden. Co-authored-by: Vivian Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1027 Reviewed-by: Michael Kriese Reviewed-by: Mathieu Fenniak Co-authored-by: Kwonunn Co-committed-by: Kwonunn --- act/cacheproxy/handler.go | 10 +++++++--- internal/app/run/runner.go | 4 +--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/act/cacheproxy/handler.go b/act/cacheproxy/handler.go index 17adf3b5..e494b9c5 100644 --- a/act/cacheproxy/handler.go +++ b/act/cacheproxy/handler.go @@ -37,7 +37,8 @@ type Handler struct { outboundIP string - cacheServerHost string + cacheServerHost string + cacheProxyHostOverride string cacheSecret string @@ -55,7 +56,7 @@ func (h *Handler) CreateRunData(fullName, runNumber, timestamp, writeIsolationKe } } -func StartHandler(targetHost, outboundIP string, port uint16, cacheSecret string, logger logrus.FieldLogger) (*Handler, error) { +func StartHandler(targetHost, outboundIP string, port uint16, cacheProxyHostOverride, cacheSecret string, logger logrus.FieldLogger) (*Handler, error) { h := &Handler{} if logger == nil { @@ -77,6 +78,7 @@ func StartHandler(targetHost, outboundIP string, port uint16, cacheSecret string } h.cacheServerHost = targetHost + h.cacheProxyHostOverride = cacheProxyHostOverride proxy, err := h.newReverseProxy(targetHost) if err != nil { @@ -153,7 +155,9 @@ func (h *Handler) newReverseProxy(targetHost string) (*httputil.ReverseProxy, er } func (h *Handler) ExternalURL() string { - // TODO: make the external url configurable if necessary + if h.cacheProxyHostOverride != "" { + return h.cacheProxyHostOverride + } return fmt.Sprintf("http://%s", net.JoinHostPort(h.outboundIP, strconv.Itoa(h.listener.Addr().(*net.TCPAddr).Port))) } diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index a1283d61..98a39f92 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -144,6 +144,7 @@ func setupCache(cfg *config.Config, envs map[string]string) *cacheproxy.Handler cacheURL, cfg.Cache.Host, cfg.Cache.ProxyPort, + cfg.Cache.ActionsCacheURLOverride, cacheSecret, log.StandardLogger().WithField("module", "cache_proxy"), ) @@ -152,9 +153,6 @@ func setupCache(cfg *config.Config, envs map[string]string) *cacheproxy.Handler } envs["ACTIONS_CACHE_URL"] = cacheProxy.ExternalURL() - if cfg.Cache.ActionsCacheURLOverride != "" { - envs["ACTIONS_CACHE_URL"] = cfg.Cache.ActionsCacheURLOverride - } return cacheProxy }