diff --git a/.circleci/config.yml b/.circleci/config.yml index 2445ec87..6ac62edc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,8 +53,8 @@ jobs: steps: - prometheus/setup_build_environment: docker_version: "" - - run: make -C generator docker DOCKER_IMAGE_TAG=main - - run: make -C generator docker DOCKER_REPO=quay.io/prometheus DOCKER_IMAGE_TAG=main + - run: make -C generator docker REPO_TAG=main DOCKER_IMAGE_TAG=main + - run: make -C generator docker REPO_TAG=main DOCKER_REPO=quay.io/prometheus DOCKER_IMAGE_TAG=main - run: docker images - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io @@ -67,8 +67,8 @@ jobs: steps: - prometheus/setup_build_environment: docker_version: "" - - run: make -C generator docker DOCKER_IMAGE_TAG=$CIRCLE_TAG - - run: make -C generator docker DOCKER_IMAGE_TAG=$CIRCLE_TAG DOCKER_REPO=quay.io/prometheus + - run: make -C generator docker REPO_TAG=$CIRCLE_TAG DOCKER_IMAGE_TAG=$CIRCLE_TAG + - run: make -C generator docker REPO_TAG=$CIRCLE_TAG DOCKER_IMAGE_TAG=$CIRCLE_TAG DOCKER_REPO=quay.io/prometheus - run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io - run: | diff --git a/generator/Dockerfile b/generator/Dockerfile index b1281394..7be2e0d5 100644 --- a/generator/Dockerfile +++ b/generator/Dockerfile @@ -1,13 +1,23 @@ -FROM golang:latest +FROM golang:bookworm AS builder -RUN apt-get update && \ - apt-get install -y libsnmp-dev unzip && \ - go install github.com/prometheus/snmp_exporter/generator@latest +RUN apt-get update \ + && apt-get install -y --no-install-recommends libsnmp-dev + +ARG REPO_TAG=main +RUN go install github.com/prometheus/snmp_exporter/generator@"$REPO_TAG" + +FROM debian:bookworm-slim WORKDIR "/opt" -ENTRYPOINT ["/go/bin/generator"] +ENTRYPOINT ["/bin/generator"] -ENV MIBDIRS mibs +ENV MIBDIRS=mibs CMD ["generate"] + +RUN apt-get update \ + && apt-get install -y --no-install-recommends libsnmp40 \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /go/bin/generator /bin/generator diff --git a/generator/Makefile b/generator/Makefile index f7f113ea..16703e61 100644 --- a/generator/Makefile +++ b/generator/Makefile @@ -16,8 +16,10 @@ MIB_PATH := 'mibs' CURL_OPTS ?= -L --no-progress-meter --retry 3 --retry-delay 3 --fail +REPO_TAG ?= $(shell git rev-parse --abbrev-ref HEAD) + DOCKER_IMAGE_NAME ?= snmp-generator -DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) +DOCKER_IMAGE_TAG ?= $(subst /,-,$(REPO_TAG)) DOCKER_REPO ?= prom SANITIZED_DOCKER_IMAGE_TAG := $(subst +,-,$(DOCKER_IMAGE_TAG)) @@ -79,7 +81,7 @@ parse_errors: generator mibs .PHONY: docker docker: - docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" . + docker build --build-arg REPO_TAG="$(REPO_TAG)" -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" . .PHONY: docker-generate docker-generate: docker mibs