diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 2c0f1c76..08e264c9 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -97,6 +97,27 @@ jobs: tags: | ghcr.io/${{ github.repository }}-minimal:${{ github.event.release.tag_name }} ghcr.io/${{ github.repository }}-minimal:latest + - name: Build zot-exporter container image + uses: docker/build-push-action@v2 + with: + build-args: | + COMMIT=${{ github.event.release.tag_name }}-${{ github.sha }} + push: true + file: Dockerfile-zxp + tags: | + ghcr.io/${{ github.repository }}-zxp:${{ github.event.release.tag_name }} + ghcr.io/${{ github.repository }}-zxp:latest + - name: Build zot-exporter container image (arm64) + uses: docker/build-push-action@v2 + with: + build-args: | + COMMIT=${{ github.event.release.tag_name }}-${{ github.sha }} + ARCH=arm64 + push: true + file: Dockerfile-arch-zxp + tags: | + ghcr.io/${{ github.repository }}-arm64-zxp:${{ github.event.release.tag_name }} + ghcr.io/${{ github.repository }}-arm64-zxp:latest - name: Build container image (arm64) uses: docker/build-push-action@v2 with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f3d2f76..c1ee6d7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,7 +68,7 @@ make binary-container . ... ├── cmd/zot # Source code contains the main logic -├── cmd/exporter # Source code contains the main logic for node exporter +├── cmd/zxp # Source code contains the main logic for node exporter ├── docs # Source code for Swagger docs ├── errors # Source code for errors ├── examples # Configuration examples to enable various features diff --git a/Dockerfile-arch-zxp b/Dockerfile-arch-zxp new file mode 100644 index 00000000..6f5f76bc --- /dev/null +++ b/Dockerfile-arch-zxp @@ -0,0 +1,33 @@ +# --- +# Stage 1: Build binary, create default config file +# --- +FROM ghcr.io/project-zot/golang:1.17 AS builder +ARG COMMIT +ARG ARCH +RUN mkdir -p /go/src/github.com/project-zot/zot +WORKDIR /go/src/github.com/project-zot/zot +COPY . . +RUN make COMMIT=$COMMIT ARCH=$ARCH clean exporter-minimal +RUN echo '{\n\ + "Server": {\n\ + "protocol": "http",\n\ + "host": "127.0.0.1",\n\ + "port": "5000"\n\ + },\n\ + "Exporter": {\n\ + "port": "5001",\n\ + "log": {\n\ + "level": "debug"\n\ + }\n\ + }\n\ +}\n' > config.json && cat config.json + +# --- +# Stage 2: Final image with nothing but binary and default config file +# --- +FROM scratch AS final +COPY --from=builder /go/src/github.com/project-zot/zot/bin/zxp /zxp +COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zxp/config.json +ENTRYPOINT ["/zxp"] +EXPOSE 5001 +CMD ["config", "/etc/zxp/config.json"] diff --git a/Dockerfile-zxp b/Dockerfile-zxp new file mode 100644 index 00000000..c4b88d84 --- /dev/null +++ b/Dockerfile-zxp @@ -0,0 +1,31 @@ +# --- +# Stage 1: Build binary, create default config file +# --- +FROM ghcr.io/project-zot/golang:1.17 AS builder +RUN mkdir -p /go/src/github.com/project-zot/zot +WORKDIR /go/src/github.com/project-zot/zot +COPY . . +RUN make clean exporter-minimal +RUN echo '{\n\ + "Server": {\n\ + "protocol": "http",\n\ + "host": "127.0.0.1",\n\ + "port": "5000"\n\ + },\n\ + "Exporter": {\n\ + "port": "5001",\n\ + "log": {\n\ + "level": "debug"\n\ + }\n\ + }\n\ +}\n' > config.json && cat config.json + +# --- +# Stage 2: Final image with nothing but binary and default config file +# --- +FROM scratch AS final +COPY --from=builder /go/src/github.com/project-zot/zot/bin/zxp /zxp +COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zxp/config.json +ENTRYPOINT ["/zxp"] +EXPOSE 5001 +CMD ["config", "/etc/zxp/config.json"] diff --git a/Makefile b/Makefile index 11b6e78b..353a4ef5 100644 --- a/Makefile +++ b/Makefile @@ -54,8 +54,12 @@ bench-arch: env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zb-$(ARCH) -tags extended,containers_image_openpgp -v -trimpath -ldflags "-X zotregistry.io/zot/pkg/api/config.Commit=${COMMIT} -X zotregistry.io/zot/pkg/api/config.BinaryType=extended -X zotregistry.io/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zb .PHONY: exporter-minimal -exporter-minimal: swagger - env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-exporter -tags minimal,containers_image_openpgp -v -trimpath ./cmd/exporter +exporter-minimal: + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zxp -tags minimal,containers_image_openpgp -v -trimpath ./cmd/zxp + +.PHONY: exporter-arch-minimal +exporter-arch-minimal: + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zxp-$(ARCH) -tags minimal,containers_image_openpgp -v -trimpath ./cmd/zxp .PHONY: test test: check-skopeo $(NOTATION) diff --git a/README.md b/README.md index 2ad06f32..71afb526 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,7 @@ The dist-spec-only zot exposes internal metrics into a Prometheus format through The configuration of node exporter contains connection details for the zot server it is intend to scrape metrics from. See a [configuration example](./examples/metrics/exporter/config-minimal.json). The metrics are automatically enabled in the zot server on first scrape from the Node Exporter (no extra configuration option is needed). Similarly, the metrics are automatically disabled when Node Exporter did not perform any scrapings in a while. ``` -bin/zot-exporter config _config-file_ +bin/zxp config _config-file_ ``` ## Enable Metrics diff --git a/cmd/exporter/main.go b/cmd/zxp/main.go similarity index 100% rename from cmd/exporter/main.go rename to cmd/zxp/main.go diff --git a/examples/metrics/Dockerfile-exporter b/examples/metrics/Dockerfile-zxp similarity index 62% rename from examples/metrics/Dockerfile-exporter rename to examples/metrics/Dockerfile-zxp index e14ad642..ff723f49 100644 --- a/examples/metrics/Dockerfile-exporter +++ b/examples/metrics/Dockerfile-zxp @@ -1,5 +1,5 @@ # --- -# Stage 1: Install certs, build binary, create default config file +# Stage 1: Build binary, create default config file # --- FROM ghcr.io/project-zot/golang:1.17 AS builder RUN mkdir -p /go/src/github.com/project-zot/zot @@ -21,12 +21,11 @@ RUN echo '{\n\ }\n' > config.json && cat config.json # --- -# Stage 2: Final image with nothing but certs, binary, and default config file +# Stage 2: Final image with nothing but binary and default config file # --- FROM scratch AS final -COPY --from=builder /go/src/github.com/project-zot/zot/bin/zot-exporter /zot-exporter -COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zot/config.json -ENTRYPOINT ["/zot-exporter"] +COPY --from=builder /go/src/github.com/project-zot/zot/bin/zxp /zxp +COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zxp/config.json +ENTRYPOINT ["/zxp"] EXPOSE 5051 -VOLUME ["/var/lib/registry"] -CMD ["config", "/etc/zot/config.json"] +CMD ["config", "/etc/zxp/config.json"] diff --git a/examples/metrics/Makefile b/examples/metrics/Makefile index 77eb396b..952c6556 100644 --- a/examples/metrics/Makefile +++ b/examples/metrics/Makefile @@ -20,9 +20,8 @@ run-minimal-container: .PHONY: binary-exporter-container binary-exporter-container: - ${CONTAINER_RUNTIME} build -f Dockerfile-exporter -t zot-exporter:latest ../../. + ${CONTAINER_RUNTIME} build -f Dockerfile-zxp -t zxp:latest ../../. .PHONY: run-exporter-container run-exporter-container: - ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd)/../..:/go/src/github.com/project-zot/zot \ - zot-exporter:latest + ${CONTAINER_RUNTIME} run --rm --security-opt label=disable zxp:latest diff --git a/examples/metrics/README.md b/examples/metrics/README.md index 5451df83..9c2a890e 100644 --- a/examples/metrics/README.md +++ b/examples/metrics/README.md @@ -24,5 +24,5 @@ At the end of the script below ports are locally available (using *kubectl port- * 9090 - for accessing Prometheus server * 5000 - for zot with all extensions enabled * 5050 - for accessing dist-spec-only zot server - * 5051 - for zot-exporter access (a Prometheus Node exporter) + * 5051 - for zxp access (a Prometheus Node exporter) diff --git a/examples/metrics/kind_setup.sh b/examples/metrics/kind_setup.sh index bab1c0b1..c52219a6 100755 --- a/examples/metrics/kind_setup.sh +++ b/examples/metrics/kind_setup.sh @@ -40,14 +40,14 @@ kind load docker-image quay.io/prometheus-operator/prometheus-operator:v0.51.2 - kind load docker-image quay.io/prometheus-operator/prometheus-config-reloader:v0.51.2 --name ${CLUSTER_NAME} kind load docker-image quay.io/prometheus/prometheus:v2.22.1 --name ${CLUSTER_NAME} -## Build zot & zot-exporter related images +## Build zot & zxp images make binary-container make binary-minimal-container make binary-exporter-container kind load docker-image zot-build:latest --name ${CLUSTER_NAME} kind load docker-image zot-minimal:latest --name ${CLUSTER_NAME} -kind load docker-image zot-exporter:latest --name ${CLUSTER_NAME} +kind load docker-image zxp:latest --name ${CLUSTER_NAME} ## Deploy prometheus operator kubectl create -f kubernetes/prometheus/bundle.yaml diff --git a/examples/metrics/kubernetes/zot-minimal/deployment.yaml b/examples/metrics/kubernetes/zot-minimal/deployment.yaml index 20df7bc7..c9aeccf8 100644 --- a/examples/metrics/kubernetes/zot-minimal/deployment.yaml +++ b/examples/metrics/kubernetes/zot-minimal/deployment.yaml @@ -22,7 +22,7 @@ spec: - name: zot-minimal containerPort: 5050 - name: zot-exporter - image: zot-exporter:latest + image: zxp:latest imagePullPolicy: IfNotPresent ports: - name: zot-exporter diff --git a/pkg/exporter/cli/cli.go b/pkg/exporter/cli/cli.go index 92e5454e..3fbc9eee 100644 --- a/pkg/exporter/cli/cli.go +++ b/pkg/exporter/cli/cli.go @@ -41,9 +41,9 @@ func NewExporterCmd() *cobra.Command { // "node_exporter" exporterCmd := &cobra.Command{ - Use: "zot_exporter", - Short: "`zot_exporter`", - Long: "`zot_exporter`", + Use: "zxp", + Short: "`zxp`", + Long: "`zxp`", Run: func(cmd *cobra.Command, args []string) { _ = cmd.Usage() cmd.SilenceErrors = false