From 13d231a62cec9bfb56ccd0764edbf7a43f7748e8 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Wed, 9 Jul 2025 14:11:46 +0200 Subject: [PATCH] feat(package): Add RPM, deb, pacman and tar packages and manpage Build package using fpm. As I don't want ruby/gem in my computer, the build system creates an OCI image with Podman (at this time), and generate dist pacakges. To enhance the packages, a manpage is now generated from the documentation. --- .gitignore | 3 ++ Makefile | 55 ++++++++++++++++++++++++++++++++++++ doc/manpage_requirements.txt | 2 ++ doc/mkdocs.yml | 10 +++++++ doc/preprocess.py | 22 +++++++++++++++ packaging/description | 4 +++ packaging/oci/Containerfile | 15 ++++++++++ 7 files changed, 111 insertions(+) create mode 100644 doc/manpage_requirements.txt create mode 100644 doc/preprocess.py create mode 100644 packaging/description create mode 100644 packaging/oci/Containerfile diff --git a/.gitignore b/.gitignore index 8c1ff8b..6cbef35 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ cover* # nsis nsis/*.dll nsis/*.exe + +doc/share +__pycache__ diff --git a/Makefile b/Makefile index 8c785c7..18f8f97 100644 --- a/Makefile +++ b/Makefile @@ -220,6 +220,19 @@ doc: # generate the labels doc and code doc $(MAKE) __label_doc +manpage: + @echo "=> Generating manpage from documentation" + @cd doc && \ + [ -d venv ] || python -m venv venv; \ + source venv/bin/activate && \ + echo "==> Installing requirements in the virtual env..." && \ + pip install -qq -r requirements.txt && \ + pip install -qq -r manpage_requirements.txt && \ + echo "==> Generating manpage..." && \ + MANPAGE=true mkdocs build && \ + rm -rf site && + echo "==> Manpage generated in doc/share/man/man1/katenary.1" + install-gomarkdoc: go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest @@ -284,3 +297,45 @@ cover: dist-clean: rm -rf dist rm -f katenary + + +#FPM_OPTS=--name katenary \ +# --description "$(shell cat packaging/description)" \ +# --version $(VERSION) \ +# --url https://katenary.org \ +# --vendor "Katenary Project" \ +# --maintainer "Patrice Ferlet " \ +# --license "MIT" \ +# katenary-linux-amd64=/usr/local/bin/katenary +#packages: +# podman build -t packaging:fedora ./packaging/oci +# podman run -it --rm -w /opt -v ./dist:/opt:z --userns keep-id:uid=999,gid=999 packaging:fedora \ +# fpm -s dir -t rpm --rpm-summary="$(shell head -n1 packaging/description)" -f $(FPM_OPTS) +# podman run -it --rm -w /opt -v ./dist:/opt:z --userns keep-id:uid=999,gid=999 packaging:fedora \ +# fpm -s dir -t deb -f $(FPM_OPTS) + +# print packaging/description and replace newlines with explicit \n +DESCRIPTION := $(shell cat packaging/description | sed ':a;N;$$!ba;s/\n/\\n/g') + + +FPM_OCI_OPTS=-w /opt/katenary/dist \ + -v ./:/opt/katenary:z \ + --userns keep-id:uid=999,gid=999 packaging:fedora +FPM_OPTS=--name katenary \ + --version $(VERSION) \ + --url https://katenary.org \ + --vendor "Katenary Project" \ + --maintainer "Patrice Ferlet " \ + --license "MIT" \ + --description="$$(printf "$(DESCRIPTION)" | fold -s)" \ + ./katenary-linux-amd64=/usr/local/bin/katenary \ + ../doc/share/man/man1/katenary.1=/usr/local/share/man/man1/katenary.1 \ + ../LICENSE=/usr/local/share/doc/katenary/LICENSE \ + ../README.md=/usr/local/share/doc/katenary/README.md +packages: manpage + @podman build -t packaging:fedora ./packaging/oci 1>/dev/null + @for target in rpm deb pacman tar; do \ + echo "==> Building $$target package..."; \ + podman run $(FPM_OCI_OPTS) fpm -s dir -t $$target -f $(FPM_OPTS); \ + done + mv dist/katenary.tar dist/katenary-$(VERSION).tar diff --git a/doc/manpage_requirements.txt b/doc/manpage_requirements.txt new file mode 100644 index 0000000..9072507 --- /dev/null +++ b/doc/manpage_requirements.txt @@ -0,0 +1,2 @@ +beautifulsoup4==4.* +mkdocs-manpage[preprocess] diff --git a/doc/mkdocs.yml b/doc/mkdocs.yml index 80925d3..64196d5 100644 --- a/doc/mkdocs.yml +++ b/doc/mkdocs.yml @@ -3,6 +3,16 @@ docs_dir: ./docs plugins: - search - inline-svg + - manpage: + enabled: !ENV [MANPAGE, false] + preprocess: preprocess.py + pages: + - title: Katenary + header: Katenary helm chart generator + output: share/man/man1/katenary.1 + inputs: + - usage.md + - labels.md theme: name: material custom_dir: overrides diff --git a/doc/preprocess.py b/doc/preprocess.py new file mode 100644 index 0000000..d691cc1 --- /dev/null +++ b/doc/preprocess.py @@ -0,0 +1,22 @@ +"""Called by mkdocs to preprocess files and build manpages""" + +from bs4 import BeautifulSoup, Tag + + +def to_remove(tag: Tag) -> bool: + """Removes images, SVGs, links containing images or SVGs, and permalinks from the BeautifulSoup object.""" + if tag.name in {"img", "svg"}: + return True + # remove links containing images or SVGs + if tag.name == "a" and tag.img and to_remove(tag.img): + return True + # remove permalinks + if tag.name == "a" and "headerlink" in tag.get("class", ()): + return True + return False + + +def preprocess(soup: BeautifulSoup, output: str) -> None: + """Preprocess the BeautifulSoup object to remove unwanted elements.""" + for element in soup.find_all(to_remove): + element.decompose() diff --git a/packaging/description b/packaging/description new file mode 100644 index 0000000..63c1b66 --- /dev/null +++ b/packaging/description @@ -0,0 +1,4 @@ +Katenary transforms docker/podman compose files to Helm Charts. +It harnesses the labels from your "compose" file to craft complete Helm Charts effortlessly, saving you time and energy. +- Simple automated CLI: Katenary handles the grunt work, generating everything needed for seamless service binding and Helm Chart creation. +- Effortless Efficiency: You only need to add labels when it's necessary to precise things. Then call katenary convert and let the magic happen diff --git a/packaging/oci/Containerfile b/packaging/oci/Containerfile new file mode 100644 index 0000000..7179620 --- /dev/null +++ b/packaging/oci/Containerfile @@ -0,0 +1,15 @@ +FROM registry.fedoraproject.org/fedora:42 +RUN set -eux; \ + microdnf -y install \ + rubygems rpmbuild bsdtar + +RUN useradd -m -r -d /home/builder -s /bin/bash builder; \ + chown builder:builder /home/builder + +USER builder +ENV PATH="/home/builder/bin:${PATH}" +WORKDIR /home/builder +RUN gem install fpm + + +