1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-30 19:22:09 +00:00

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.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1027): <!--number 1027 --><!--line 0 --><!--description Zml4OiBDb3JyZWN0bHkgb3ZlcnJpZGUgdGhlIHZhbHVlIG9mIGBGb3JnZWpvLUNhY2hlLUhvc3RgIHdoZW4gQUNUSU9OU19DQUNIRV9VUkwgaXMgb3ZlcnJpZGRlbi4=-->fix: Correctly override the value of `Forgejo-Cache-Host` when ACTIONS_CACHE_URL is overridden.<!--description-->
<!--end release-notes-assistant-->

Co-authored-by: Vivian <me@vivstuff.gay>
Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1027
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Kwonunn <kwonunn@noreply.code.forgejo.org>
Co-committed-by: Kwonunn <kwonunn@noreply.code.forgejo.org>
This commit is contained in:
Kwonunn 2025-09-26 07:02:45 +00:00 committed by earl-warren
parent 8debbe699e
commit 6bdb7ed9c7
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
2 changed files with 8 additions and 6 deletions

View file

@ -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)))
}

View file

@ -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
}