Mock failing to build package in docker (gitlab-runner)

I’m a newbee and i’m trying to build rpm packages using mock and gitlab CI/CD.

Mock

I use the standard configuration file (unchanged) centos-stream+epel-9-x86_64in /etc/mock/ with the following command to build source rpm inside the gitlab runner container.

sudo mock -r centos-stream+epel-9-x86_64 --rebuild /home/builder/rpmbuild/*src.rpm --resultdir=output

I get the following error from the pipeline.

ERROR: Exception(/home/builder/rpmbuild/package.src.rpm) Config(centos-stream+epel-9-x86_64) 1 minutes 40 seconds
INFO: Results and/or logs in: output
ERROR: Command failed: 
 # bash --login -c /usr/bin/rpmbuild -bb --noclean --target x86_64 --nodeps /builddir/build/SPECS/package.spec

Any help will be much appreciated.

Thanks.

1 Like

Hi @nassor , welcome to the community.

Can you please check the logs in output? They’ll note exactly where and why the build failed.

Hi @ankursinha, Thanks for the reply and the warm welcome to the community.

The build.log shows the output below. But i fail to understand why the file is not found. Is it necessay to explicity mention it in the spec file to install these files in the chroot environment? - But if this is the workaround, wouldn’t rpmbuild tool be enough for this since i thought maybe i could automate the whole building process using mock?

It would be great if someone can point me in the right direction, Thanks.

Mock Version: 3.1
Mock Version: 3.1
Mock Version: 3.1
Mock Version: 3.1
ENTER ['do_with_status'](['bash', '--login', '-c', '/usr/bin/rpmbuild -bs --noclean --target x86_64 --nodeps /builddir/build/SPECS/package.spec'], chrootPath='/var/lib/mock/centos-stream+epel-9-x86_64/root'env={'TERM': 'vt100', 'SHELL': '/bin/bash', 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PROMPT_COMMAND': 'printf "\\033]0;<mock-chroot>\\007"', 'PS1': '<mock-chroot> \\s-\\v\\$ ', 'LANG': 'C.UTF-8'}shell=Falselogger=<mockbuild.trace_decorator.getLog object at 0x7f02f585e400>timeout=0uid=1000gid=135user='mockbuild'nspawn_args=[]unshare_net=TrueprintOutput=True)
Executing command: ['bash', '--login', '-c', '/usr/bin/rpmbuild -bs --noclean --target x86_64 --nodeps /builddir/build/SPECS/package.spec'] with env {'TERM': 'vt100', 'SHELL': '/bin/bash', 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PROMPT_COMMAND': 'printf "\\033]0;<mock-chroot>\\007"', 'PS1': '<mock-chroot> \\s-\\v\\$ ', 'LANG': 'C.UTF-8'} and shell False
Building target platforms: x86_64
Building for target x86_64
setting SOURCE_DATE_EPOCH=1567123200
Wrote: /builddir/build/SRPMS/package-1.0.8-0.src.rpm
Child return code was: 0
ENTER ['do_with_status'](['bash', '--login', '-c', '/usr/bin/rpmbuild -bb --noclean --target x86_64 --nodeps /builddir/build/SPECS/package.spec'], chrootPath='/var/lib/mock/centos-stream+epel-9-x86_64/root'env={'TERM': 'vt100', 'SHELL': '/bin/bash', 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PROMPT_COMMAND': 'printf "\\033]0;<mock-chroot>\\007"', 'PS1': '<mock-chroot> \\s-\\v\\$ ', 'LANG': 'C.UTF-8'}shell=Falselogger=<mockbuild.trace_decorator.getLog object at 0x7f02f585e400>timeout=0uid=1000gid=135user='mockbuild'nspawn_args=[]unshare_net=TrueprintOutput=True)
Executing command: ['bash', '--login', '-c', '/usr/bin/rpmbuild -bb --noclean --target x86_64 --nodeps /builddir/build/SPECS/package.spec'] with env {'TERM': 'vt100', 'SHELL': '/bin/bash', 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PROMPT_COMMAND': 'printf "\\033]0;<mock-chroot>\\007"', 'PS1': '<mock-chroot> \\s-\\v\\$ ', 'LANG': 'C.UTF-8'} and shell False
Building target platforms: x86_64
Building for target x86_64
setting SOURCE_DATE_EPOCH=1567123200
Processing files: package-1.0.8-0.noarch
RPM build errors:
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/hosts.0
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/hosts.128
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/profile.d/10-cardis.sh
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/profile.d/10-java.sh
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/logrotate.d/cardis
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/udev/rules.d/99-cardis.rules
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/bin/fuser
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/netcat
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/sd
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/kd
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/fuser
error: File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/lsof
error: Directory not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/var/log/cardis
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/hosts.0
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/hosts.128
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/profile.d/10-cardis.sh
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/profile.d/10-java.sh
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/logrotate.d/cardis
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/etc/udev/rules.d/99-cardis.rules
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/bin/fuser
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/netcat
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/sd
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/kd
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/fuser
    File not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/usr/bin/lsof
    Directory not found: /builddir/build/BUILDROOT/package-1.0.8-0.x86_64/var/log/cardis
Child return code was: 1
EXCEPTION: [Error()]
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/mockbuild/trace_decorator.py", line 93, in trace
    result = func(*args, **kw)
  File "/usr/lib/python3.9/site-packages/mockbuild/util.py", line 598, in do_with_status
    raise exception.Error("Command failed: \n # %s\n%s" % (command, output), child.returncode)
mockbuild.exception.Error: Command failed:
 # bash --login -c /usr/bin/rpmbuild -bb --noclean --target x86_64 --nodeps /builddir/build/SPECS/package.spec

Mock Version: 3.1
Mock Version: 3.1
@

1 Like

Yes, it is necessary to explicitly mention the files that need to be included in the %files section. One can use wildcards etc. to make it easier.

Can you share your spec please? it’s hard to note what exactly the issue is—have you installed files called fuser and netcat etc. to $RPM_BUILD_ROOT/%{_bindir}? They’re system files—do you really want to include these? Could you share some info on what you’re trying to do with the package please?

2 Likes

So in short summary, The package i’m trying to build prepares the production environment for all other custom packages that will be installed on the server. It ensures all the necessary packages and custom scripts are installed on the RHEL 9 server (before centos 7 server was used).

Below is the spec file that i’m building the package from. I have taken your suggestion into consideration and removed the system files that are actually being already installed in the base installation of rhel 9, except of lsof which i decided to install it in the kickstart file.

# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
%define packageName package
Name		: %{packageName}
Summary		: Environment for Production Server
Version		: 1.0.9
Release		: 0
BuildArch	: noarch
License		: (C) XXX
Group		: XXX-Base
URL		    : http://www.xxx.com/
Distribution	: RHEL
Vendor		: XXX
Packager	: magnas <magnas@domain.com>


# ------------------------------------------------------------------------------
# Requirements
# ------------------------------------------------------------------------------
Requires: bitstream-vera-fonts
Requires: vim-common


# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
%description
Environment for production Server

# ------------------------------------------------------------------------------
# After the installation
# ------------------------------------------------------------------------------
%post
test -f /usr/bin/uncompress && rm -f /usr/bin/uncompress
ln -sf /usr/bin/gunzip /usr/bin/uncompress
if [ $1 -eq 1 ]; then
	
	# set UID and GID start to 500 instead of 1000
	sed -i -e 's/UID_MIN                  1000/UID_MIN                   500/g' -e 's/GID_MIN                  1000/GID_MIN                   500/g' /etc/login.defs
	
	echo "$(date '+[%d/%b/%Y %H:%M]'): [RPM]: [INSTALL]: %{packageName }is installed" >> /var/log/cardis/install.log
else
	echo "$(date '+[%d/%b/%Y %H:%M]'): [RPM]: [UPDATE]: %{packageName} is updated" >> /var/log/cardis/install.log
fi


# ------------------------------------------------------------------------------
# After the installation
# ------------------------------------------------------------------------------
%postun	
if [ $1 -eq 0 ]; then
	rm -f '/etc/systemd/system/multi-user.target.wants/snmpd.service'
	echo "$(date '+[%d/%b/%Y %H:%M]'): [RPM]: [DELETE]: %{packageName} is removed" >> /var/log/cardis/install.log
fi


# ------------------------------------------------------------------------------
# Included files
# ------------------------------------------------------------------------------
%files
/etc/hosts.0
/etc/hosts.128
/etc/profile.d/10-cardis.sh
/etc/profile.d/10-java.sh
%attr(644, root, root) /etc/logrotate.d/cardis
/etc/udev/rules.d/99-cardis.rules
/usr/bin/sd
/usr/bin/kd
%dir /var/log/cardis

# ------------------------------------------------------------------------------
# Changelog
# LANG=C date +"%a %b %d %Y"
# ------------------------------------------------------------------------------
%changelog
* Tue Aug 30 2022 MAGNAS <magnas@domain.com> 1.0.9
- First preparations for RHEL 9

After that i have written a gitlab-ci.yml file to automate the build with a custom docker image as shown below:

Custom rpmbuild-image:

FROM dokken/centos-stream-9


RUN dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y
RUN dnf install -y gcc gcc-c++ \
                   libtool libtool-ltdl \
                   make cmake \
                   git \
                   pkgconfig \
                   sudo \
                   mock \
                   automake autoconf \
                   yum-utils rpm-build && \
    dnf clean all
    
RUN useradd builder -u 1000 -m -G mock,users,wheel && \
    echo "builder ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers && \
    echo "# macros"                      >  /home/builder/.rpmmacros && \
    echo "%_topdir    /home/builder/rpmbuild" >> /home/builder/.rpmmacros && \
    echo "%_sourcedir %{_topdir}"        >> /home/builder/.rpmmacros && \
    echo "%_builddir  %{_topdir}"        >> /home/builder/.rpmmacros && \
    echo "%_specdir   %{_topdir}"        >> /home/builder/.rpmmacros && \
    echo "%_rpmdir    %{_topdir}"        >> /home/builder/.rpmmacros && \
    echo "%_srcrpmdir %{_topdir}"        >> /home/builder/.rpmmacros && \
    mkdir -p /home/builder/rpmbuild && \
    chown -R builder /home/builder
    
USER builder
RUN mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

#CMD "mock -r centos-stream+epel-9-x86_64 --clean"
#CMD "mock -r centos-stream+epel-9-x86_64 --init"

ENV FLAVOR=rpmbuild OS=centos DIST=el7

After building the docker image, i push it into the container registry in Gitlab and use this custom image which has all necessary tools to build rpm packages.

Below is the .gitlab-ci.yml that is used to automate the whole build:

.gitlab-ci.yml

stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy

build-source:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    - tar -czvf files.tar.gz files/*
    - sudo mkdir -p output
    - sudo cp -r files.tar.gz /home/builder/rpmbuild/SOURCES/
    - sudo cp -r rpm/*spec /home/builder/rpmbuild/SPECS/
    - rpmbuild -bs /home/builder/rpmbuild/SPECS/*.spec 
    - sudo mock -r centos-stream+epel-9-x86_64 --no-cleanup-after --isolation=simple --chroot --rebuild /home/builder/rpmbuild/*src.rpm --resultdir=output
   
  artifacts:
    paths:
        - files.tar.gz
        - output/

But i still keep getting the same error.

I hope i explained the scenario a little more in details to help you understand what i’m trying to accomplish.

Thanks for the support.

It looks like you’re using a CentOS Stream 9 base and not a Fedora base for this and you’re building it for EL9. Unless you’re building this from Fedora, it seems offtopic here, save for the EPEL part of it.

1 Like

Hi @vwbusguy, the issue is not with which image i used, i could use Fedora also as the base image but still use the same tools and they should apparently work the same way.

I’m building a custom package which should be able to be installed in any EL 9 system. I’m stuck at using mock, which is a tool used and developed by Fedora and thats the reason i’m here seeking assistance.

Please correct me if i’m wrong and if possible enlighten me / point me in the right direction. Thanks

1 Like

Your spec isn’t installing these files, so rpmbuild (and so mock) cannot find them. Where are these supposed to come from?

1 Like