From 3c19420b3e7786ba87dad15df2cad9de73ef56d3 Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Wed, 17 Jul 2019 15:53:21 +0200 Subject: [PATCH] introduce spec file and related build scripts The repository now contains a Vagrantfile for running the testing script against an RPM package created locally using `make rpm`. To run this test use `make vagrant-test`. setup.py was also modified to adhere to packaging guidelines and not to install system-level executables. The lincense is now included in the Python package using the MANIFEST.in file. --- .gitignore | 3 ++ MANIFEST.in | 1 + Makefile | 39 +++++++++++++++++++++++++ osbuild.spec | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 6 +--- test/Makefile | 12 ++++---- test/Vagrantfile | 15 ++++++++++ 7 files changed, 141 insertions(+), 11 deletions(-) create mode 100644 .gitignore create mode 100644 MANIFEST.in create mode 100644 Makefile create mode 100644 osbuild.spec create mode 100644 test/Vagrantfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..5d953a8d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.rpm +*.tar.gz +*.egg-info diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..1aba38f6 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include LICENSE diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..92b056b8 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +PACKAGE_NAME=osbuild +VERSION=1 + +sdist: + python3 setup.py sdist + find `pwd`/dist -name '*.tar.gz' -printf '%f\n' -exec mv {} . \; + +tarball: + git archive --prefix=osbuild-$(VERSION)/ --format=tar.gz HEAD > $(VERSION).tar.gz + +srpm: $(PACKAGE_NAME).spec tarball + /usr/bin/rpmbuild -bs \ + --define "_sourcedir $(CURDIR)" \ + --define "_srcrpmdir $(CURDIR)" \ + $(PACKAGE_NAME).spec + +rpm: $(PACKAGE_NAME).spec tarball + mkdir -p "`pwd`/output" + mkdir -p "`pwd`/rpmbuild" + /usr/bin/rpmbuild -bb \ + --define "_sourcedir `pwd`" \ + --define "_specdir `pwd`" \ + --define "_builddir `pwd`/rpmbuild" \ + --define "_srcrpmdir `pwd`" \ + --define "_rpmdir `pwd`/output" \ + --define "_buildrootdir `pwd`/build" \ + $(PACKAGE_NAME).spec + find `pwd`/output -name '*.rpm' -printf '%f\n' -exec mv {} . \; + rm -r "`pwd`/rpmbuild" + rm -r "`pwd`/output" + rm -r "`pwd`/build" + +copy-rpms-to-test: + cp *.rpm test/ + +vagrant-test: rpm copy-rpms-to-test + - $(MAKE) -C test up + - $(MAKE) -C test install-deps + $(MAKE) -C test run-tests-remotely diff --git a/osbuild.spec b/osbuild.spec new file mode 100644 index 00000000..eef52553 --- /dev/null +++ b/osbuild.spec @@ -0,0 +1,76 @@ +%global pypi_name osbuild + +Name: %{pypi_name} +Version: 1 +Release: 1%{?dist} +License: ASL 2.0 + +URL: https://github.com/larskarlitski/osbuild + +Source0: https://github.com/larskarlitski/%{pypi_name}/archive/%{version}.tar.gz +BuildArch: noarch +Summary: A build system for OS images + +BuildRequires: python3-devel + +Requires: bash +Requires: coreutils +Requires: dnf +Requires: e2fsprogs +Requires: glibc +Requires: policycoreutils +Requires: qemu-img +Requires: systemd +Requires: systemd-container +Requires: tar +Requires: util-linux +Requires: python3-%{pypi_name} + +%{?python_enable_dependency_generator} + +%description +A build system for OS images + +%package -n python3-%{pypi_name} +Summary: %{summary} +%{?python_provide:%python_provide python3-%{pypi_name}} + +%description -n python3-%{pypi_name} +A build system for OS images + +%prep +%autosetup -n %{name}-%{version} + +%build +%py3_build + +%install +%py3_install + +mkdir -p %{buildroot}%{_libexecdir}/%{pypi_name}/stages +install -p -m 0755 stages/* %{buildroot}%{_libexecdir}/%{pypi_name}/stages/ + +mkdir -p %{buildroot}%{_libexecdir}/%{pypi_name}/assemblers +install -p -m 0755 assemblers/* %{buildroot}%{_libexecdir}/%{pypi_name}/assemblers/ + +install -p -m 0755 osbuild-run %{buildroot}%{_libexecdir}/%{pypi_name}/ + +%check +exit 0 +# We have some integration tests, but those require running a VM, so that would +# be an overkill for RPM check script. + +%files +%license LICENSE +%{_bindir}/osbuild +%{_libexecdir}/%{pypi_name} + +%files -n python3-%{pypi_name} +%license LICENSE +%doc README.md +%{python3_sitelib}/%{pypi_name}-*.egg-info/ +%{python3_sitelib}/%{pypi_name}/ + +%changelog +* Wed Jul 17 2019 Martin Sehnoutka - 1-1 +- Initial package diff --git a/setup.py b/setup.py index 603341cb..90953ec8 100644 --- a/setup.py +++ b/setup.py @@ -6,12 +6,8 @@ setuptools.setup( version="1", description="A build system for OS images", packages=["osbuild"], + license='Apache-2.0', entry_points={ "console_scripts": ["osbuild = osbuild.__main__:main"] }, - data_files=[ - ("/usr/lib/osbuild", ["osbuild-run"]), - ("/usr/lib/osbuild/stages", glob.glob("./stages/*")), - ("/usr/lib/osbuild/assemblers", glob.glob("./assemblers/*")) - ] ) diff --git a/test/Makefile b/test/Makefile index a7f928ec..73bdbe0d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,8 +1,8 @@ -base: - $(OSBUILD) --input $(BASE_INPUT) --output $(BASE_OUTPUT) 1-create-base.json +up: + vagrant up -web: - $(OSBUILD) --input $(BASE_OUTPUT) --output $(WEB_OUTPUT) 2-configure-web-server.json +install-deps: + vagrant provision -qcow2: - $(OSBUILD) --input $(WEB_OUTPUT) --output $(QCOW2_OUTPUT) 3-compose-qcow2.json \ No newline at end of file +run-tests-remotely: + vagrant ssh -c 'pushd /vagrant; sudo python3 run-tests.py' diff --git a/test/Vagrantfile b/test/Vagrantfile new file mode 100644 index 00000000..b9355285 --- /dev/null +++ b/test/Vagrantfile @@ -0,0 +1,15 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +$script = <<-SCRIPT +sudo dnf install qemu-system-x86 /vagrant/osbuild*.rpm -y +SCRIPT + +Vagrant.configure("2") do |config| + config.vm.box = "fedora/30-cloud-base" + config.vm.box_version = "30.20190425.0" + config.vm.provider "libvirt" do |v| + v.memory = 4096 + end + config.vm.provision "shell", inline: $script +end