Skip to content

Commit

Permalink
docs: explain how to cache the base image (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarbs authored Jan 3, 2024
1 parent 1e7569c commit abe37c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ Each layer is stored in the registry as a separate image. The image tag is the h

The performance improvement of builds depends on the complexity of your Dockerfile. For [`coder/coder`](https://github.com/coder/coder/blob/main/.devcontainer/Dockerfile), uncached builds take 36m while cached builds take 40s (~98% improvement).

## Image Caching

When the base container is large, it can take a long time to pull the image from the registry. You can pre-pull the image into a read-only volume and mount it into the container to speed up builds.

```bash
# Pull your base image from the registry to a local directory.
docker run --rm \
-v /tmp/kaniko-cache:/cache \
gcr.io/kaniko-project/warmer:latest \
--cache-dir=/cache \
--image=<your-image>

# Run envbuilder with the local image cache.
docker run -it --rm \
-v /tmp/kaniko-cache:/image-cache:ro \
-e BASE_IMAGE_CACHE_DIR=/image-cache
```

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

## Setup Script

The `SETUP_SCRIPT` environment variable dynamically configures the user and init command (PID 1) after the container build process.
Expand Down
2 changes: 1 addition & 1 deletion envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type Options struct {
// BaseImageCacheDir is the path to a directory where the base
// image can be found. This should be a read-only directory
// solely mounted for the purpose of caching the base image.
BaseImageCacheDir string `env:"BASE_IMAGECACHE_DIR"`
BaseImageCacheDir string `env:"BASE_IMAGE_CACHE_DIR"`

// LayerCacheDir is the path to a directory where built layers
// will be stored. This spawns an in-memory registry to serve
Expand Down

0 comments on commit abe37c8

Please sign in to comment.