fix(rpm): copy files to BUILD dir instead of source archive

Simplified rpmbuild process:
- Copy files directly to BUILD directory (no tar archive)
- Use --noclean flag to preserve BUILD contents
- Use %{_builddir} macro in spec file instead of %{_sourcedir}

This avoids the complexity of source archive creation/extraction
and fixes the 'No such file or directory' error.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
toto
2026-03-03 22:26:00 +00:00
parent 379b310381
commit af62c43465
2 changed files with 16 additions and 14 deletions

View File

@ -32,18 +32,18 @@ mkdir -p /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
# Copy spec file # Copy spec file
cp /build/packaging/rpm/logcorrelator.spec /root/rpmbuild/SPECS/ cp /build/packaging/rpm/logcorrelator.spec /root/rpmbuild/SPECS/
# Create source archive (required by rpmbuild) # Copy files directly to BUILD directory (no archive needed)
# Archive contains the pre-built binary and all config files # This is simpler than creating/extracting a source archive
tar -czf /root/rpmbuild/SOURCES/logcorrelator-${VERSION}.tar.gz \ cp -r /tmp/pkgroot/* /root/rpmbuild/BUILD/
-C /tmp/pkgroot \
usr etc var
# Build RPM using rpmbuild # Build RPM using rpmbuild
# Use --noclean to keep BUILD directory contents
rpmbuild -bb /root/rpmbuild/SPECS/logcorrelator.spec \ rpmbuild -bb /root/rpmbuild/SPECS/logcorrelator.spec \
--define "version ${VERSION}" \ --define "version ${VERSION}" \
--define "dist .${DIST_NAME}" \ --define "dist .${DIST_NAME}" \
--define "_topdir /root/rpmbuild" \ --define "_topdir /root/rpmbuild" \
--define "_rpmdir /packages/rpm/${DIST_NAME}" --define "_rpmdir /packages/rpm/${DIST_NAME}" \
--noclean
# Ensure output directory exists and copy RPM # Ensure output directory exists and copy RPM
mkdir -p /packages/rpm/${DIST_NAME} mkdir -p /packages/rpm/${DIST_NAME}

View File

@ -32,8 +32,10 @@ Notes de sécurité :
- /var/run/logcorrelator est en 755 pour permettre la création de sockets - /var/run/logcorrelator est en 755 pour permettre la création de sockets
%prep %prep
# No source extraction needed - binary is pre-built # Files are already in BUILD directory (copied by build-rpm.sh)
# Files are already in the source archive # No extraction needed
echo "Files available in BUILD directory:"
ls -la %{_builddir}/
%install %install
# Create directory structure in buildroot # Create directory structure in buildroot
@ -45,18 +47,18 @@ mkdir -p %{buildroot}/var/lib/logcorrelator
mkdir -p %{buildroot}/etc/systemd/system mkdir -p %{buildroot}/etc/systemd/system
mkdir -p %{buildroot}/etc/logrotate.d mkdir -p %{buildroot}/etc/logrotate.d
# Install binary (from source archive extracted in SOURCES) # Install binary (from BUILD directory)
install -m 0755 %{_sourcedir}/usr/bin/logcorrelator %{buildroot}/usr/bin/logcorrelator install -m 0755 %{_builddir}/usr/bin/logcorrelator %{buildroot}/usr/bin/logcorrelator
# Install config files # Install config files
install -m 0640 %{_sourcedir}/etc/logcorrelator/logcorrelator.yml %{buildroot}/etc/logcorrelator/logcorrelator.yml install -m 0640 %{_builddir}/etc/logcorrelator/logcorrelator.yml %{buildroot}/etc/logcorrelator/logcorrelator.yml
install -m 0640 %{_sourcedir}/etc/logcorrelator/logcorrelator.yml.example %{buildroot}/etc/logcorrelator/logcorrelator.yml.example install -m 0640 %{_builddir}/etc/logcorrelator/logcorrelator.yml.example %{buildroot}/etc/logcorrelator/logcorrelator.yml.example
# Install systemd service # Install systemd service
install -m 0644 %{_sourcedir}/etc/systemd/system/logcorrelator.service %{buildroot}/etc/systemd/system/logcorrelator.service install -m 0644 %{_builddir}/etc/systemd/system/logcorrelator.service %{buildroot}/etc/systemd/system/logcorrelator.service
# Install logrotate config # Install logrotate config
install -m 0644 %{_sourcedir}/etc/logrotate.d/logcorrelator %{buildroot}/etc/logrotate.d/logcorrelator install -m 0644 %{_builddir}/etc/logrotate.d/logcorrelator %{buildroot}/etc/logrotate.d/logcorrelator
%post %post
# Create logcorrelator user and group # Create logcorrelator user and group