Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ docker run -it --rm \

In Kubernetes, you can pre-populate a persistent volume with the same warmer image, then mount it into many workspaces with the [`ReadOnlyMany` access mode](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes).

A sample script to pre-fetch a number of images can be viewed [here](./examples/kaniko-cache-warmer.sh). This can be run, for example, as a cron job to periodically fetch the latest versions of a number of base images.

## Setup Script

The `SETUP_SCRIPT` environment variable dynamically configures the user and init command (PID 1) after the container build process.
Expand Down
27 changes: 27 additions & 0 deletions examples/kaniko-cache-warmer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# This is an example script to pull a number of images into the Kaniko cache
# to have them ready for consumption by envbuilder.
# Ref: https://github.com/coder/envbuilder/blob/main/README.md#image-caching
KANIKO_CACHE_VOLUME=${KANIKO_CACHE_VOLUME:-"kanikocache"}
IMAGES=(
alpine:latest
debian:latest
ubuntu:latest
)

set -euo pipefail

if ! docker volume inspect "${KANIKO_CACHE_VOLUME}" > /dev/null 2>&1; then
echo "Kaniko cache volume does not exist; creating it."
docker volume create "${KANIKO_CACHE_VOLUME}"
fi

for img in "${IMAGES[@]}"; do
echo "Fetching image ${img} to kaniko cache ${KANIKO_CACHE_VOLUME}"
docker run --rm \
-v "${KANIKO_CACHE_VOLUME}:/cache" \
gcr.io/kaniko-project/warmer:latest \
--cache-dir=/cache \
--image="${img}"
done