zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/examples/kind/kind-ci.sh (about) 1 #!/bin/sh 2 set -o errexit 3 4 # Reference: https://kind.sigs.k8s.io/docs/user/local-registry/ 5 6 # set no_proxy if applicable 7 if [ ! -z "${no_proxy}" ]; then 8 echo "Updating no_proxy env var"; 9 export no_proxy=${no_proxy},kind-registry; 10 export NO_PROXY=${no_proxy}; 11 fi 12 13 # create registry container unless it already exists 14 reg_name='kind-registry' 15 reg_port='5001' 16 if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then 17 docker run \ 18 -d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \ 19 ghcr.io/project-zot/zot-minimal-linux-amd64:latest 20 fi 21 22 CLUSTER_NAME=kind 23 ## Delete the cluster if it already exist 24 kind get clusters | grep ${CLUSTER_NAME} && kind delete cluster --name ${CLUSTER_NAME} 25 26 # create a cluster with the local registry enabled in containerd 27 cat <<EOF | kind create cluster --config=- 28 kind: Cluster 29 apiVersion: kind.x-k8s.io/v1alpha4 30 containerdConfigPatches: 31 - |- 32 [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"] 33 endpoint = ["http://${reg_name}:5000"] 34 EOF 35 36 # connect the registry to the cluster network if not already connected 37 if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then 38 docker network connect "kind" "${reg_name}" 39 fi 40 41 # https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry 42 # 43 # document the local registry 44 cat <<EOF | kubectl apply -f - 45 apiVersion: v1 46 kind: ConfigMap 47 metadata: 48 name: local-registry-hosting 49 namespace: kube-public 50 data: 51 localRegistryHosting.v1: | 52 host: "localhost:${reg_port}" 53 help: "https://kind.sigs.k8s.io/docs/user/local-registry/" 54 EOF 55 56 ## Deploy prometheus operator 57 kubectl create -f examples/metrics/kubernetes/prometheus/bundle.yaml 58 59 ## Deploy the Kubernetes objects for RBAC, prometheus CRD and deploy the service 60 kubectl apply -f examples/metrics/kubernetes/prometheus/prom_rbac.yaml 61 kubectl apply -f examples/metrics/kubernetes/prometheus/prometheus.yaml 62 kubectl apply -f examples/metrics/kubernetes/prometheus/prom_service.yaml 63 64 make oci-image 65 # copy the image 66 COMMIT_HASH=$(git describe --always --tags --long) 67 echo "deploy zot-build:${COMMIT_HASH} image to local registry" 68 skopeo copy --format=oci --dest-tls-verify=false oci:oci docker://localhost:5001/zot-build:${COMMIT_HASH} 69 70 # deploy the image 71 kubectl apply -f examples/metrics/kubernetes/zot-extended/deployment.yaml 72 kubectl patch deployment/zot-extended --patch-file examples/metrics/kubernetes/zot-extended/patch-deployment.yaml 73 kubectl set image deployment/zot-extended zot-extended=localhost:5001/zot-build:${COMMIT_HASH} 74 kubectl apply -f examples/metrics/kubernetes/zot-extended/service.yaml 75 kubectl apply -f examples/metrics/kubernetes/zot-extended/servicemonitor.yaml 76 77 # check for availability 78 echo "Waiting for deployment/zot-extended to be ready ..." 79 kubectl wait deployment -n default zot-extended --for condition=Available=True --timeout=90s 80 kubectl wait deployment -n default prometheus-operator --for condition=Available=True --timeout=90s 81 82 kubectl port-forward svc/prometheus 9090 --address='0.0.0.0' & 83 echo "Kind cluster status before sleep:" 84 kubectl get pods -A 85 # Put enough amount of time for prometheus scraping take place 86 sleep 90 87 echo "Kind cluster status:" 88 kubectl get pods -A 89 echo "zot-extended logs:" 90 kubectl logs -l app=zot-extended --tail=-1 91 92 containername=`curl -s http://localhost:9090/api/v1/query?query=up | jq '.data.result[].metric.container'` 93 echo "containername=${containername}" 94 if [ "${containername}" != '"zot-extended"' ]; then 95 exit 1 96 fi 97 98 containerup=`curl -s http://localhost:9090/api/v1/query?query=up | jq '.data.result[].value[1]'` 99 echo "containerup=${containerup}" 100 if [ "${containerup}" != '"1"' ]; then 101 exit 1 102 fi 103 104 zotinfo=`curl -s http://localhost:9090/api/v1/query?query=zot_info | jq '.data.result[].value[1]'` 105 echo "zotinfo=${zotinfo}" 106 if [ "${zotinfo}" != '"0"' ]; then 107 exit 1 108 fi