-
Notifications
You must be signed in to change notification settings - Fork 626
Tweak fast build cache and file exposure #2188
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
Conversation
nevillelyh
commented
Mar 7, 2025
- Clean up build cache
- Only overwrite env.txt if different
- Bind mount . => /src during monobase.user build
* Replace broken global .cog_cache with id=monobase-cache * APT cache is not needed now that we build APT tarball with docker run * Rename tmpMount variable name
* So that Python wheel or zip files in requirements.txt are exposed to uv pip install
@@ -227,12 +228,12 @@ func (g *FastGenerator) generateMonobase(lines []string, tmpDir string) ([]strin | |||
|
|||
// The only input to monobase.build are these ENV vars | |||
// Write them in tmp mount for layer caching | |||
err := os.WriteFile(path.Join(tmpDir, "env.txt"), []byte(strings.Join(envs, "\n")), 0o644) | |||
err := files.WriteIfDifferent(path.Join(tmpDir, "env.txt"), strings.Join(envs, "\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overwriting files with same content changes its timestamp and invalidates layer cache. So only write if content changed.
@@ -16,10 +17,10 @@ import ( | |||
) | |||
|
|||
const FUSE_RPC_WEIGHTS_PATH = "/srv/r8/fuse-rpc/weights/sha256" | |||
const MONOBASE_CACHE_PATH = "/var/cache/monobase" | |||
const APT_CACHE_MOUNT = "--mount=type=cache,target=/var/cache/apt,id=apt-cache,sharing=locked" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not caching /var/cache/apt
for the APT tarball building stage. But those are usually small and rarely change. We can add cache later if it becomes problematic.
@@ -288,10 +288,12 @@ func (g *FastGenerator) installPython(lines []string, tmpDir string) ([]string, | |||
return nil, err | |||
} | |||
if requirementsFile != "" { | |||
srcMount := "--mount=type=bind,ro,source=.,target=/src" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python wheel/zip files in requirements.txt
cannot be in .dockerignore
or they'll not be exposed via this bind mount. OTOH they'll be baked into the /src
layer unless we parse requirements, check existence and add them to --exclude
in the COPY
step, overkill for now assuming most private packages are small.