diff --git a/Dockerfile b/Dockerfile index 6347827..213192a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,29 @@ ARG OS=alpine ARG VERSION=3.8 ARG MAINT="nicolas.coudene@epfl.ch" ARG DESC="This image is used to use sausage" FROM python:$VERSION-$OS LABEL maintainer=$MAINT LABEL Description=$DESC WORKDIR /usr/src/app -ENV VERSION=3.8 -RUN apk --no-cache add ca-certificates COPY ssl/certs /usr/local/share/ca-certificates/ -RUN update-ca-certificates - COPY requirements.txt ./ -RUN python --version -RUN python -m pip install --no-cache-dir -r requirements.txt - +RUN apk --no-cache add ca-certificates && \ + update-ca-certificates && \ + python -m pip install --no-cache-dir -r requirements.txt # fix a bug when python did not detect default cacert dir -RUN cat /usr/local/share/ca-certificates/* >> /usr/local/lib/python$VERSION/site-packages/certifi/cacert.pem +RUN cat /usr/local/lib/python*/site-packages/certifi/cacert.pem /usr/local/share/ca-certificates/* > /tmp/cacert.pem && \ + cp /tmp/cacert.pem /usr/local/lib/python*/site-packages/certifi/cacert.pem -#COPY README.rst setup.py sausage.cfg Sausage ./ -#RUN python setup.py install -COPY sausage.cfg /etc/sausage/ -COPY sausage.template.j2 /etc/sausage/ +COPY README.rst setup.py setup.cfg ./build/ +COPY src ./build/src +COPY src/etc/sausage.cfg src/etc/sausage.template.j2 /etc/sausage/ +RUN pip install build/ && \ + rm -rf ./build/ setup.* README.rst -COPY Sausage ./ -COPY sausage ./sausage -CMD [ "python", "/usr/src/app/Sausage" ] +ENTRYPOINT [ "sausage" ] diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..321fa3d --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,38 @@ +# Docker + +Build the image : +``` +docker build -t sausage-app . +``` + +# Singularity + +Build a docker image and then build a singularity image with it : + +``` +docker build -t sausage-app . +singularity build -F sausage-app.sif docker-daemon://sausage-app +``` + +OR + +Build a docker image, save it and build a singularity image with the archive : +``` +docker build -t sausage-app . +docker save sausage-app -o sausage-app.tar +singularity build -F sausage-app.sif docker-archive://sausage-app.tar +``` + +Note: usefull if you do not have docker and singularity on the same system. + +# RPM + +TODO + +# Python + +``` +pip3 install . +mkir /etc/sausage +cp src/etc/* /etc/sausage +``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b1615dc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42.0", + "wheel", +] +build-backend = "setuptools.build_meta" diff --git a/sausage.spec b/sausage.spec index 701b864..d2892cb 100644 --- a/sausage.spec +++ b/sausage.spec @@ -1,58 +1,54 @@ -%define name sausage -%define version 0.1.7 -%define unmangled_version 0.1.7 +%define name Sausage +%define version 0.2 +%define unmangled_version 0.2 %define release 1 Summary: Command-line interface to query the sausage-API service Name: %{name} Version: %{version} Release: %{release}%{?dist} Source0: %{name}-%{unmangled_version}.tar.gz License: GPL v3 Group: Development/Libraries BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot Prefix: %{_prefix} BuildArch: noarch Vendor: ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE Url: https://c4science.ch/source/sausage-binary/ -BuildRequires: python3-setuptools -%if 0%{?rhel} < 8 -Requires: python36-requests -%else -Requires: python3 python3-requests -%endif +#BuildRequires: python3-setuptools +Requires: python3 %description SLURM account usage (Sausage) ============================= This project implements a Command-line interface to query the sausage-API service. The service queries the elastic instance created by the jobcomp/elasticsearch plugin provided by SchedMD. %prep %setup -n %{name}-%{unmangled_version} -n %{name}-%{unmangled_version} %build python3 setup.py build /usr/bin/mkdir -p %{buildroot}/etc/sausage/ -/usr/bin/mkdir -p %{buildroot}/usr/bin/ %install python3 setup.py install --single-version-externally-managed -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES -install -m 644 sausage.cfg %{buildroot}/etc/sausage/ -install -m 600 sausage.secure %{buildroot}/etc/sausage/ -install -m 755 Sausage %{buildroot}/usr/bin/ +install -m 644 src/etc/sausage.cfg %{buildroot}/etc/sausage/ +install -m 644 src/etc/sausage.template.j2 %{buildroot}/etc/sausage/ %clean rm -rf $RPM_BUILD_ROOT +%post +python3 -m pip install --user elasticseach + %files -f INSTALLED_FILES %defattr(-,root,root) /etc/sausage/sausage.cfg -/etc/sausage/sausage.secure -/usr/bin/Sausage +/etc/sausage/sausage.template.j2 diff --git a/sausage/__init__.py b/sausage/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8c241d2 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,53 @@ +[metadata] +name = sausage +version = 0.2 +description = Command-line interface to query slurm accouting database +long_description = file: README.rst +long_description_content_type = text/markdown +author = Nicolas Coudene +author_email = nicolas.coudene@epfl.ch +url = https://c4science.ch/source/sausage-binary/ +license = GPL v3 +platforms = linux +classifiers = + Development Status :: 4 - Beta + Intended Audience :: System Administrators + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Natural Language :: English + Operating System :: POSIX :: Linux + Topic :: System :: Logging + Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 +keywords = + hpc + supercomputers + consumptions + billing + slurm + elasticsearch +[bdist_rpm] +release = 1 +group = Development/Libraries +doc_files = + README.rst +vendor = ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE + +[options] +package_dir = + =src +packages = + sausage +install_requires = + elasticsearch + elasticsearch-dsl + elastic-transport<9,>=8 + jinja2 +python_requires = >=3.6 +zip_safe = False +[options.entry_points] +console_scripts = + sausage = sausage.__main__:main diff --git a/setup.py b/setup.py index b3719c5..5fb1672 100644 --- a/setup.py +++ b/setup.py @@ -1,31 +1,10 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -from setuptools import setup, find_packages +from setuptools import setup -desc = "" -with open("README.rst") as f: - desc = f.read() - -setup( - name="Sausage", - scripts=["Sausage"], - data_files=[("/etc/sausage", ["sausage.cfg","sausage.template.j2"])], - version="0.1.7", - description=("Command-line interface to query slurm accouting database"), - long_description=desc, - url="", - author="Nicolas Coudene", - author_email="nicolas.coudene@epfl.ch", - license="GPL v3", - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: System Administrators", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Natural Language :: English", - "Operating System :: POSIX :: Linux", - "Programming Language :: Python :: 3.9", - "Topic :: System :: Logging", - ], - keywords=["hpc", "supercomputers", "consumption", "billing", "slurm"], - packages=find_packages(exclude=["docs", "test*"]), -) +if __name__ == "__main__": + setup( + # data_files=[ + # ("/etc/sausage", ["src/etc/sausage.cfg", "src/etc/sausage.template.j2"]) + # ], + ) diff --git a/sausage.cfg b/src/etc/sausage.cfg similarity index 100% rename from sausage.cfg rename to src/etc/sausage.cfg diff --git a/sausage.template.j2 b/src/etc/sausage.template.j2 similarity index 100% rename from sausage.template.j2 rename to src/etc/sausage.template.j2 diff --git a/Sausage b/src/sausage/__init__.py old mode 100755 new mode 100644 similarity index 91% rename from Sausage rename to src/sausage/__init__.py index 3ac5aa3..9c89f4e --- a/Sausage +++ b/src/sausage/__init__.py @@ -1,33 +1,29 @@ -#!/usr/bin/python3 - from sys import version_info from sausage.readconf import ReadConf from sausage.appargs import AppArgs from sausage.esclient import ESClient from sausage.display import Display from sausage.debug import Debug from sausage.logging import setup_logging AppArgs() @Debug(timer=AppArgs.verbose) @Debug(prof=AppArgs.verbose) def main(): assert version_info >= (3, 8) ReadConf() logger = setup_logging(ReadConf.debug, AppArgs.verbose) logger.debug("START") client = ESClient() client.set_result() display = Display(client.result, client.total) display.get_motd(carbon=AppArgs.response["carbon"]) logger.debug("END") -if __name__ == "__main__": - main() diff --git a/src/sausage/__main__.py b/src/sausage/__main__.py new file mode 100644 index 0000000..2794ade --- /dev/null +++ b/src/sausage/__main__.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +from sausage import main + +if __name__ == "__main__": + main() diff --git a/sausage/appargs.py b/src/sausage/appargs.py similarity index 100% rename from sausage/appargs.py rename to src/sausage/appargs.py diff --git a/sausage/debug.py b/src/sausage/debug.py similarity index 100% rename from sausage/debug.py rename to src/sausage/debug.py diff --git a/sausage/display.py b/src/sausage/display.py similarity index 100% rename from sausage/display.py rename to src/sausage/display.py diff --git a/sausage/esclient.py b/src/sausage/esclient.py similarity index 100% rename from sausage/esclient.py rename to src/sausage/esclient.py diff --git a/sausage/esquery.py b/src/sausage/esquery.py similarity index 100% rename from sausage/esquery.py rename to src/sausage/esquery.py diff --git a/sausage/functions.py b/src/sausage/functions.py similarity index 100% rename from sausage/functions.py rename to src/sausage/functions.py diff --git a/sausage/logging.py b/src/sausage/logging.py similarity index 100% rename from sausage/logging.py rename to src/sausage/logging.py diff --git a/sausage/readconf.py b/src/sausage/readconf.py similarity index 100% rename from sausage/readconf.py rename to src/sausage/readconf.py