Cache
Cache in Buddy
Working speed is essential to any CI/CD tool. Buddy improves pipeline performance by caching resources that would otherwise have to be generated or downloaded on every run:
- Repository files, dependencies and artifacts (cached within the pipeline filesystem)
- Docker images in which build actions are run (no need to build the environment from scratch every time)
- Docker images used in the Run Image action
- Docker layers built with the Build Image action
You can also enable cache for services and databases attached to build actions or an extra cache per individual build action.
Pipeline filesystem cache
Each pipeline has its own filesystem. On the first pipeline run, the repository is cloned to the filesystem. Subsequent executions only fetch changes from the repository (git fetch
).
The pipeline filesystem is available for every action executed in the pipeline:
- Build actions are run in a Docker container to which the filesystem is mounted. By default, all build commands are executed in the context of the filesystem.
- Deployment actions are also run in the context of the filesystem, enabling you to deploy artifacts built in previous actions.
Cache in build actions
Repository, dependencies, and artifacts
Builds, tests, and other commands defined in the build action are executed in the context of the filesystem containing the repository. This is the primary cache of the pipeline.
If you fetch dependencies to a different directory than the default build context, you can cache them by entering their paths in the Cache tab: Cache tab in Node action
Build environment cache
Build actions are run in Docker containers. The build environment is based on the Docker image pulled from the selected registry (default: Docker Hub). On the first pipeline run, Buddy pulls and caches the image in the selected version. If you set image the tag to 'Latest' in the environment tab, it checks for a new version by running docker pull
on every subsequent execution. The procedure only downloads Docker layers missing in the previous execution.
This way you don't have to pull the full image every time, and you're always sure that you're using the most recent version. The same rule applies to other actions that pull Docker images from the registry.
Environment customization
Docker images can be customized with commands in the Packages & Tools tab of the build action. The commands are run on the first pipeline execution to create a new image. The image is used until a new one is pulled from the registry or until modified with new commands.
Databases and services
All build actions support microservices (MySQL, MongoDB, Redis, etc.). The services act like individual containers with separate caching systems.
Docker
All layers created in Docker-building actions are cached. During subsequent builds, Buddy adds only the layers that have not been built in the previous step. Cached images can be used by other actions in the pipeline, including builds and Docker Push/Docker Run actions.
Clearing cache
Sometimes you may want to clear the cache – for example, if you need to regenerate the artifacts. In such case, you can either clear the cache manually, or select an option which will do that automatically before every execution. The operation is performed per pipeline – it is not possible to clear caches of the entire workspace at once.
Checking consumed space
You can check the volume of consumed space for each project and pipeline in the workspace billing settings by switching to the Usage tab, or directly at https://app.buddy.works/YOUR_WORKSPACE/payments/usage
:
Cache usage in workspace billing
Manual purge
You can clear the pipeline cache in a few different ways:
- By clicking the Clear cache option from the pipeline's dropdown menu:
Clear cache in pipeline options
By checking the flag 'Clear cache before running' when running the pipeline manually.
By using
/[name] clear run
slash command when running the pipeline from Slack.By using the
--clear-cache
parameter when running the pipeline with a commit command.
Automatic purge
To automatically purge the cache on every pipeline run, check the flag 'Erase filesystem, Docker layers & cached container paths on run' in the pipeline's settings.
Clear Cache action
Another method is using the Clear Cache action in the pipeline. Here you can specify what exactly should be purged:
- Cached Docker layers
- Pipeline filesystem (cached dependencies, repository files)
- Cache of attached services
- Additional cache in build actions used to store files outside pipeline filesystem.
You can add the action to any place in the pipeline and also define when the action should run using the trigger conditions. For instance, you can choose to purge the cache only on changes to the package-lock.json
file, which is useful when you want to rebuild the application from scratch and ensure that all dependencies are included:
Clear cache action in pipeline
Last modified on October 11, 2023