Skip to content

Commit

Permalink
Merge pull request moby#4702 from crazy-max/gha-cache-timeout
Browse files Browse the repository at this point in the history
cache(gha): add timeout attr for cache export/import
  • Loading branch information
tonistiigi authored Feb 28, 2024
2 parents 3888649 + 6b5d5d6 commit 7b23ff0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,12 @@ in your workflow to expose the runtime.
* `max`: export all the layers of all intermediate steps
* `scope=<scope>`: which scope cache object belongs to (default `buildkit`)
* `ignore-error=<false|true>`: specify if error is ignored in case cache export fails (default: `false`)
* `timeout=<duration>`: sets the timeout duration for cache export (default: `10m`)

`--import-cache` options:
* `type=gha`
* `scope=<scope>`: which scope cache object belongs to (default `buildkit`)
* `timeout=<duration>`: sets the timeout duration for cache import (default: `10m`)

#### S3 cache (experimental)

Expand Down
43 changes: 31 additions & 12 deletions cache/remotecache/gha/gha.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7b23ff0

Please sign in to comment.