Skip to content

Commit

Permalink
Use pyproject.toml, pip-compile and venv to build container image (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
znerol authored Jan 6, 2024
1 parent 6c71909 commit eee11ab
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ updates:
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Install pylint / pyflakes
run: |
sudo apt-get update
sudo apt-get install --yes pylint pyflakes3
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: pip install -r requirements.txt

- name: Install test dependencies
run: pip install -r requirements-test.txt

- name: Install pve_exporter
run: sudo pip install -e .
run: pip install .

- name: Run pylint
run: pylint pve_exporter

- name: Run pyflakes
run: pyflakes3 src/pve_exporter
run: pyflakes src/pve_exporter
30 changes: 9 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
FROM alpine:3.18.5 as base
FROM alpine:3.18.5
RUN apk update && apk upgrade

RUN apk add --no-cache \
ca-certificates \
py3-gunicorn \
py3-paramiko \
py3-pip \
py3-prometheus-client \
py3-requests \
py3-werkzeug \
py3-wheel \
py3-yaml \
python3

FROM base as builder
ADD . /src
WORKDIR /opt
RUN pip3 wheel --no-deps /src proxmoxer==2.0.1
ADD . /src/prometheus-pve-exporter
RUN python3 -m venv /opt/prometheus-pve-exporter && \
/opt/prometheus-pve-exporter/bin/pip install -r /src/prometheus-pve-exporter/requirements.txt && \
/opt/prometheus-pve-exporter/bin/pip install /src/prometheus-pve-exporter && \
ln -s /opt/prometheus-pve-exporter/bin/pve_exporter /usr/bin/pve_exporter && \
rm -rf /src/prometheus-pve-exporter /root/.cache

FROM base as runtime

COPY --from=builder /opt /opt

RUN pip3 install --no-cache-dir --no-index /opt/*py3-none-any.whl && \
rm /opt/*py3-none-any.whl && \
addgroup -S -g 101 prometheus && \
RUN addgroup -S -g 101 prometheus && \
adduser -D -H -S -G prometheus -u 101 prometheus

USER prometheus

EXPOSE 9221

ENTRYPOINT [ "/usr/bin/pve_exporter" ]
ENTRYPOINT [ "/opt/prometheus-pve-exporter/bin/pve_exporter" ]
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "prometheus-pve-exporter"
version = "3.1.0"
authors = [{ name = "Lorenz Schori", email = "[email protected]" }]
description = "Proxmox VE exporter for the Prometheus monitoring system."
requires-python = ">=3.9"
keywords = ["prometheus", "exporter", "network", "monitoring", "proxmox"]
license = { text = "Apache-2.0" }
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Information Technology",
"Intended Audience :: System Administrators",
"Topic :: System :: Monitoring",
"Topic :: System :: Networking :: Monitoring",
"License :: OSI Approved :: Apache Software License",
]
dynamic = ["dependencies", "optional-dependencies", "readme"]

[project.urls]
Homepage = "https://github.com/prometheus-pve/prometheus-pve-exporter"

[project.scripts]
pve_exporter = "pve_exporter.cli:main"

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.in"] }
optional-dependencies.test = { file = ["requirements-test.txt"] }
readme = { file = ["README.rst"] }
2 changes: 2 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pylint==2.12.2
pyflakes
7 changes: 7 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prometheus_client>=0.0.11
proxmoxer
pyyaml
requests
Werkzeug
gunicorn
paramiko
378 changes: 378 additions & 0 deletions requirements.txt

Large diffs are not rendered by default.

37 changes: 1 addition & 36 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
from setuptools import find_packages
from setuptools import setup

setup(
name="prometheus-pve-exporter",
version="3.1.0",
author="Lorenz Schori",
author_email="[email protected]",
description=("Proxmox VE exporter for the Prometheus monitoring system."),
long_description=open('README.rst').read(),
license="Apache Software License 2.0",
keywords="prometheus exporter network monitoring proxmox",
url="https://github.com/prometheus-pve/prometheus-pve-exporter",
package_dir={"": "src"},
packages=find_packages('src'),
entry_points={
'console_scripts': [
'pve_exporter=pve_exporter.cli:main',
],
},
python_requires=">=3.9",
install_requires=[
"prometheus_client>=0.0.11",
"proxmoxer",
"pyyaml",
"requests",
'Werkzeug',
'gunicorn',
],
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Information Technology",
"Intended Audience :: System Administrators",
"Topic :: System :: Monitoring",
"Topic :: System :: Networking :: Monitoring",
"License :: OSI Approved :: Apache Software License",
],
)
setup()
2 changes: 0 additions & 2 deletions test-requirements.txt

This file was deleted.

0 comments on commit eee11ab

Please sign in to comment.