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:
parent
8debbe699e
commit
efab761fd2
2 changed files with 10 additions and 7 deletions
|
@ -38,6 +38,7 @@ type Handler struct {
|
|||
outboundIP 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,9 +155,12 @@ 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
|
||||
} 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.
|
||||
// The RunData contains the information about the repository.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue