Caching
Railpack uses both BuildKit layer and mount caches to speed up successive builds.
Layer Cache
Section titled “Layer Cache”Railpack uses BuildKit’s layer cache and avoids busting the cache when possible. Cache busting events are defined in a granular way as part of the steps commands list. These include:
- Copying files from the local context to the build context
- Changing environment variables
- Adding new generated files to the build context
- Executing shell commands in the build context
Cache Backends
Section titled “Cache Backends”Railpack supports all BuildKit cache backends.
railpack buildsupports the same CLI arguments asdocker buildxfor cache import/export. See the CLI reference for more information.- Cache import/export references are supported when using the Railpack frontend directly with
docker buildxorbuildctl. See the frontend reference for more information.
Mount Cache
Section titled “Mount Cache”The BuildKit mount cache is used to save the contents of a directory from the build context between builds. This is useful for speeding up commands that download or compile assets (e.g. npm install). The directory does not appear in the final image.
Caches are defined in the build plan and referenced by steps that need them. Each cache has a type and a directory:
Cache Types
Section titled “Cache Types”shared: Multiple builds can use this cache simultaneously (used for package manager caches)locked: Only one build can use this cache at a time (used for apt caches to prevent concurrent package installations)
Caches are shared across all steps that reference them. This is useful for common caches such as the apt-cache or apt-lists.