1// Copyright 2023 The Gitea Authors. All rights reserved.2// SPDX-License-Identifier: MIT34package cmd56import (7 "context"8 "fmt"9 "os"10 "os/signal"1112 "gitea.com/gitea/act_runner/internal/pkg/config"1314 "github.com/nektos/act/pkg/artifactcache"15 log "github.com/sirupsen/logrus"16 "github.com/spf13/cobra"17)1819type cacheServerArgs struct {20 Dir string21 Host string22 Port uint1623}2425func runCacheServer(ctx context.Context, configFile *string, cacheArgs *cacheServerArgs) func(cmd *cobra.Command, args []string) error {26 return func(cmd *cobra.Command, args []string) error {27 cfg, err := config.LoadDefault(*configFile)28 if err != nil {29 return fmt.Errorf("invalid configuration: %w", err)30 }3132 initLogging(cfg)3334 var (35 dir = cfg.Cache.Dir36 host = cfg.Cache.Host37 port = cfg.Cache.Port38 )3940 // cacheArgs has higher priority41 if cacheArgs.Dir != "" {42 dir = cacheArgs.Dir43 }44 if cacheArgs.Host != "" {45 host = cacheArgs.Host46 }47 if cacheArgs.Port != 0 {48 port = cacheArgs.Port49 }5051 cacheHandler, err := artifactcache.StartHandler(52 dir,53 host,54 port,55 log.StandardLogger().WithField("module", "cache_request"),56 )57 if err != nil {58 return err59 }6061 log.Infof("cache server is listening on %v", cacheHandler.ExternalURL())6263 c := make(chan os.Signal, 1)64 signal.Notify(c, os.Interrupt)65 <-c6667 return nil68 }69}