1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-10-15 19:42:06 +00:00

fix: Correctly override the value of Forgejo-Cache-Host when ACTIONS_CACHE_URL is overridden.

This commit is contained in:
Vivian 2025-09-25 20:59:19 +02:00
parent 8debbe699e
commit efab761fd2
2 changed files with 10 additions and 7 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,8 +155,11 @@ func (h *Handler) newReverseProxy(targetHost string) (*httputil.ReverseProxy, er
}
func (h *Handler) ExternalURL() string {
// TODO: make the external url configurable if necessary
return fmt.Sprintf("http://%s", net.JoinHostPort(h.outboundIP, strconv.Itoa(h.listener.Addr().(*net.TCPAddr).Port)))
if h.cacheProxyHostOverride != "" {
return h.cacheProxyHostOverride
} else {
return fmt.Sprintf("http://%s", net.JoinHostPort(h.outboundIP, strconv.Itoa(h.listener.Addr().(*net.TCPAddr).Port)))
}
}
// Informs the proxy of a workflow run that can make cache requests.