Open nicks opened 4 years ago
Currently, docker_build has a cache_from parameter, which should make it easier to play around with solutions in a Tiltfile (though ultimately I'd want something that auto-configured a bit better without you having to know it exists)
(you'd also have to set up tilt to set build_args={'BUILDKIT_INLINE_CACHE': '1'} and push the image to a remote repo)
Akshat Khandelwal in the Tilt channel pointed out this approach, which i thought was neat:
We have a bunch of docker_build calls like below -
docker_build(
'my-image',
'.',
dockerfile='./service/Dockerfile',
build_args = {'BUILDKIT_INLINE_CACHE': '1'},
cache_from = ['my-image:<HEAD commit id>', 'my-image:<HEAD~1>', 'my-image:master commit id', 'my-image:master~1'],
extra_tag = 'my-image:<HEAD commit id>'
)
Where currently, the values of HEAD commit id, master commit id etc. are calculated at the start of every Tilt run. The idea is to use external cache sources, and use multiple 'commit id' tags to increase chances of getting cache hits.
i'm not 100% confident on the semantics of cache_from and how it pulls the cache from the remote registry, though i wonder if tilt could do something intelligent here about selecting caches
@nicks Akshat is working with us :)
He/we will have some updates on our caching progress; we've basically got it working well but have had to do some tricks with making the tilt build context clean from local files that aren't meant to be in the docker images but can't easily be docker/git ignored. FWIW, this saves us an insane amount of build time for all our developers and in CI.
In the #tilt channel, Adam writes:
There are a couple different possible recommendations on this. Some teams we work with have fairly complex Tiltfiles that try to simulate version of this (e.g., "pass this environment variable to get the pre-built version of service X, Y, and Z")
Docker build has a --cache-from parameter https://docs.docker.com/engine/reference/commandline/build/#specifying-external-cache-sources
but it takes some wiring to get this to work well with tilt (both to use the cache and to populate the cache)
This is a pretty common thing to want to do, but we should research how to do it and provide recommendations