From 8419ef767ca827de51595e3dd520bc5f2892778d Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:57:10 +0100 Subject: [PATCH 1/2] cache(gha): add timeout attr for cache export/import Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- README.md | 2 ++ cache/remotecache/gha/gha.go | 43 ++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9438d6369503..aafe2ce63e21 100644 --- a/README.md +++ b/README.md @@ -506,10 +506,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: `5m`) `--import-cache` options: * `type=gha` * `scope=`: which scope cache object belongs to (default `buildkit`) +* `timeout=`: sets the timeout duration for cache import (default: `5m`) #### S3 cache (experimental) diff --git a/cache/remotecache/gha/gha.go b/cache/remotecache/gha/gha.go index 81e17102f8bb..47f1a2db7985 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 = 5 * 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 } From 6b5d5d6746212de2ad0f1b20a21ff05d35506d4d Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:57:26 +0100 Subject: [PATCH 2/2] cache(gha): increase default timeout to 10m Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- README.md | 4 ++-- cache/remotecache/gha/gha.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aafe2ce63e21..8e916cb96a4a 100644 --- a/README.md +++ b/README.md @@ -506,12 +506,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: `5m`) +* `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: `5m`) +* `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 47f1a2db7985..abc2b30aa442 100644 --- a/cache/remotecache/gha/gha.go +++ b/cache/remotecache/gha/gha.go @@ -39,7 +39,7 @@ const ( attrURL = "url" version = "1" - defaultTimeout = 5 * time.Minute + defaultTimeout = 10 * time.Minute ) type Config struct {