Skip to content

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

Merged
merged 4 commits into from
Mar 7, 2025
Merged

Tweak fast build cache and file exposure #2188

merged 4 commits into from
Mar 7, 2025

Conversation

nevillelyh
Copy link
Contributor

  • 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"))
Copy link
Contributor Author

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"
Copy link
Contributor Author

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"
Copy link
Contributor Author

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.

@nevillelyh nevillelyh requested review from 8W9aG and NikhilSinha1 March 7, 2025 20:13
@nevillelyh nevillelyh merged commit a27eb98 into main Mar 7, 2025
21 checks passed
@nevillelyh nevillelyh deleted the neville/fast branch March 7, 2025 20:54
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.

2 participants