# Package details PACKAGE_NAME := pgmon VERSION := 1.0 SCRIPT := src/$(PACKAGE_NAME).py # Where packages are built BUILD_DIR := build # List of distros we support SUPPORTED := ubuntu-20.04 \ ubuntu-22.04 \ ubuntu-24.04 \ debian-10 \ debian-11 \ rockylinux-8 \ rockylinux-9 \ oraclelinux-7 ## # These targets are the main ones to use for most things. ## .PHONY: all clean tgz test install # Build all packages .PHONY: package-all all: $(foreach distro_release, $(SUPPORTED), package-$(distro_release)) # Create a deb package .PHONY: package-% package-%: PARTS=$(subst -, ,$*) package-%: DISTRO=$(word 1, $(PARTS)) package-%: RELEASE=$(word 2, $(PARTS)) package-%: mkdir -p $(BUILD_DIR) docker run --rm \ -v .:/src:ro \ -v ./$(BUILD_DIR):/output \ --user $(shell id -u):$(shell id -g) \ "$(DISTRO)-packager:$(RELEASE)" # Create a tarball tgz: rm -rf $(BUILD_DIR)/tgz/root mkdir -p $(BUILD_DIR)/tgz/root $(MAKE) install DESTDIR=$(BUILD_DIR)/tgz/root tar -cz -f $(BUILD_DIR)/tgz/$(PACKAGE_NAME)-$(VERSION).tgz -C $(BUILD_DIR)/tgz/root . # Clean up the build directory clean: rm -rf $(BUILD_DIR) # Run unit tests for the script test: cd src ; python3 -m unittest # Install the script at the specified base directory install: # Set up directories mkdir -p $(DESTDIR)/etc/$(PACKAGE_NAME) mkdir -p ${DESTDIR}/etc/logrotate.d mkdir -p $(DESTDIR)/lib/systemd/system mkdir -p $(DESTDIR)/usr/local/bin mkdir -p $(DESTDIR)/usr/share/man/man1 # Install script cp $(SCRIPT) $(DESTDIR)/usr/local/bin/$(PACKAGE_NAME) chmod 755 $(DESTDIR)/usr/local/bin/$(PACKAGE_NAME) # Install manpage cp manpages/* $(DESTDIR)/usr/share/man/man1/ gzip -f -9 $(DESTDIR)/usr/share/man/man1/$(PACKAGE_NAME).1 # Install sample config cp sample-config/* $(DESTDIR)/etc/$(PACKAGE_NAME)/ # Install systemd unit files cp systemd/* $(DESTDIR)/lib/systemd/system/ # Install logrotate config cp logrotate/${PACKAGE_NAME}.logrotate ${DESTDIR}/etc/logrotate.d/${PACKAGE_NAME} # Run all of the install tests .PHONY: install-tests debian-%-install-test rockylinux-%-install-test ubuntu-%-install-test install-tests: $(foreach distro_release, $(SUPPORTED), $(distro_release)-install-test) # Run a Debian install test debian-%-install-test: docker run --rm \ -v ./$(BUILD_DIR):/output \ debian:$* \ bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)-$(VERSION)-debian-$*.deb' # Run a RedHat install test rockylinux-%-install-test: docker run --rm \ -v ./$(BUILD_DIR):/output \ rockylinux:$* \ bash -c 'dnf makecache && dnf install -y /output/$(PACKAGE_NAME)-$(VERSION)-1.el$*.noarch.rpm' # Run an Ubuntu install test ubuntu-%-install-test: docker run --rm \ -v ./$(BUILD_DIR):/output \ ubuntu:$* \ bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)-$(VERSION)-ubuntu-$*.deb' # Run an OracleLinux install test (this is for EL7 since CentOS7 images no longer exist) oraclelinux-%-install-test: docker run --rm \ -v ./$(BUILD_DIR):/output \ oraclelinux:7 \ bash -c 'yum makecache && yum install -y /output/$(PACKAGE_NAME)-$(VERSION)-1.el7.noarch.rpm' ## # Container targets # # These targets build the docker images used to create packages ## # Target to build packaging images for all supported releases .PHONY: all-package-images all-package-images: $(foreach distro_release, $(SUPPORTED), package-image-$(distro_release)) # Generic target for creating images that actually build the packages # The % is expected to be: distro-release # The build/.package-image-% target actually does the work and touches a state file to avoid excessive building .PHONY: package-image-% package-image-%: PARTS=$(subst -, ,$*) package-image-%: DISTRO=$(word 1, $(PARTS)) package-image-%: RELEASE=$(word 2, $(PARTS)) package-image-%: docker build -t "$(DISTRO)-packager:$(RELEASE)" --build-arg "RELEASE=$(RELEASE)" --build-arg "DISTRO=$(DISTRO)" -f docker/Dockerfile-$(DISTRO) . ## # Inside-container targets # # These targets are used inside containers. They expect the repo to be mounted # at /src and the package manager specific build directory to be mounted at # /output. ## .PHONY: actually-package-debian-% actually-package-rockylinux-% actually-package-ubuntu-% actually-package-oraclelinux-% # Debian package creation actually-package-debian-%: $(MAKE) install DESTDIR=/output/debian-$* cp -r --preserve=mode DEBIAN /output/debian-$*/ dpkg-deb -Zgzip --build /output/debian-$* "/output/$(PACKAGE_NAME)-$(VERSION)-debian-$*.deb" # RedHat package creation actually-package-rockylinux-%: mkdir -p /output/rockylinux-$*/{BUILD,RPMS,SOURCES,SPECS,SRPMS} cp RPM/$(PACKAGE_NAME).spec /output/rockylinux-$*/SPECS/ rpmbuild --define '_topdir /output/rockylinux-$*' \ --define 'version $(VERSION)' \ -bb /output/rockylinux-$*/SPECS/$(PACKAGE_NAME).spec cp /output/rockylinux-$*/RPMS/noarch/$(PACKAGE_NAME)-$(VERSION)-1.el$*.noarch.rpm /output/ # Ubuntu package creation actually-package-ubuntu-%: $(MAKE) install DESTDIR=/output/ubuntu-$* cp -r --preserve=mode DEBIAN /output/ubuntu-$*/ dpkg-deb -Zgzip --build /output/ubuntu-$* "/output/$(PACKAGE_NAME)-$(VERSION)-ubuntu-$*.deb" # OracleLinux package creation actually-package-oraclelinux-%: mkdir -p /output/oraclelinux-$*/{BUILD,RPMS,SOURCES,SPECS,SRPMS} cp RPM/$(PACKAGE_NAME)-el7.spec /output/oraclelinux-$*/SPECS/$(PACKAGE_NAME).spec rpmbuild --define '_topdir /output/oraclelinux-$*' \ --define 'version $(VERSION)' \ -bb /output/oraclelinux-$*/SPECS/$(PACKAGE_NAME).spec cp /output/oraclelinux-$*/RPMS/noarch/$(PACKAGE_NAME)-$(VERSION)-1.el$*.noarch.rpm /output/