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

cache backend for github actions #1974

Merged
merged 3 commits into from Jul 11, 2021

Conversation

tonistiigi
Copy link
Member

closes #1947

WIP version for early testing. type=gha, optional scope can be specified to namespace the cache.

TODO:

  • only tested some basic cases.
  • exporting always overwrites cache for the current writable scope. The actual version should merge all caches together and periodically clean up the branches that point to layers that github has pruned.

@crazy-max
Copy link
Member

Many thanks for this feature @tonistiigi

I don't see it but I assume cache exporter already prune/gc remote blobs?

@tonistiigi
Copy link
Member Author

I don't see it but I assume cache exporter already prune/gc remote blobs?

There is no API to remove cache blobs in Github afaics. I think Github just deletes objects whenever usage goes over the cap. I'm not sure of the exact order of how blobs are deleted (see #1947 (comment)) . Exporting will push a new manifest and currently, if it doesn't refer to the old blob anymore it will remain dangling until github cleans it up. I hope to change that so that there are periodical checks to determine what objects still exists and the old cache that still points to existing objects is merged with the new one.

@chrispat
Copy link

@tonistiigi in regards to

I think Github just deletes objects whenever usage goes over the cap. I'm not sure of the exact order of how blobs are deleted (see #1947 (comment))

We delete the blobs in order of least recently accessed as they go over the cap and any blob that has not been access in 7 days will be deleted. We should have an API in the near future to delete cache blobs as well.

@tonistiigi tonistiigi added this to the v0.9.0 milestone Jun 11, 2021
@tonistiigi tonistiigi marked this pull request as ready for review June 11, 2021 15:35
)

func init() {
actionscache.Log = log.Printf
Copy link
Member

Choose a reason for hiding this comment

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

nit: why not logrus

if ce == nil {
return nil, errors.Errorf("blob not found")
}
rac := ce.Download(context.TODO())
Copy link
Member

Choose a reason for hiding this comment

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

Can't we pass the ctx here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This context is long-running. Canceling it (allowed after this function returns) would cancel the ReaderAt that it returns. It should use the tracing context though, or the library should take a HTTP client so that tracing transport can be used.

@AkihiroSuda
Copy link
Member

needs rebase

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

Tested on my side and LGTM:

  time="2021-07-06T22:44:49Z" level=debug msg="load cache https://artifactcache.actions.githubusercontent.com/iC2459jfgdOW9d7EC3lNVmpsYRV1wmgoJboSD3iyUzxb76QZip/_apis/artifactcache/cache?keys=buildkit-blob-1-sha256%3A5843afab387455b37944e709ee8c78d7520df80f8d01cf7f861aae63beeddb6b&version=693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2"
  time="2021-07-06T22:44:49Z" level=debug msg="load cache https://artifactcache.actions.githubusercontent.com/iC2459jfgdOW9d7EC3lNVmpsYRV1wmgoJboSD3iyUzxb76QZip/_apis/artifactcache/cache?keys=buildkit-blob-1-sha256%3Adc728e95acca44552fe2f7a2fba71b75c7b2a9a5572c42f2c6291edb4a11fb37&version=693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2"
  time="2021-07-06T22:44:49Z" level=debug msg="load cache https://artifactcache.actions.githubusercontent.com/iC2459jfgdOW9d7EC3lNVmpsYRV1wmgoJboSD3iyUzxb76QZip/_apis/artifactcache/cache?keys=buildkit-blob-1-sha256%3Af03631b5b56f414fd215d7b32bd09d35631f9e851c5809f8cf07edfb8e3aae44&version=693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2"
  time="2021-07-06T22:44:49Z" level=debug msg="load cache https://artifactcache.actions.githubusercontent.com/iC2459jfgdOW9d7EC3lNVmpsYRV1wmgoJboSD3iyUzxb76QZip/_apis/artifactcache/cache?keys=index-buildkit-1-49c8f7d5%23&version=693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2"
  time="2021-07-06T22:44:49Z" level=debug msg="load cache https://artifactcache.actions.githubusercontent.com/iC2459jfgdOW9d7EC3lNVmpsYRV1wmgoJboSD3iyUzxb76QZip/_apis/artifactcache/cache?keys=index-buildkit-1-49c8f7d5%23&version=693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2"
  time="2021-07-06T22:44:49Z" level=debug msg="save cache req https://artifactcache.actions.githubusercontent.com/iC2459jfgdOW9d7EC3lNVmpsYRV1wmgoJboSD3iyUzxb76QZip/_apis/artifactcache/caches body={\"key\":\"index-buildkit-1-49c8f7d5#6\",\"version\":\"693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2\"}"
  time="2021-07-06T22:44:49Z" level=debug msg="save cache resp: {\"cacheId\":65}"
  time="2021-07-06T22:44:49Z" level=debug msg="upload cache chunk https://artifactcache.actions.githubusercontent.com/iC2459jfgdOW9d7EC3lNVmpsYRV1wmgoJboSD3iyUzxb76QZip/_apis/artifactcache/caches/65, range 0-3049"
  time="2021-07-06T22:44:49Z" level=debug msg="commit cache https://artifactcache.actions.githubusercontent.com/iC2459jfgdOW9d7EC3lNVmpsYRV1wmgoJboSD3iyUzxb76QZip/_apis/artifactcache/caches/65, size 3050"
  time="2021-07-06T22:44:49Z" level=debug msg="session finished: <nil>"

@crazy-max
Copy link
Member

Would need to update the README with a new section about this cache exporter.

@tonistiigi
Copy link
Member Author

🤦 I forgot to merge this for v0.9-rc1. Writing changelog and wondered why my tool didn't detect this.

The plan was to merge this even though it is not fully complete to ease testing and gathering feedback. I guess this means rc2.

@crazy-max
Copy link
Member

crazy-max commented Jul 8, 2021

@tonistiigi That's fine. It will be ok in rc2. In the meantime can you rebase and merge the PR to be able to test from public repos? I already have a workflow ready.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@crazy-max crazy-max merged commit 0304821 into moby:master Jul 11, 2021
@mlissner
Copy link

crazy-max merged commit 0304821 into moby:master yesterday

Woo hoo!

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

Successfully merging this pull request may close these issues.

cache backend for GitHub Actions
5 participants