1 Commits

Author SHA1 Message Date
林玮 (Jade Lin)
9661a37003 Make the external url of cache server configurable if necessary
Some checks failed
checks / check and test (push) Failing after 21s
2024-09-06 13:12:58 +02:00
3 changed files with 15 additions and 7 deletions

View File

@@ -46,6 +46,7 @@ type Input struct {
artifactServerPort string artifactServerPort string
noCacheServer bool noCacheServer bool
cacheServerPath string cacheServerPath string
cacheServerAdvertiseURL string
cacheServerAddr string cacheServerAddr string
cacheServerPort uint16 cacheServerPort uint16
jsonLogger bool jsonLogger bool

View File

@@ -94,6 +94,7 @@ func Execute(ctx context.Context, version string) {
rootCmd.PersistentFlags().BoolVarP(&input.noSkipCheckout, "no-skip-checkout", "", false, "Do not skip actions/checkout") rootCmd.PersistentFlags().BoolVarP(&input.noSkipCheckout, "no-skip-checkout", "", false, "Do not skip actions/checkout")
rootCmd.PersistentFlags().BoolVarP(&input.noCacheServer, "no-cache-server", "", false, "Disable cache server") rootCmd.PersistentFlags().BoolVarP(&input.noCacheServer, "no-cache-server", "", false, "Disable cache server")
rootCmd.PersistentFlags().StringVarP(&input.cacheServerPath, "cache-server-path", "", filepath.Join(CacheHomeDir, "actcache"), "Defines the path where the cache server stores caches.") rootCmd.PersistentFlags().StringVarP(&input.cacheServerPath, "cache-server-path", "", filepath.Join(CacheHomeDir, "actcache"), "Defines the path where the cache server stores caches.")
rootCmd.PersistentFlags().StringVarP(&input.cacheServerAdvertiseURL, "cache-server-advertise-url", "", "", "Defines the URL for advertising the cache server behind a proxy. e.g.: https://act-cache-server.example.com")
rootCmd.PersistentFlags().StringVarP(&input.cacheServerAddr, "cache-server-addr", "", common.GetOutboundIP().String(), "Defines the address to which the cache server binds.") rootCmd.PersistentFlags().StringVarP(&input.cacheServerAddr, "cache-server-addr", "", common.GetOutboundIP().String(), "Defines the address to which the cache server binds.")
rootCmd.PersistentFlags().Uint16VarP(&input.cacheServerPort, "cache-server-port", "", 0, "Defines the port where the artifact server listens. 0 means a randomly available port.") rootCmd.PersistentFlags().Uint16VarP(&input.cacheServerPort, "cache-server-port", "", 0, "Defines the port where the artifact server listens. 0 means a randomly available port.")
rootCmd.PersistentFlags().StringVarP(&input.actionCachePath, "action-cache-path", "", filepath.Join(CacheHomeDir, "act"), "Defines the path where the actions get cached and host workspaces created.") rootCmd.PersistentFlags().StringVarP(&input.actionCachePath, "action-cache-path", "", filepath.Join(CacheHomeDir, "act"), "Defines the path where the actions get cached and host workspaces created.")
@@ -598,7 +599,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
var cacheHandler *artifactcache.Handler var cacheHandler *artifactcache.Handler
if !input.noCacheServer && envs[cacheURLKey] == "" { if !input.noCacheServer && envs[cacheURLKey] == "" {
var err error var err error
cacheHandler, err = artifactcache.StartHandler(input.cacheServerPath, input.cacheServerAddr, input.cacheServerPort, common.Logger(ctx)) cacheHandler, err = artifactcache.StartHandler(input.cacheServerPath, input.cacheServerAdvertiseURL, input.cacheServerAddr, input.cacheServerPort, common.Logger(ctx))
if err != nil { if err != nil {
return err return err
} }

View File

@@ -39,9 +39,10 @@ type Handler struct {
gcAt time.Time gcAt time.Time
outboundIP string outboundIP string
advertiseURL string
} }
func StartHandler(dir, outboundIP string, port uint16, logger logrus.FieldLogger) (*Handler, error) { func StartHandler(dir, advertiseURL, outboundIP string, port uint16, logger logrus.FieldLogger) (*Handler, error) {
h := &Handler{} h := &Handler{}
if logger == nil { if logger == nil {
@@ -71,6 +72,8 @@ func StartHandler(dir, outboundIP string, port uint16, logger logrus.FieldLogger
} }
h.storage = storage h.storage = storage
h.advertiseURL = advertiseURL
if outboundIP != "" { if outboundIP != "" {
h.outboundIP = outboundIP h.outboundIP = outboundIP
} else if ip := common.GetOutboundIP(); ip == nil { } else if ip := common.GetOutboundIP(); ip == nil {
@@ -111,11 +114,14 @@ func StartHandler(dir, outboundIP string, port uint16, logger logrus.FieldLogger
} }
func (h *Handler) ExternalURL() string { func (h *Handler) ExternalURL() string {
// TODO: make the external url configurable if necessary if h.advertiseURL != "" {
return h.advertiseURL
} else {
return fmt.Sprintf("http://%s:%d", return fmt.Sprintf("http://%s:%d",
h.outboundIP, h.outboundIP,
h.listener.Addr().(*net.TCPAddr).Port) h.listener.Addr().(*net.TCPAddr).Port)
} }
}
func (h *Handler) Close() error { func (h *Handler) Close() error {
if h == nil { if h == nil {