diff --git a/README.md b/README.md index 004f970..d568032 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cache-images.sh b/cache-images.sh new file mode 100755 index 0000000..14bda73 --- /dev/null +++ b/cache-images.sh @@ -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 + diff --git a/cached-registries.yaml b/cached-registries.yaml new file mode 100644 index 0000000..d684f36 --- /dev/null +++ b/cached-registries.yaml @@ -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: {} \ No newline at end of file diff --git a/kyma-k3d.sh b/kyma-k3d.sh index 3d853b1..e038c81 100755 --- a/kyma-k3d.sh +++ b/kyma-k3d.sh @@ -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() { @@ -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