Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: build venv based python for el9 #76

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ build-packages: poetry-install ## build source package, wheel and srpm

.PHONY: rebuild-packages
rebuild-packages: ## build binary rpms
@docker run -v ./:/source rockylinux:9 /source/tools/venv-rpm
@docker run -v ./:/source fedora:39 /source/tools/rebuild-rpm
@docker run -v ./:/source fedora:40 /source/tools/rebuild-rpm
#@docker run -v ./:/source rockylinux:9 /source/tools/rebuild-rpm
73 changes: 73 additions & 0 deletions tools/venv-rpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
import os
import shutil
from datetime import datetime
from pathlib import Path
from subprocess import PIPE, run

SPEC = """
Name: python3-pyaptly
Version: 2.0.0^{revision}
Release: 1%{{?dist}}
Summary: Automates the creation and managment of aptly mirrors and snapshots based on yml input files
License: AGPL-3.0-or-later
BuildArch: noarch
Requires: python3.11

%description
Automates the creation and managment of aptly mirrors and snapshots based on yml input files


%install
rm -rf /opt/pyaptly
python3.11 -m venv /opt/pyaptly
(source /opt/pyaptly/bin/activate
pip install -r /root/requirements.txt)
mkdir -p ${{RPM_BUILD_ROOT}}/opt
cp -r --preserve=links /opt/pyaptly/ ${{RPM_BUILD_ROOT}}/opt/pyaptly/
mkdir -p ${{RPM_BUILD_ROOT}}/usr/bin
ln -s /opt/pyaptly/bin/pyaptly ${{RPM_BUILD_ROOT}}/usr/bin/pyaptly
rm -rf /opt/pyaptly

%files
/usr/bin/pyaptly
/opt/pyaptly

%changelog
* {date} Package Robot <[email protected]> - 2.0.0^alpha
- Automatic build of revision {revision}
"""


def main():
os.chdir("/source")
macros = Path("/root/.rpmmacros")
with macros.open("w", encoding="UTF-8") as f:
f.write("%_binaries_in_noarch_packages_terminate_build 0")
f.write("\n")
run(["dnf", "install", "-y", "rpm-build", "python3.11", "git"], check=True)
date = datetime.now().strftime("%a %b %d %Y")
build_id = run(
["git", "rev-parse", "--short", "HEAD"],
stdout=PIPE,
check=True,
encoding="UTF-8",
).stdout.strip()
dist = Path("/source/dist")
package = str(list(dist.glob("pyaptly-*-py3-none-any.whl"))[0])
req = Path("/root/requirements.txt")
with req.open("w", encoding="UTF-8") as f:
f.write(package)
f.write("\n")
spec = Path("/root/venv.spec")
with spec.open("w", encoding="UTF-8") as f:
f.write(SPEC.format(revision=build_id, date=date))
shutil.rmtree("/root/rpmbuild", ignore_errors=True)
run(["rpmbuild", "--bb", spec], check=True)
rpms = Path("/root/rpmbuild/RPMS/noarch")
file = Path(list(rpms.glob("python3-pyaptly-*.noarch.rpm"))[0])
shutil.copy2(file, dist)


if __name__ == "__main__":
main()