From 10ff2ca29786bf95571cd47febd43231264863f6 Mon Sep 17 00:00:00 2001 From: ge Date: Tue, 16 Jan 2024 22:26:59 +0300 Subject: [PATCH] add PKGBUILD, upd DEB builder --- .gitignore | 2 +- Makefile | 18 +++++++----- .../completion.bash | 0 packaging/Makefile | 24 --------------- packaging/archlinux/Dockerfile | 10 +++++++ packaging/archlinux/Makefile | 22 ++++++++++++++ packaging/archlinux/PKGBUILD | 16 ++++++++++ packaging/{ => debian}/Dockerfile | 0 packaging/debian/Makefile | 29 +++++++++++++++++++ packaging/{ => debian}/build.sh | 3 +- packaging/{ => debian}/files/control | 0 packaging/{ => debian}/files/copyright | 0 packaging/{ => debian}/files/docs | 0 packaging/{ => debian}/files/install | 0 packaging/{ => debian}/files/rules | 0 15 files changed, 91 insertions(+), 33 deletions(-) rename packaging/files/compute.bash-completion => extra/completion.bash (100%) delete mode 100644 packaging/Makefile create mode 100644 packaging/archlinux/Dockerfile create mode 100644 packaging/archlinux/Makefile create mode 100644 packaging/archlinux/PKGBUILD rename packaging/{ => debian}/Dockerfile (100%) create mode 100644 packaging/debian/Makefile rename packaging/{ => debian}/build.sh (84%) rename packaging/{ => debian}/files/control (100%) rename packaging/{ => debian}/files/copyright (100%) rename packaging/{ => debian}/files/docs (100%) rename packaging/{ => debian}/files/install (100%) rename packaging/{ => debian}/files/rules (100%) diff --git a/.gitignore b/.gitignore index eabf06c..9abb846 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ dist/ docs/build/ -packaging/build/ +packaging/*/build/ instance.yaml .ruff_cache/ __pycache__/ diff --git a/Makefile b/Makefile index 1dbea2c..245cb72 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ DOCS_BUILDDIR = docs/build .PHONY: docs -all: docs build-deb +all: docs build debian archlinux requirements.txt: poetry export -f requirements.txt -o requirements.txt @@ -13,8 +13,11 @@ requirements.txt: build: version format lint poetry build -build-deb: build - cd packaging && $(MAKE) +debian: + cd packaging/debian && $(MAKE) + +archlinux: + cd packaging/archlinux && $(MAKE) version: VERSION=$$(awk '/^version/{print $$3}' pyproject.toml); \ @@ -42,11 +45,12 @@ clean: [ -d $(DISTDIR) ] && rm -rf $(DISTDIR) || true [ -d $(DOCS_BUILDDIR) ] && rm -rf $(DOCS_BUILDDIR) || true find . -type d -name __pycache__ -exec rm -rf {} \; > /dev/null 2>&1 || true - cd packaging && $(MAKE) clean + cd packaging/debian && $(MAKE) clean + cd packaging/archlinux && $(MAKE) clean -test-build: build-deb - scp packaging/build/compute*.deb vm:~ +test-build: build debian + scp packaging/debian/build/compute*.deb vm:~ -upload-docs: docs-versions +upload-docs: ssh root@hitomi 'rm -rf /srv/http/nixhacks.net/hstack/compute/*' scp -r $(DOCS_BUILDDIR)/* root@hitomi:/srv/http/nixhacks.net/hstack/compute/ diff --git a/packaging/files/compute.bash-completion b/extra/completion.bash similarity index 100% rename from packaging/files/compute.bash-completion rename to extra/completion.bash diff --git a/packaging/Makefile b/packaging/Makefile deleted file mode 100644 index d92de39..0000000 --- a/packaging/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -DOCKER_CMD ?= docker -DOCKER_IMG = pybuilder:bookworm -DEBBUILDDIR = build - -all: docker-build build - -clean: - test -d $(DEBBUILDDIR) && rm -rf $(DEBBUILDDIR) || true - -docker-build: - $(DOCKER_CMD) build -f Dockerfile -t $(DOCKER_IMG) . - -build: clean - mkdir -p $(DEBBUILDDIR) - cp -v ../dist/compute-*[.tar.gz] $(DEBBUILDDIR)/ - cp -r ../docs $(DEBBUILDDIR)/ - if [ -f build.sh.bak ]; then mv build.sh{.bak,}; fi - cp build.sh{,.bak} - awk '/authors/{gsub(/[\[\]]/,"");print $$3" "$$4}' ../pyproject.toml \ - | sed "s/['<>]//g" \ - | tr ' ' '\n' \ - | xargs -I {} sed "0,/%placeholder%/s//{}/" -i build.sh - $(DOCKER_CMD) run --rm -i -v $$PWD:/mnt $(DOCKER_IMG) bash < build.sh - mv build.sh{.bak,} diff --git a/packaging/archlinux/Dockerfile b/packaging/archlinux/Dockerfile new file mode 100644 index 0000000..d29ecee --- /dev/null +++ b/packaging/archlinux/Dockerfile @@ -0,0 +1,10 @@ +FROM archlinux:latest +WORKDIR /mnt +RUN chown 1000:1000 /mnt; \ + pacman -Sy --noconfirm \ + fakeroot \ + binutils \ + python \ + python-pip; \ + echo "alias ll='ls -alFh'" >> /etc/bash.bashrc +USER 1000:1000 diff --git a/packaging/archlinux/Makefile b/packaging/archlinux/Makefile new file mode 100644 index 0000000..e66e270 --- /dev/null +++ b/packaging/archlinux/Makefile @@ -0,0 +1,22 @@ +DOCKER_CMD ?= docker +DOCKER_IMG = computebuilder:archlinux +BUILDDIR = build + +all: docker-build build + +clean: + test -d $(BUILDDIR) && rm -rf $(BUILDDIR) || true + +docker-build: + $(DOCKER_CMD) build -f Dockerfile -t $(DOCKER_IMG) . + +build: clean + mkdir -p $(BUILDDIR) + VERSION=$$(awk '/^version/{print $$3}' ../../pyproject.toml | sed s'/-/\./'); \ + sed "s/pkgver=.*/pkgver=$$VERSION/" PKGBUILD > $(BUILDDIR)/PKGBUILD + cp -v ../../dist/compute-*[.tar.gz] $(BUILDDIR)/ + cp ../../extra/completion.bash $(BUILDDIR)/ + $(DOCKER_CMD) run --rm -i -v $$PWD/$(BUILDDIR):/mnt --ulimit "nofile=1024:1048576" \ + $(DOCKER_IMG) makepkg --nodeps --clean + # Remove unwanted files from build dir + rm $(BUILDDIR)/compute*.tar.gz $(BUILDDIR)/PKGBUILD diff --git a/packaging/archlinux/PKGBUILD b/packaging/archlinux/PKGBUILD new file mode 100644 index 0000000..a546db5 --- /dev/null +++ b/packaging/archlinux/PKGBUILD @@ -0,0 +1,16 @@ +pkgname=compute +pkgver='0.1.0-dev4' +pkgrel=1 +pkgdesc='Compute instances management library' +arch=(any) +url=https://get.lulzette.ru/hstack/compute +license=('GPL-3-or-later') +makedepends=(python python-pip) +depends=(python libvirt libvirt-python qemu-base qemu-system-x86 qemu-img dnsmasq iptables-nft) +provides=(compute) +conflicts=() + +package() { + pip install --no-cache-dir --no-deps --root $pkgdir ../$pkgname-*.tar.gz + install -Dm644 ../completion.bash $pkgdir/usr/share/bash-completion/completions/compute +} diff --git a/packaging/Dockerfile b/packaging/debian/Dockerfile similarity index 100% rename from packaging/Dockerfile rename to packaging/debian/Dockerfile diff --git a/packaging/debian/Makefile b/packaging/debian/Makefile new file mode 100644 index 0000000..b010351 --- /dev/null +++ b/packaging/debian/Makefile @@ -0,0 +1,29 @@ +DOCKER_CMD ?= docker +DOCKER_IMG = computebuilder:debian-bookworm +BUILDDIR = build +KEEP_BUILDFILES ?= + +all: docker-build build + +clean: + test -d $(BUILDDIR) && rm -rf $(BUILDDIR) || true + +docker-build: + $(DOCKER_CMD) build -f Dockerfile -t $(DOCKER_IMG) . + +build: clean + mkdir -p $(BUILDDIR) + cp -v ../../dist/compute-*[.tar.gz] $(BUILDDIR)/ + cp -r ../../docs $(BUILDDIR)/ + cp ../../extra/completion.bash $(BUILDDIR)/compute.bash-completion + if [ -f build.sh.bak ]; then mv build.sh{.bak,}; fi + cp build.sh{,.bak} + awk '/authors/{gsub(/[\[\]]/,"");print $$3" "$$4}' ../pyproject.toml \ + | sed "s/['<>]//g" \ + | tr ' ' '\n' \ + | xargs -I {} sed "0,/%placeholder%/s//{}/" -i build.sh + $(DOCKER_CMD) run --rm -i -v $$PWD:/mnt $(DOCKER_IMG) bash < build.sh + mv build.sh{.bak,} + # Remove unwanted files from build dir + find $(BUILDDIR) -mindepth 1 -type d -exec rm -rf {} + + [ -z $(KEEP_BUILDFILES) ] && find $(BUILDDIR) ! -name '*.deb' -type f -exec rm -f {} + || true diff --git a/packaging/build.sh b/packaging/debian/build.sh similarity index 84% rename from packaging/build.sh rename to packaging/debian/build.sh index 50af8f0..ca2d504 100644 --- a/packaging/build.sh +++ b/packaging/debian/build.sh @@ -11,5 +11,6 @@ sed -e "s%\.\./\.\.%$PWD%" -i ../docs/source/conf.py dh_make --copyright gpl3 --yes --python --file ../compute-*[.tar.gz] rm debian/*.ex debian/README.{Debian,source} debian/*.docs sed -e 's/\* Initial release.*/\* This is the development build, see commits in upstream repo for info./' -i debian/changelog -cp -v ../../files/{control,rules,copyright,docs,compute.bash-completion,install} debian/ +cp -v ../../files/{control,rules,copyright,docs,install} debian/ +mv ../compute.bash-completion debian/ dpkg-buildpackage -us -uc diff --git a/packaging/files/control b/packaging/debian/files/control similarity index 100% rename from packaging/files/control rename to packaging/debian/files/control diff --git a/packaging/files/copyright b/packaging/debian/files/copyright similarity index 100% rename from packaging/files/copyright rename to packaging/debian/files/copyright diff --git a/packaging/files/docs b/packaging/debian/files/docs similarity index 100% rename from packaging/files/docs rename to packaging/debian/files/docs diff --git a/packaging/files/install b/packaging/debian/files/install similarity index 100% rename from packaging/files/install rename to packaging/debian/files/install diff --git a/packaging/files/rules b/packaging/debian/files/rules similarity index 100% rename from packaging/files/rules rename to packaging/debian/files/rules