garm/cache/endpoint_cache.go
Gabriel Adrian Samfira 5fdb69ac18 Add the ability to set tools download source (Gitea)
This change adds 2 new options to gitea forge endpoints:

* Tools metadata URL
* Use internal tools URLs

By default, GARM looks in the releases page of the gitea arc_runner
to determine where it can download the runner binary from for a particular
OS/arch. The tools metadata URL option can be set on an endpoint and can point
to a mirror of the upstream repo. The requirement is that the asset names
exactly mirror upstream naming conventions.

The second option disables GARM calling out to the tools metadata URL entirely.
GARM has some hardcoded values for nightly binaries. If this option is checked,
GARM will use those values, without making any kind of outgoing API call to
determine availability. This is useful in air-gapped environments.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2025-09-26 18:59:15 +03:00

72 lines
1.7 KiB
Go

// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cache
import (
"sync"
"github.com/cloudbase/garm/params"
)
var endpointCache *EndpointCache
func init() {
epCache := &EndpointCache{
endpoints: make(map[string]params.ForgeEndpoint),
}
endpointCache = epCache
}
type EndpointCache struct {
endpoints map[string]params.ForgeEndpoint
mux sync.Mutex
}
func (e *EndpointCache) SetEndpoint(ep params.ForgeEndpoint) {
e.mux.Lock()
defer e.mux.Unlock()
e.endpoints[ep.Name] = ep
UpdateCredentialsUsingEndpoint(ep)
}
func (e *EndpointCache) GetEndpoint(epName string) (params.ForgeEndpoint, bool) {
e.mux.Lock()
defer e.mux.Unlock()
ep, ok := e.endpoints[epName]
if ok {
return ep, true
}
return params.ForgeEndpoint{}, false
}
func (e *EndpointCache) RemoveEndpoint(epName string) {
e.mux.Lock()
defer e.mux.Unlock()
delete(e.endpoints, epName)
}
func SetEndpoint(ep params.ForgeEndpoint) {
endpointCache.SetEndpoint(ep)
}
func GetEndpoint(epName string) (params.ForgeEndpoint, bool) {
return endpointCache.GetEndpoint(epName)
}
func RemoveEndpoint(epName string) {
endpointCache.RemoveEndpoint(epName)
}