Skip to content
This repository was archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
Add caching container images
Browse files Browse the repository at this point in the history
  • Loading branch information
pbochynski committed Jul 29, 2020
1 parent 4246e33 commit c0c7967
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,39 @@ Your cluster is ready!
# Clean up

```
k3d cluster delete kyma
docker rm -f k3d-registry
./kyma-k3d-delete.sh
```

# Cache docker registry localy

Install [crane](https://github.com/google/go-containerregistry/tree/master/cmd/crane) tool with:
```
GO111MODULE=on go get -u github.com/google/go-containerregistry/cmd/crane
```

Start Kyma cluster (`kyma-k3d.sh`) and when it is up and running execute this command:
```
./cache-images.sh
```

Delete the cluster:
```
./kyma-k3d-delete.sh
```

Start it again with using [cached-registries](cached-registries.yaml):
```
./kyma-k3d.sh cached-registries.yaml
```

This time all the images from docker.io, eu.gcr.io, gcr.io and quay.io will be fetched from your local registry.

Be aware that if you download newer Kyma charts some new images can be used that are not stored in the cache. In this case installation can fail and you will see some pods in status `ImagePullBackOff`. To fix the problem can just copy missing image using crane:
```
crane cp some.docker.registry/path/image:tag registry.localhost:5000/path/image:tag
```
If there is more such images you can just start the caching procedure again.

# FAQ


Expand Down
13 changes: 13 additions & 0 deletions cache-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function cacheImage () {
regex="^(eu\.gcr\.io/|gcr\.io/|docker\.io/|quay\.io/)(.*)"
if [[ $1 =~ $regex ]]
then
registry=${BASH_REMATCH[1]//[$'\t\r\n']}
image=${BASH_REMATCH[2]//[$'\t\r\n']}
crane cp ${registry}${image} registry.localhost:5000/${image}
fi
}

docker exec -it k3d-kyma-server-0 sh -c "ctr images ls -q" >images.txt
cat images.txt | while read -r line; do cacheImage "$line"; done

15 changes: 15 additions & 0 deletions cached-registries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
mirrors:
registry.localhost:5000:
endpoint:
- http://registry.localhost:5000
docker.io:
endpoint:
- http://registry.localhost:5000
gcr.io:
endpoint:
- http://registry.localhost:5000
eu.gcr.io:
endpoint:
- http://registry.localhost:5000
configs: {}
auths: {}
5 changes: 3 additions & 2 deletions kyma-k3d.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SECONDS=0
SECONDS=0
REGISTRY_CONFIG=${1:-registries.yaml}

# Wait until number of background jobs is less than $1, try every $2 second(s)
function waitForJobs() {
Expand All @@ -24,7 +25,7 @@ k3d cluster create kyma \
--k3s-server-arg --no-deploy \
--k3s-server-arg traefik \
--network k3d-kyma \
--volume $PWD/registries.yaml:/etc/rancher/k3s/registries.yaml \
--volume $PWD/${REGISTRY_CONFIG}:/etc/rancher/k3s/registries.yaml \
--wait \
--switch-context \
--timeout 60s
Expand Down

0 comments on commit c0c7967

Please sign in to comment.