From cd4a49c23af97d07ecaeab31d4e425e94614bd7d Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 8 Dec 2024 15:47:21 +0100 Subject: [PATCH 1/9] CI: Update to Grafana "9.5.21", "10.3.12", "10.4.14", "11.4.0" --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 85dbef0..904cfcf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,7 @@ jobs: matrix: os: [ "ubuntu-latest" ] python-version: [ "3.8", "3.13" ] - grafana-version: [ "6.7.6", "7.5.17", "8.5.27", "9.5.18", "10.3.5", "10.4.1", "11.2.2" ] + grafana-version: [ "6.7.6", "7.5.17", "8.5.27", "9.5.21", "10.3.12", "10.4.14", "11.4.0" ] env: OS_TYPE: ${{ matrix.os }} From a9e5624e424d88363bddddbc22e09152e60a6eff Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 8 Dec 2024 15:50:19 +0100 Subject: [PATCH 2/9] Documentation: Prefer `pipx` over `pip` for installing standalone tools --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 0d5f1f7..055c016 100644 --- a/README.rst +++ b/README.rst @@ -112,7 +112,7 @@ Install ``grafana-wtf`` ======================= :: - pip install grafana-wtf + pipx install grafana-wtf Configure Grafana From 5c55e750f40ee1bc162ad2e6f2bcb320cde40079 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 8 Dec 2024 16:08:12 +0100 Subject: [PATCH 3/9] OCI: Improve build efficiency, reduce from 0m33s to 0m22s, using `uv` time docker build -t grafana-wtf:dev . --- Dockerfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9cccc6e..096efdf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,8 +8,12 @@ RUN apt-get update RUN apt-get --yes install jq # Provide sources -COPY . /app +COPY . /src # Install package -WORKDIR /app -RUN pip install --prefer-binary . +ENV UV_SYSTEM_PYTHON=true +RUN \ + true \ + && pip install uv \ + && uv pip install /src \ + && uv pip uninstall uv From 230abd620c307d116bfb8572e743be1d3628ecff Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 8 Dec 2024 16:09:02 +0100 Subject: [PATCH 4/9] Chore: Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c5d3f39..2fa4dee 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /.idea /.venv* /var +/build /dist .coverage coverage.xml From 4883077f90b4f3b47b955c7ec0e9d7143add0bc2 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 8 Dec 2024 16:12:26 +0100 Subject: [PATCH 5/9] OCI: Update baseline image to `python:3.13-slim-bookworm` --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 096efdf..2b3c098 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-slim-bullseye +FROM python:3.13-slim-bookworm ENV DEBIAN_FRONTEND=noninteractive ENV TERM=linux From ba020d3382f3a9ef40fb0a07c5f783e326a72421 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 8 Dec 2024 16:48:14 +0100 Subject: [PATCH 6/9] CI: Use `uv` on GHA to speed up installing dependency packages --- .github/workflows/tests.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 904cfcf..00cdc7d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,6 +33,7 @@ jobs: OS_TYPE: ${{ matrix.os }} PYTHON_VERSION: ${{ matrix.python-version }} GRAFANA_VERSION: ${{ matrix.grafana-version }} + UV_SYSTEM_PYTHON: true name: Python ${{ matrix.python-version }}, Grafana ${{ matrix.grafana-version }} steps: @@ -40,7 +41,7 @@ jobs: - name: Acquire sources uses: actions/checkout@v4 - - name: Setup Python + - name: Set up Python uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -48,10 +49,18 @@ jobs: cache: 'pip' cache-dependency-path: 'setup.py' - - name: Setup Project + - name: Set up uv + uses: astral-sh/setup-uv@v4 + with: + cache-dependency-glob: | + setup.py + cache-suffix: ${{ matrix.python-version }} + enable-cache: true + version: "latest" + + - name: Set up project run: | - pip install pip 'setuptools>=64' --upgrade - pip install --editable='.[test]' + uv pip install --editable='.[test]' - name: Run tests run: | From 320266df0fff2221f53e8505da416061651110de Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 8 Dec 2024 17:24:24 +0100 Subject: [PATCH 7/9] OCI: Improve image by bundling all build commands Also, remove build artefacts. --- Dockerfile | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b3c098..234693e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,30 @@ FROM python:3.13-slim-bookworm +# Configure operating system ENV DEBIAN_FRONTEND=noninteractive ENV TERM=linux -# Install prerequisites -RUN apt-get update -RUN apt-get --yes install jq - -# Provide sources +# Provide package sources COPY . /src -# Install package +# Install package and dependencies +ENV UV_COMPILE_BYTECODE=true +ENV UV_NO_CACHE=true +ENV UV_PYTHON_DOWNLOADS=never ENV UV_SYSTEM_PYTHON=true RUN \ true \ + # Install package. && pip install uv \ && uv pip install /src \ - && uv pip uninstall uv + && uv pip uninstall uv \ + # Install `jq`. + && apt-get update \ + && apt-get install --no-install-recommends --no-install-suggests --yes jq \ + # Tear down. + && apt-get autoremove --yes \ + && apt-get autoclean --yes \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /root/.cache \ + && rm -rf /src \ + && rm -rf /tmp/* From c50530b4939dd43542f4235bcc60b4ca38355514 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 8 Dec 2024 18:35:55 +0100 Subject: [PATCH 8/9] OCI: Improve packaging by using multi-stage builds --- Dockerfile | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 234693e..f9a4fed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,42 @@ -FROM python:3.13-slim-bookworm +# ----- +# Build +# ----- +FROM python:3.13-bookworm AS build + +# For more verbose output, use: +# export BUILDKIT_PROGRESS=plain # Configure operating system ENV DEBIAN_FRONTEND=noninteractive ENV TERM=linux +# Configure build environment +ENV PIP_ROOT_USER_ACTION=ignore +ENV UV_COMPILE_BYTECODE=true +ENV UV_LINK_MODE=copy +ENV UV_PYTHON_DOWNLOADS=never + # Provide package sources COPY . /src # Install package and dependencies -ENV UV_COMPILE_BYTECODE=true -ENV UV_NO_CACHE=true -ENV UV_PYTHON_DOWNLOADS=never -ENV UV_SYSTEM_PYTHON=true RUN \ + --mount=type=cache,id=pip,target=/root/.cache/pip \ + --mount=type=cache,id=uv,target=/root/.cache/uv \ true \ - # Install package. && pip install uv \ - && uv pip install /src \ - && uv pip uninstall uv \ - # Install `jq`. - && apt-get update \ - && apt-get install --no-install-recommends --no-install-suggests --yes jq \ - # Tear down. - && apt-get autoremove --yes \ - && apt-get autoclean --yes \ - && rm -rf /var/lib/apt/lists/* \ - && rm -rf /root/.cache \ - && rm -rf /src \ - && rm -rf /tmp/* + && uv venv --no-project --relocatable /app \ + && uv pip install --directory=/app /src + +# Install optional software +RUN wget --quiet --output-document=/tmp/jq "https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64" +RUN chmod +x /tmp/jq + + +# ------------ +# Distribution +# ------------ +FROM python:3.13-slim-bookworm +COPY --from=build /app /opt/grafana-wtf +COPY --from=build /tmp/jq /usr/local/bin/jq +ENV PATH="$PATH:/opt/grafana-wtf/bin" From abc7bc0f3d1f763d71e19897f53de72905035af5 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 9 Dec 2024 01:00:28 +0100 Subject: [PATCH 9/9] Documentation: Fix broken link to `git-wtf` --- README.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 055c016..43f4fc7 100644 --- a/README.rst +++ b/README.rst @@ -41,9 +41,8 @@ grafana-wtf ***** About ***** -grafana-wtf - grep through all Grafana entities in the spirit of `git-wtf`_. - -.. _git-wtf: http://thrawn01.org/posts/2014/03/03/git-wtf/ +grafana-wtf - grep through all Grafana entities in the spirit of `git-wtf`_, +see also `Introduction to GIT WTF`_. .. attention:: @@ -277,4 +276,6 @@ Development pytest --keepalive -vvv -k test_find_textual +.. _git-wtf: https://github.com/DanielVartanov/willgit/blob/master/bin/git-wtf .. _grafana-wtf examples: https://github.com/grafana-toolbox/grafana-wtf/blob/main/doc/examples.rst +.. _Introduction to GIT WTF: https://web.archive.org/web/20230921074244/https://thrawn01.org/posts/2014/03/03/git-wtf/