#
# spec file for package python-cloud_builder
#
# Copyright (c) 2021 SUSE Software Solutions Germany GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
#
# Please submit bugfixes or comments via:
#
#       https://github.com/OSInside/cloud-builder/issues
#

# If they aren't provided by a system installed macro, define them
%{!?_defaultdocdir: %global _defaultdocdir %{_datadir}/doc}
%{!?__python3: %global __python3 /usr/bin/python3}

%if %{undefined python3_sitelib}
%global python3_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
%endif

%if 0%{?el7}
%global python3_pkgversion 36
%else
%{!?python3_pkgversion:%global python3_pkgversion 3}
%endif

%if 0%{?debian} || 0%{?ubuntu}
%global is_deb 1
%global pygroup python
%global sysgroup admin
%global develsuffix dev
%else
%global pygroup Development/Languages/Python
%global sysgroup System/Management
%global develsuffix devel
%endif

Name:           python-cloud_builder
Version:        %%VERSION
Release:        0
Url:            https://github.com/OSInside/cloud-builder
Summary:        CB - Cloud Builder
License:        GPL-3.0-or-later
%if "%{_vendor}" == "debbuild"
# Needed to set Maintainer in output debs
Packager:       Marcus Schaefer <marcus.schaefer@gmail.com>
%endif
Group:          %{pygroup}
Source:         %{name}.tar.gz
Source1:        %{name}-rpmlintrc
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  python%{python3_pkgversion}-%{develsuffix}
BuildRequires:  python%{python3_pkgversion}-setuptools
BuildRequires:  systemd-rpm-macros
BuildRequires:  fdupes
BuildArch:      noarch

%description
Cloud Builder provides services to stand up a package building
cluster in cloud(VM) or container clusters.

# python3-cloud_builder
%package -n python%{python3_pkgversion}-cloud_builder
Summary:        CB - Cloud Builder
Group:          Development/Languages/Python
Requires:       python%{python3_pkgversion}-docopt
Requires:       python%{python3_pkgversion}-kiwi >= 9.21.21
Requires:       python%{python3_pkgversion}-requests
Requires:       python%{python3_pkgversion}-PyYAML
Requires:       python%{python3_pkgversion}-APScheduler
Requires:       python%{python3_pkgversion}-kafka-python
Requires:       python%{python3_pkgversion}-Cerberus
Requires:       python%{python3_pkgversion}-psutil
Requires:       python%{python3_pkgversion}-setuptools
Requires(preun):  systemd
Requires(postun): systemd
%description -n python%{python3_pkgversion}-cloud_builder
Cloud Builder provides services to stand up a package building
cluster in cloud(VM) or container clusters.

%prep
%setup -q -n cloud_builder-%{version}

%build
# Build Python 3 version
python3 setup.py build

%install
# Install Python 3 version
python3 setup.py install --prefix=%{_prefix} --root=%{buildroot} %{?is_deb:--install-layout=deb}

# Install license/docs
make buildroot=%{buildroot}/ docdir=%{_defaultdocdir}/ install

# Install systemd services
install -D -m 644 systemd/cb-fetch.service \
    %{buildroot}%{_unitdir}/cb-fetch.service

install -D -m 644 systemd/cb-fetch-once.service \
    %{buildroot}%{_unitdir}/cb-fetch-once.service

install -D -m 644 systemd/cb-scheduler.service \
    %{buildroot}%{_unitdir}/cb-scheduler.service

install -D -m 644 systemd/cb-info.service \
    %{buildroot}%{_unitdir}/cb-info.service

# Install config file
install -D -m 644 sysconfig/cloud_builder \
    %{buildroot}%{_sysconfdir}/cloud_builder

%files -n python%{python3_pkgversion}-cloud_builder
%dir %{_defaultdocdir}/python-cloud_builder
%{python3_sitelib}/cloud_builder*
%{_defaultdocdir}/python-cloud_builder/LICENSE
%{_defaultdocdir}/python-cloud_builder/README
%{_unitdir}/cb-fetch.service
%{_unitdir}/cb-fetch-once.service
%{_unitdir}/cb-scheduler.service
%{_unitdir}/cb-info.service
%config %{_sysconfdir}/cloud_builder
%{_bindir}/cb-fetch
%{_bindir}/cb-prepare
%{_bindir}/cb-run
%{_bindir}/cb-scheduler
%{_bindir}/cb-info

%changelog
