summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2026-01-14 20:59:14 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2026-01-21 18:00:26 -0500
commit4d8fc28985dbd69ca5b0b2cfe3e977d74fe5b3dd (patch)
tree6da2330220ef822bb59231ee01e5d87763cf85c6 /docs
parent24c604854c6ffe79ac7973e333b2df7f7f82ddd9 (diff)
downloadmeta-virtualization-4d8fc28985dbd69ca5b0b2cfe3e977d74fe5b3dd.tar.gz
image-oci: add layer caching for multi-layer OCI builds
Add layer caching to speed up multi-layer OCI image rebuilds. When enabled, pre-installed package layers are cached to disk and restored on subsequent builds, avoiding repeated package installation. New variables: - OCI_LAYER_CACHE: Enable/disable caching (default "1") - OCI_LAYER_CACHE_DIR: Cache location (default ${TOPDIR}/oci-layer-cache/${MACHINE}) Cache key is computed from: - Layer name and type - Sorted package list - Package versions from PKGDATA_DIR - MACHINE and TUNE_PKGARCH Cache automatically invalidates when: - Package versions change - Layer definition changes - Architecture changes Benefits: - First build: ~10-30s per layer (cache miss, packages installed) - Subsequent builds: ~1s per layer (cache hit, files copied) - Shared across recipes with identical layer definitions Build log shows cache status: NOTE: OCI Cache HIT: Layer 'base' (be88c180f651416b) NOTE: OCI: Pre-installed packages for 3 layers (cache: 3 hits, 0 misses) Also adds comprehensive pytest suite for multi-layer OCI functionality including tests for 1/2/3 layer modes and cache behavior. Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/container-bundling.md64
1 files changed, 64 insertions, 0 deletions
diff --git a/docs/container-bundling.md b/docs/container-bundling.md
index a695a5b8..745622b5 100644
--- a/docs/container-bundling.md
+++ b/docs/container-bundling.md
@@ -193,6 +193,70 @@ OCI_LAYERS = "\
193" 193"
194``` 194```
195 195
196### Layer Caching
197
198Multi-layer builds cache pre-installed package layers for faster rebuilds.
199Installing packages requires configuring the package manager, resolving
200dependencies, and running post-install scripts - this is slow. Caching
201saves the fully-installed layer rootfs after the first build so subsequent
202builds can skip package installation entirely.
203
204#### Configuration
205
206 # Enabled by default
207 OCI_LAYER_CACHE ?= "1"
208 OCI_LAYER_CACHE_DIR ?= "${TOPDIR}/oci-layer-cache/${MACHINE}"
209
210#### Cache Key Components
211
212The cache key is a SHA256 hash of:
213
214| Component | Why It Matters |
215|-----------|----------------|
216| Layer name | Different layers cached separately |
217| Layer type | `packages` vs `directories` vs `files` |
218| Package list (sorted) | Adding/removing packages invalidates cache |
219| Package versions | Upgrading a package invalidates cache |
220| MACHINE, TUNE_PKGARCH | Architecture-specific packages |
221
222#### Advantages
223
224**Faster rebuilds**: Subsequent builds restore cached layers in ~1 second
225instead of ~10-30 seconds per layer for package installation.
226
227**Efficient development**: When only your app layer changes, base and
228dependency layers are restored from cache:
229
230 OCI_LAYERS = "\
231 base:packages:base-files+busybox \ # Cached - stable
232 deps:packages:python3+python3-pip \ # Cached - stable
233 app:packages:myapp \ # Rebuilt - changes often
234 "
235
236**Automatic invalidation**: Cache invalidates when packages change version,
237layers are modified, or architecture changes. No manual clearing needed.
238
239**Shared across recipes**: Cache stored in `${TOPDIR}/oci-layer-cache/` so
240recipes with identical layers share the same cached content.
241
242#### Build Log Example
243
244 # First build - cache misses
245 NOTE: OCI Cache MISS: Layer 'base' (base:base-files=3.0.14 ...)
246 NOTE: OCI Cache: Saving layer 'base' to cache (be88c180f651416b)
247 NOTE: OCI: Pre-installed packages for 3 layers (cache: 0 hits, 3 misses)
248
249 # Second build - cache hits
250 NOTE: OCI Cache HIT: Layer 'base' (be88c180f651416b)
251 NOTE: OCI: Pre-installed packages for 3 layers (cache: 3 hits, 0 misses)
252
253#### When to Disable
254
255Disable caching with `OCI_LAYER_CACHE = "0"` if you:
256- Suspect cache corruption
257- Need fully reproducible builds with no local state
258- Are debugging package installation issues
259
196### OCI_IMAGE_CMD vs OCI_IMAGE_ENTRYPOINT 260### OCI_IMAGE_CMD vs OCI_IMAGE_ENTRYPOINT
197 261
198 # CMD (default) - replaced when user passes arguments 262 # CMD (default) - replaced when user passes arguments