From 576e29c4784190935415e677257300d9ef44de4a Mon Sep 17 00:00:00 2001 From: Alexei Dodon Date: Fri, 6 Oct 2023 18:26:43 +0300 Subject: [PATCH] fix: quick metrics setup in kind with prometheus Signed-off-by: Alexei Dodon --- Makefile | 19 +++++++- examples/metrics/Dockerfile | 2 +- examples/metrics/Dockerfile-minimal | 2 +- examples/metrics/Dockerfile-zxp | 2 +- examples/metrics/Makefile | 27 ------------ examples/metrics/kind_setup.sh | 6 ++- .../kubernetes/prometheus/prom_rbac.yaml | 4 +- .../kubernetes/zot-extended/deployment.yaml | 43 ++++++++++++++++++- 8 files changed, 69 insertions(+), 36 deletions(-) delete mode 100644 examples/metrics/Makefile diff --git a/Makefile b/Makefile index eb9dfae793..28f0531afa 100644 --- a/Makefile +++ b/Makefile @@ -259,7 +259,7 @@ swagger: .PHONY: update-licenses # note: for predictable output of below sort command we use locale LC_ALL=C update-licenses: LC_ALL=C -update-licenses: +update-licenses: check-linux @echo "Detecting and updating licenses ... please be patient!" go install github.com/google/go-licenses@latest $(shell echo "Module | License URL | License" > THIRD-PARTY-LICENSES.md; echo "---|---|---" >> THIRD-PARTY-LICENSES.md; for i in $$(go list -m all | awk '{print $$1}'); do l=$$(go-licenses csv $$i 2>/dev/null); if [ $$? -ne 0 ]; then continue; fi; echo $$l | tr \, \| | tr ' ' '\n'; done | sort -u >> THIRD-PARTY-LICENSES.md) @@ -362,6 +362,23 @@ run-container: ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/go/src/github.com/project-zot/zot \ zot-build:latest +.PHONY: binary-minimal-container +binary-minimal-container: + ${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f build/Dockerfile-minimal -t zot-minimal:latest . + +.PHONY: run-minimal-container +run-minimal-container: + ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/go/src/github.com/project-zot/zot \ + zot-minimal:latest + +.PHONY: binary-exporter-container +binary-exporter-container: + ${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f build/Dockerfile-zxp -t zxp:latest . + +.PHONY: run-exporter-container +run-exporter-container: + ${CONTAINER_RUNTIME} run --rm --security-opt label=disable zxp:latest + .PHONY: oci-image oci-image: $(STACKER) ${STACKER} --debug build \ diff --git a/examples/metrics/Dockerfile b/examples/metrics/Dockerfile index 1239a18c9d..84cf1bcf8d 100644 --- a/examples/metrics/Dockerfile +++ b/examples/metrics/Dockerfile @@ -1,7 +1,7 @@ # --- # Stage 1: Install certs, build binary, create default config file # --- -FROM ghcr.io/project-zot/golang:1.19 AS builder +FROM ghcr.io/project-zot/golang:1.20 AS builder RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . diff --git a/examples/metrics/Dockerfile-minimal b/examples/metrics/Dockerfile-minimal index d05d560635..0d76b2ec25 100644 --- a/examples/metrics/Dockerfile-minimal +++ b/examples/metrics/Dockerfile-minimal @@ -1,7 +1,7 @@ # --- # Stage 1: Install certs, build binary, create default config file # --- -FROM ghcr.io/project-zot/golang:1.19 AS builder +FROM ghcr.io/project-zot/golang:1.20 AS builder RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . diff --git a/examples/metrics/Dockerfile-zxp b/examples/metrics/Dockerfile-zxp index ebe35685c4..f3e2f5442a 100644 --- a/examples/metrics/Dockerfile-zxp +++ b/examples/metrics/Dockerfile-zxp @@ -1,7 +1,7 @@ # --- # Stage 1: Build binary, create default config file # --- -FROM ghcr.io/project-zot/golang:1.19 AS builder +FROM ghcr.io/project-zot/golang:1.20 AS builder RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . diff --git a/examples/metrics/Makefile b/examples/metrics/Makefile deleted file mode 100644 index 2dbe13a9c4..0000000000 --- a/examples/metrics/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -CONTAINER_RUNTIME := docker - -.PHONY: binary-container -binary-container: - ${CONTAINER_RUNTIME} build -f build/Dockerfile -t zot-build:latest ../../. - -.PHONY: run-container -run-container: - ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd)/../..:/go/src/github.com/project-zot/zot \ - zot-build:latest - -.PHONY: binary-minimal-container -binary-minimal-container: - ${CONTAINER_RUNTIME} build -f build/Dockerfile-minimal -t zot-minimal:latest ../../. - -.PHONY: run-minimal-container -run-minimal-container: - ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd)/../..:/go/src/github.com/project-zot/zot \ - zot-minimal:latest - -.PHONY: binary-exporter-container -binary-exporter-container: - ${CONTAINER_RUNTIME} build -f build/Dockerfile-zxp -t zxp:latest ../../. - -.PHONY: run-exporter-container -run-exporter-container: - ${CONTAINER_RUNTIME} run --rm --security-opt label=disable zxp:latest diff --git a/examples/metrics/kind_setup.sh b/examples/metrics/kind_setup.sh index c52219a687..51d1ff9ba5 100755 --- a/examples/metrics/kind_setup.sh +++ b/examples/metrics/kind_setup.sh @@ -6,8 +6,8 @@ set -e CLUSTER_NAME=zot # Script tested with below kubectl & kind versions -KUBECTL_VERSION=v1.17.5 -KIND_VERSION=v0.7.0 +KUBECTL_VERSION=v1.27.3 +KIND_VERSION=v0.20.0 function install_bin() { if [ "$EUID" -ne 0 ] @@ -41,9 +41,11 @@ kind load docker-image quay.io/prometheus-operator/prometheus-config-reloader:v0 kind load docker-image quay.io/prometheus/prometheus:v2.22.1 --name ${CLUSTER_NAME} ## Build zot & zxp images +pushd ../../ make binary-container make binary-minimal-container make binary-exporter-container +popd kind load docker-image zot-build:latest --name ${CLUSTER_NAME} kind load docker-image zot-minimal:latest --name ${CLUSTER_NAME} diff --git a/examples/metrics/kubernetes/prometheus/prom_rbac.yaml b/examples/metrics/kubernetes/prometheus/prom_rbac.yaml index c6bf0e8fb7..5b8fd88ec5 100644 --- a/examples/metrics/kubernetes/prometheus/prom_rbac.yaml +++ b/examples/metrics/kubernetes/prometheus/prom_rbac.yaml @@ -3,7 +3,7 @@ kind: ServiceAccount metadata: name: prometheus --- -apiVersion: rbac.authorization.k8s.io/v1beta1 +apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: prometheus @@ -28,7 +28,7 @@ rules: - nonResourceURLs: ["/metrics"] verbs: ["get"] --- -apiVersion: rbac.authorization.k8s.io/v1beta1 +apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: prometheus diff --git a/examples/metrics/kubernetes/zot-extended/deployment.yaml b/examples/metrics/kubernetes/zot-extended/deployment.yaml index 108fab8b10..f479264abb 100644 --- a/examples/metrics/kubernetes/zot-extended/deployment.yaml +++ b/examples/metrics/kubernetes/zot-extended/deployment.yaml @@ -18,7 +18,48 @@ spec: - name: zot-extended image: zot-build:latest imagePullPolicy: IfNotPresent + command: ["/usr/bin/zot"] + args: ["serve", "/zot-config/config.json"] ports: - name: zot-extended containerPort: 5000 - + protocol: TCP + volumeMounts: + - name: zot-config + mountPath: /zot-config + readOnly: false + volumes: + - name: zot-config + configMap: + name: zot-config + items: + - key: zot_config.json + path: config.json +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: zot-config +data: + zot_config.json: | + { + "distSpecVersion":"1.0.1", + "storage": { + "rootDirectory": "/var/lib/registry" + }, + "http": { + "address": "0.0.0.0", + "port": "5000" + }, + "log": { + "level": "debug" + }, + "extensions": { + "metrics": { + "enable": true, + "prometheus": { + "path": "/metrics" + } + } + } + }