Skip to content

Commit ea695d0

Browse files
authored
docs: add example kaniko cache warmer script (#123)
1 parent c1b4a9e commit ea695d0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ docker run -it --rm \
188188

189189
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).
190190

191+
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.
192+
191193
## Setup Script
192194

193195
The `SETUP_SCRIPT` environment variable dynamically configures the user and init command (PID 1) after the container build process.

examples/kaniko-cache-warmer.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# This is an example script to pull a number of images into the Kaniko cache
4+
# to have them ready for consumption by envbuilder.
5+
# Ref: https://github.com/coder/envbuilder/blob/main/README.md#image-caching
6+
KANIKO_CACHE_VOLUME=${KANIKO_CACHE_VOLUME:-"kanikocache"}
7+
IMAGES=(
8+
alpine:latest
9+
debian:latest
10+
ubuntu:latest
11+
)
12+
13+
set -euo pipefail
14+
15+
if ! docker volume inspect "${KANIKO_CACHE_VOLUME}" > /dev/null 2>&1; then
16+
echo "Kaniko cache volume does not exist; creating it."
17+
docker volume create "${KANIKO_CACHE_VOLUME}"
18+
fi
19+
20+
for img in "${IMAGES[@]}"; do
21+
echo "Fetching image ${img} to kaniko cache ${KANIKO_CACHE_VOLUME}"
22+
docker run --rm \
23+
-v "${KANIKO_CACHE_VOLUME}:/cache" \
24+
gcr.io/kaniko-project/warmer:latest \
25+
--cache-dir=/cache \
26+
--image="${img}"
27+
done

0 commit comments

Comments
 (0)