Search code examples
dockercentosbinaryfilesrpmbuildrpm-spec

creating an RPM package from binary file doesn't package the files into an archive


I'm trying to create an RPM package from node project packaged into a binary file with pkg.
I've created an rpmbuild skeleton in /root/rpmbuild.
The binary package was copied into /root/rpmbuild/SOURCES. I've created a menlolab-runner.service file in /root/rpmbuild.

I'm skipping the %prep and %build sections in the .spec file. During the install section the binary files is copied to /usr/bin folder. In the %post section the service file is copied to /etc/systemd/system/

%define version %(cat package.json | jq -r '.version')
%define release 1
%define buildroot /root/rpmbuild/BUILDROOT/

Name: %{name}
Version: %{version}
Release: %{release}
Summary: menlolab-runner

Group: Installation Script
License: MIT
Source0: runner
AutoReqProv: no

%description
The agent deployed on private and public infrastructure to manage tasks.

%global debug_package %{nil}

%prep

%build

%pre
getent group menlolab-runner >/dev/null || groupadd -r menlolab-runner
getent passwd menlolab-runner >/dev/null || useradd -r -g menlolab-runner -G menlolab-runner -d / -s /sbin/nologin -c "menlolab-runner" menlolab-runner

%install
mkdir -p %{buildroot}%{_bindir}/
mkdir -p %{buildroot}%{_unitdir}

cp runner %{buildroot}%{_bindir}/menlolab-runner
cp /root/rpmbuild/menlolab-runner.service %{buildroot}%{_unitdir}

%post
systemctl enable %{_unitdir}/menlolab-runner.service
chmod ugo+x /usr/bin/menlolab-runner
mkdir -p '/etc/menlolab-runner/'
chown -R 'menlolab-runner:menlolab-runner' '/etc/menlolab-runner'
chmod 700 '/etc/menlolab-runner'
mkdir -p '/var/lib/menlolab-runner/'
chown -R 'menlolab-runner:menlolab-runner' '/var/lib/menlolab-runner/'
mkdir -p '/var/lib/menlolab-runner/jobs/'
chown -R 'menlolab-runner:menlolab-runner' '/var/lib/menlolab-runner/jobs/'
chmod 700 '/var/lib/menlolab-runner/jobs/'
mkdir -p '/var/log/menlolab-runner/'
chown -R 'menlolab-runner:menlolab-runner' '/var/log/menlolab-runner/'
mkdir -p '/var/cache/menlolab-runner/'
chown -R 'menlolab-runner:menlolab-runner' '/var/cache/menlolab-runner/'
groupadd docker
usermod -aG docker menlolab-runner

%clean
rm -rf %{buildroot}

%files
%{_bindir}/menlolab-runner
%{_unitdir}/menlolab-runner.service

%defattr(644, menlolab-runner, menlolab-runner, 755)

My issue is the fact that .rpm contains no files after executing rpmbuild -ba /path/to/spec/file.

I think it's because I have no entry in the %files section. I'm not sure what to put into this section. If I add the path to binary file there I receive the following error:

error: File not found: /root/rpmbuild/BUILDROOT/menlolab-runner-0.2.5a2-1.x86_64/root/rpmbuild/SOURCES/runner


Solution

  • In your %install section you must place files into $RPM_BUILD_ROOT, so something like:

    %install
    cp runner $RPM_BUILD_ROOT%{_bindir}/menlolab-runner
    

    Subsequently, the %files section should list the installed files, relative to the $RPM_BUILD_ROOT, e.g.:

    %files
    %{_bindir}/menlolab-runner