diff --git a/README.md b/README.md index 3d6c3ed354b0..f8d55bbf63a1 100644 --- a/README.md +++ b/README.md @@ -519,10 +519,12 @@ in your workflow to expose the runtime. * `max`: export all the layers of all intermediate steps * `scope=`: which scope cache object belongs to (default `buildkit`) * `ignore-error=`: specify if error is ignored in case cache export fails (default: `false`) +* `timeout=`: sets the timeout duration for cache export (default: `10m`) `--import-cache` options: * `type=gha` * `scope=`: which scope cache object belongs to (default `buildkit`) +* `timeout=`: sets the timeout duration for cache import (default: `10m`) #### S3 cache (experimental) diff --git a/cache/remotecache/gha/gha.go b/cache/remotecache/gha/gha.go index 81e17102f8bb..abc2b30aa442 100644 --- a/cache/remotecache/gha/gha.go +++ b/cache/remotecache/gha/gha.go @@ -33,16 +33,20 @@ func init() { } const ( - attrScope = "scope" - attrToken = "token" - attrURL = "url" - version = "1" + attrScope = "scope" + attrTimeout = "timeout" + attrToken = "token" + attrURL = "url" + version = "1" + + defaultTimeout = 10 * time.Minute ) type Config struct { - Scope string - URL string - Token string + Scope string + URL string + Token string + Timeout time.Duration } func getConfig(attrs map[string]string) (*Config, error) { @@ -58,10 +62,19 @@ func getConfig(attrs map[string]string) (*Config, error) { if !ok { return nil, errors.Errorf("token not set for github actions cache") } + timeout := defaultTimeout + if v, ok := attrs[attrTimeout]; ok { + var err error + timeout, err = time.ParseDuration(v) + if err != nil { + return nil, errors.Wrap(err, "failed to parse timeout for github actions cache") + } + } return &Config{ - Scope: scope, - URL: url, - Token: token, + Scope: scope, + URL: url, + Token: token, + Timeout: timeout, }, nil } @@ -85,7 +98,10 @@ type exporter struct { func NewExporter(c *Config) (remotecache.Exporter, error) { cc := v1.NewCacheChains() - cache, err := actionscache.New(c.Token, c.URL, actionscache.Opt{Client: tracing.DefaultClient}) + cache, err := actionscache.New(c.Token, c.URL, actionscache.Opt{ + Client: tracing.DefaultClient, + Timeout: c.Timeout, + }) if err != nil { return nil, err } @@ -212,7 +228,10 @@ type importer struct { } func NewImporter(c *Config) (remotecache.Importer, error) { - cache, err := actionscache.New(c.Token, c.URL, actionscache.Opt{Client: tracing.DefaultClient}) + cache, err := actionscache.New(c.Token, c.URL, actionscache.Opt{ + Client: tracing.DefaultClient, + Timeout: c.Timeout, + }) if err != nil { return nil, err }