Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder: use buildkit's GC for build cache #37846

Merged
merged 1 commit into from
Sep 22, 2018
Merged

Conversation

tiborvass
Copy link
Contributor

@tiborvass tiborvass commented Sep 14, 2018

This allows users to configure the buildkit GC.

The following enables the default GC:

{
  "builder": {
    "gc": {
      "enabled": true
    }
  }
}

The default GC policy has a simple config:

{
  "builder": {
    "gc": {
      "enabled": true,
      "defaultKeepStorage": "30GB"
    }
  }
}

A custom GC policy can be used instead by specifying a list of cache prune rules:

{
  "builder": {
    "gc": {
      "enabled": true,
      "policy": [
        {"keepStorage": "512MB", "filter": ["unused-for=1400h"]},
        {"keepStorage": "30GB", "all": true}
      ]
    }
  }
}

Signed-off-by: Tibor Vass tibor@docker.com

wopt := mobyworker.Opt{
ID: "moby",
Root: root,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: remove this, not needed.

@codecov
Copy link

codecov bot commented Sep 14, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@b111647). Click here to learn what that means.
The diff coverage is 0%.

@@            Coverage Diff            @@
##             master   #37846   +/-   ##
=========================================
  Coverage          ?   36.09%           
=========================================
  Files             ?      610           
  Lines             ?    45115           
  Branches          ?        0           
=========================================
  Hits              ?    16284           
  Misses            ?    26591           
  Partials          ?     2240

if conf.GC.DefaultKeepStorage != "" {
defaultKeepStorage, err = units.RAMInBytes(conf.GC.DefaultKeepStorage)
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wrap these parse errors

Copy link
Member

@andrewhsu andrewhsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@fntlnz fntlnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this, just a few comments but in general looks very good 👼

err error
)

if conf.GC.DefaultKeepStorage != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this only be done only if conf.GC.Enabled is true?

}
}
} else {
gcPolicy = mobyworker.DefaultGCPolicy(root, defaultKeepStorage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not initializing gcPolicy to this directly instead of having an else statement? then if the user wants to set it the make at 194 can override it

Copy link
Contributor Author

@tiborvass tiborvass Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fntlnz It's a small matter of preference: with what you're suggesting, in the case where user wants to set it, it would have already called DefaultGCPolicy unnecessarily. The way it is now, only one of the two codepaths is executed once. If readability is what concerns you, I could change it to if conf.GC.Policy == nil { first.

@tiborvass
Copy link
Contributor Author

@fntlnz updated

@fntlnz
Copy link
Member

fntlnz commented Sep 20, 2018

LGTM

if err := syscall.Statfs(root, &st); err != nil {
return defaultCap
}
diskSize := st.Bsize * int64(st.Blocks)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is complaining that on s390x (z linux) Bsize is int32.

https://github.com/golang/go/blob/master/src/syscall/ztypes_linux_s390x.go#L119

07:19:55 builder/builder-next/worker/gc_unix.go:14:23: invalid operation: st.Bsize * int64(st.Blocks) (mismatched types uint32 and int64)

I think we need an int32 version of this too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows users to configure the buildkit GC.

The following enables the default GC:
```
{
  "builder": {
    "gc": {
      "enabled": true
    }
  }
}
```

The default GC policy has a simple config:
```
{
  "builder": {
    "gc": {
      "enabled": true,
      "defaultKeepStorage": "30GB"
    }
  }
}
```

A custom GC policy can be used instead by specifying a list of cache prune rules:
```
{
  "builder": {
    "gc": {
      "enabled": true,
      "policy": [
        {"keepStorage": "512MB", "filter": ["unused-for=1400h"]]},
        {"keepStorage": "30GB", "all": true}
      ]
    }
  }
}
```

Signed-off-by: Tibor Vass <tibor@docker.com>
@yongtang
Copy link
Member

All tests passed so merging.

@Zeks
Copy link

Zeks commented Dec 25, 2019

Can you tell me exactly which config file I need to edit to set the options from the original post?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants