Unify packaging: use Docker + fpm for DEB and RPM builds

- Add Dockerfile.package with multi-stage build (builder, package-builder, output)
- Update Makefile to add package, package-deb, package-rpm, and test-package targets
- Replace debhelper and rpmbuild with fpm for consistent packaging
- Both DEB and RPM packages now built from single Dockerfile

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Jacquin Antoine
2026-02-27 15:31:55 +01:00
parent b5d093f8cb
commit 802ce75a80
2 changed files with 163 additions and 8 deletions

View File

@ -12,6 +12,7 @@ CFLAGS ?= -Wall -Wextra -O2
SRC_DIR = src
BUILD_DIR = build
INSTALL_DIR = modules
DIST_DIR = dist
# Source files
SRCS = $(SRC_DIR)/mod_reqin_log.c
@ -19,7 +20,10 @@ SRCS = $(SRC_DIR)/mod_reqin_log.c
# Module name
MODULE_NAME = mod_reqin_log
.PHONY: all clean install uninstall test
# Package version
VERSION ?= 1.0.0
.PHONY: all clean install uninstall test package package-deb package-rpm
all: $(MODULE_NAME).so
@ -66,21 +70,63 @@ test:
debug: CFLAGS += -g -DDEBUG
debug: clean all
# =============================================================================
# Packaging (DEB + RPM with Docker + fpm)
# =============================================================================
## package: Build all packages (deb + rpm)
package: package-deb package-rpm
## package-deb: Build DEB package (requires Docker)
package-deb:
mkdir -p $(DIST_DIR)/deb $(DIST_DIR)/rpm
docker build --target output -t mod_reqin_log-packager:latest \
--build-arg VERSION=$(VERSION) \
-f Dockerfile.package .
@echo "Extracting packages from Docker image..."
docker run --rm -v $(PWD)/$(DIST_DIR):/output mod_reqin_log-packager:latest \
sh -c 'cp -r /packages/deb /output/deb/ && cp -r /packages/rpm /output/rpm/'
@echo "DEB packages created:"
ls -la $(DIST_DIR)/deb/
@echo "RPM packages created:"
ls -la $(DIST_DIR)/rpm/
## package-rpm: Build RPM package (requires Docker)
package-rpm: package-deb
@echo "RPM built together with DEB in Dockerfile.package"
## test-package-deb: Test DEB package installation in Docker
test-package-deb: package-deb
docker run --rm -v $(PWD)/$(DIST_DIR)/deb:/packages:ro debian:latest \
sh -c "apt-get update && apt-get install -y /packages/*.deb && echo 'DEB install OK'"
## test-package-rpm: Test RPM package installation in Docker
test-package-rpm: package-deb
docker run --rm -v $(PWD)/$(DIST_DIR)/rpm:/packages:ro rockylinux:8 \
sh -c "dnf install -y /packages/*.rpm && echo 'RPM install OK'"
## test-package: Test all packages installation
test-package: test-package-deb test-package-rpm
# Help target
help:
@echo "mod_reqin_log Makefile"
@echo ""
@echo "Targets:"
@echo " all - Build the module (default)"
@echo " install - Install the module to DESTDIR"
@echo " uninstall- Remove the module from DESTDIR"
@echo " clean - Remove build artifacts"
@echo " test - Run unit tests"
@echo " debug - Build with debug symbols"
@echo " help - Show this help message"
@echo " all - Build the module (default)"
@echo " install - Install the module to DESTDIR"
@echo " uninstall - Remove the module from DESTDIR"
@echo " clean - Remove build artifacts"
@echo " test - Run unit tests"
@echo " debug - Build with debug symbols"
@echo " package - Build all packages (deb + rpm)"
@echo " package-deb - Build DEB package"
@echo " package-rpm - Build RPM package"
@echo " test-package - Test package installation"
@echo ""
@echo "Variables:"
@echo " APXS - Path to apxs tool (default: apxs)"
@echo " CC - C compiler (default: gcc)"
@echo " CFLAGS - Compiler flags (default: -Wall -Wextra -O2)"
@echo " DESTDIR - Installation destination (default: /)"
@echo " VERSION - Package version (default: 1.0.0)"