%global domain          github.com
%global org             kata-containers
%global repo            runtime
%global download        %{domain}/%{org}/%{repo}
%global importname      %{download}
%global qemu            qemu-kvm

Name:      kata-%{repo}
Version:   1.8.0
Release:   1%{?dist}
Url:       https://%{download}
Source0:   https://%{download}/archive/%{version}/%{name}-%{version}.tar.gz
Summary:   Kata runtime to run containers in virtual machines
Group:     Development/Tools
License:   ASL 2.0

# F31: Add BuildRequires: go-rpm-macros
BuildRequires: %{?suse_version:go1.12} %{!?suse_version:golang}

Requires: qemu-kvm
Requires: kata-containers-image = %{version}
Requires: kata-linux-container = %{version}
Requires: kata-proxy = %{version}
Requires: kata-shim = %{version}
Requires: kata-ksm-throttler = %{version}

%description
The runtime for the Kata Containers project.

Kata Containers is an open source project and community working to
build a standard implementation of lightweight Virtual Machines (VMs)
that feel and perform like containers, but provide the workload
isolation and security advantages of VMs.

# F31: Use %gopkg

%prep
# Future: Use %goprep for F31
%autosetup -n %{repo}-%{version}

%build
# Adjust for go build requirements
# Future: Use %gopkginstall
# export GOROOT="$(pwd)/go"
export PATH=$PATH:"$(pwd)/go/bin"
export GOPATH="$(pwd)/go"

mkdir -p go/src/%{domain}/%{org}
ln -s $(pwd)/../%{repo}-%{version} go/src/%{importname}
cd go/src/%{importname}
make \
    QEMUPATH=%{_bindir}/%{qemu} \
    not_check_version=certainly_not

%check
export http_proxy=http://127.0.0.1:9/
export https_proxy=http://127.0.0.1:9/
export no_proxy=localhost

%install

export GOPATH=$(pwd)/go
export PATH=$PATH:$GOPATH/bin

cd go/src/%{importname}
make \
    DESTTARGET=%{buildroot}%{_bindir}/kata-runtime \
    DESTCONFIG=%{buildroot}%{_datadir}/defaults/kata-containers/configuration.toml \
    SCRIPTS_DIR=%{_bindir} \
    QEMUPATH=%{_bindir}/%{qemu} \
    DESTDIR=%{buildroot} \
    PREFIX=/usr \
    not_check_version=still_not_checking \
    install
sed -i -e '/^initrd =/d' %{buildroot}/usr/share/defaults/kata-containers/configuration.toml

%files
%defattr(-,root,root,-)
%license LICENSE
%{_bindir}/kata-runtime
%{_bindir}/containerd-shim-kata-v2
%dir %{_libexecdir}/kata-containers
%{_libexecdir}/kata-containers/kata-netmon
%{_bindir}/kata-collect-data.sh
%dir %{_datadir}/defaults/kata-containers
%{_datadir}/defaults/kata-containers/configuration*.toml
%{_datadir}/bash-completion/completions/kata-runtime

%changelog
* Tue Jul 30 2019 Christophe de Dinechin <dinechin@redhat.com> - 1.8.0-1
- Update to 1.8.0 release

* Fri Jul 12 2019 Christophe de Dinechin <dinechin@redhat.com> - 1.7.3-5
- Update to 1.7.3 release, cleanup spec file