You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(cache): document cache persistence behavior per runner
Add a "Cache Persistence by Runner" section explaining that cache write
behavior differs by runner: Docker and Bubblewrap use read-write bind
mounts (writes persist), while QEMU uses read-only 9p with overlay by
default (writes discarded). Update virtiofs section to clarify it enables
cache persistence for QEMU.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/BUILD-CACHE.md
+62-4Lines changed: 62 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,9 @@ As each build often requires all the same packages, it can be very inefficient t
11
11
12
12
## How to use it
13
13
14
-
When you run `melange build`, you can specify a cache directory with the `--cache-dir` flag. The value you provide here should be a path to a directory on your local filesystem. This local directory will be mounted into the build workspace (e.g. a running container) at the path `/var/cache/melange` as a read/write volume.
14
+
When you run `melange build`, you can specify a cache directory with the `--cache-dir` flag. The value you provide here should be a path to a directory on your local filesystem. This local directory will be mounted into the build workspace (e.g. a running container) at the path `/var/cache/melange`.
15
15
16
-
This enables you to speed up builds by preloading data into the cache before you run `melange build`. You can additionally use this mounted directory to persist cache data generated by the build itself, taking advantage of the cache in subsequent builds.
16
+
This enables you to speed up builds by preloading data into the cache before you run `melange build`. Depending on the runner you use, you may also be able to persist cache data generated by the build itself for use in subsequent builds (see [Cache Persistence by Runner](#cache-persistence-by-runner) below).
17
17
18
18
### Example: Go Modules
19
19
@@ -45,7 +45,7 @@ pipeline:
45
45
46
46
Now you're all set! If you've already downloaded the Go modules you need for your Go project to your local filesystem, you'll no longer need to wait for Melange to download those Go modules during every build. This can significantly speed up builds!
47
47
48
-
Keep in mind that because the build cache is a read/write-able mount, modifications to data in this directory during a Melange build **will affect** your local filesystem.
48
+
**Note:** Whether modifications to the cache during a build persist to your local filesystem depends on which runner you use. See [Cache Persistence by Runner](#cache-persistence-by-runner) for details.
49
49
50
50
### Example: Python UV
51
51
@@ -123,4 +123,62 @@ pipeline:
123
123
pip install -r requirements.txt
124
124
```
125
125
126
-
This caching support helps significantly speed up Python builds by avoiding repeated downloads of packages across builds.
126
+
This caching support helps significantly speed up Python builds by avoiding repeated downloads of packages across builds.
127
+
128
+
### Example: Maven Dependencies
129
+
130
+
Maven caching is automatically enabled when using the `maven/configure-mirror` or `maven/pombump` pipelines. When a cache directory is mounted at `/var/cache/melange`, the pipelines automatically configure Maven to use `/var/cache/melange/m2repository` as the local repository.
131
+
132
+
To use Maven caching, simply provide a cache directory:
133
+
134
+
```shell
135
+
melange build --cache-dir /path/to/my/cache ...
136
+
```
137
+
138
+
No additional configuration is required in your Melange config. The Maven pipelines detect the mounted cache directory and configure the local repository path automatically. This is useful for Java projects with many dependencies (e.g., apicurio-registry requires over 1 GB of dependencies).
139
+
140
+
On subsequent builds, Maven will reuse the downloaded dependencies from the cache, avoiding redundant downloads.
141
+
142
+
## Cache Persistence by Runner
143
+
144
+
The cache directory mount behavior varies depending on which runner you use:
Both Docker and Bubblewrap mount the cache directory as a standard read-write bind mount. Any modifications made to `/var/cache/melange` during the build **will directly affect** your local filesystem. This allows builds to populate the cache for use in subsequent builds.
156
+
157
+
### QEMU (default, without virtiofs)
158
+
159
+
By default, QEMU mounts the cache directory using the 9p protocol with a read-only flag. To allow builds to write to the cache, an overlay filesystem is layered on top:
160
+
161
+
- **Lower layer:** Read-only 9p mount of your host cache directory
162
+
- **Upper layer:** Temporary writable directory inside the guest
163
+
164
+
This means builds can read from your pre-populated cache, but any writes during the build go to the overlay's upper directory and **are discarded** when the build completes. To persist cache writes with QEMU, enable virtiofs (see below).
165
+
166
+
## QEMU Runner: virtiofs for Cache Directory
167
+
168
+
When using the QEMU runner, the default 9p mount does not persist cache writes to the host. To enable cache persistence (and improve I/O performance), you can use virtiofs instead.
169
+
170
+
To enable virtiofs for the cache directory, set the `QEMU_USE_VIRTIOFS` environment variable:
- The `virtiofsd` binary must be available on the host system (checked at `/usr/libexec/virtiofsd`, `/usr/lib/qemu/virtiofsd`, or in `$PATH`). Alternatively, set `QEMU_VIRTIOFS_PATH` to a directory containing the `virtiofsd` binary (useful for macOS/brew or non-standard installations).
178
+
- The host system must support virtiofs (Linux with appropriate kernel support)
179
+
180
+
When virtiofs is enabled, the cache directory is mounted as a read-write virtiofs share, providing:
181
+
- **Cache persistence:** Writes during the build are saved to your host filesystem
If `QEMU_USE_VIRTIOFS=1` is set but `virtiofsd` is not found, melange will return an error. If the environment variable is not set or set to `0`, the default 9p+overlay mount is used and cache writes are not persisted.
0 commit comments