pgmon/Makefile

187 lines
6.0 KiB
Makefile
Raw Permalink Normal View History

2025-01-25 06:33:30 +00:00
# Package details
2025-01-08 23:34:51 +00:00
PACKAGE_NAME := pgmon
VERSION := 1.0.1
2025-01-09 01:58:52 +00:00
2025-01-22 05:45:20 +00:00
SCRIPT := src/$(PACKAGE_NAME).py
# Where packages are built
2025-01-08 23:34:51 +00:00
BUILD_DIR := build
2025-01-09 01:58:52 +00:00
2025-01-25 06:33:30 +00:00
# List of distros we support
SUPPORTED := ubuntu-20.04 \
ubuntu-22.04 \
ubuntu-24.04 \
debian-10 \
debian-11 \
rockylinux-8 \
rockylinux-9 \
2025-05-14 05:43:44 +00:00
oraclelinux-7 \
gentoo
2025-01-10 05:40:41 +00:00
##
# These targets are the main ones to use for most things.
##
2025-01-25 06:33:30 +00:00
.PHONY: all clean tgz test install
# Build all packages
.PHONY: package-all
all: $(foreach distro_release, $(SUPPORTED), package-$(distro_release))
2025-01-08 23:34:51 +00:00
2025-05-14 05:43:44 +00:00
# Gentoo package (tar.gz) creation
.PHONY: package-gentoo
package-gentoo:
mkdir -p $(BUILD_DIR)/gentoo
tar --transform "s,^\.,$(PACKAGE_NAME)-$(VERSION)," -acjf $(BUILD_DIR)/gentoo/$(PACKAGE_NAME)-$(VERSION).tar.bz2 --exclude $(BUILD_DIR) .
2025-01-08 23:34:51 +00:00
2025-01-22 05:45:20 +00:00
# Create a deb package
2025-01-25 06:33:30 +00:00
.PHONY: package-%
package-%: PARTS=$(subst -, ,$*)
package-%: DISTRO=$(word 1, $(PARTS))
package-%: RELEASE=$(word 2, $(PARTS))
package-%:
mkdir -p $(BUILD_DIR)
2025-01-08 23:34:51 +00:00
docker run --rm \
-v .:/src:ro \
2025-01-25 06:33:30 +00:00
-v ./$(BUILD_DIR):/output \
--user $(shell id -u):$(shell id -g) \
2025-01-25 06:33:30 +00:00
"$(DISTRO)-packager:$(RELEASE)"
2025-01-08 23:34:51 +00:00
2025-01-22 05:45:20 +00:00
# Create a tarball
2025-01-10 05:40:41 +00:00
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 .
2025-01-22 05:45:20 +00:00
# Clean up the build directory
2025-01-08 23:34:51 +00:00
clean:
rm -rf $(BUILD_DIR)
2025-01-22 05:45:20 +00:00
# Run unit tests for the script
2025-01-09 01:58:52 +00:00
test:
cd src ; python3 -m unittest
2025-01-08 23:34:51 +00:00
2025-01-22 05:45:20 +00:00
# Install the script at the specified base directory
2025-01-10 05:40:41 +00:00
install:
# Set up directories
mkdir -p $(DESTDIR)/etc/$(PACKAGE_NAME)
mkdir -p ${DESTDIR}/etc/logrotate.d
2025-01-10 05:40:41 +00:00
mkdir -p $(DESTDIR)/lib/systemd/system
mkdir -p $(DESTDIR)/usr/local/bin
mkdir -p $(DESTDIR)/usr/share/man/man1
2025-01-10 05:40:41 +00:00
# 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
2025-01-10 05:40:41 +00:00
# Install sample config
cp sample-config/* $(DESTDIR)/etc/$(PACKAGE_NAME)/
# Install systemd unit files
cp systemd/* $(DESTDIR)/lib/systemd/system/
2025-01-15 06:34:04 +00:00
# Install logrotate config
cp logrotate/${PACKAGE_NAME}.logrotate ${DESTDIR}/etc/logrotate.d/${PACKAGE_NAME}
2025-01-08 23:34:51 +00:00
2025-01-22 05:45:20 +00:00
# Run all of the install tests
2025-01-25 06:33:30 +00:00
.PHONY: install-tests debian-%-install-test rockylinux-%-install-test ubuntu-%-install-test
install-tests: $(foreach distro_release, $(SUPPORTED), $(distro_release)-install-test)
2025-01-22 05:45:20 +00:00
2025-01-25 06:33:30 +00:00
# Run a Debian install test
debian-%-install-test:
2025-01-10 05:40:41 +00:00
docker run --rm \
2025-01-25 06:33:30 +00:00
-v ./$(BUILD_DIR):/output \
debian:$* \
bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)-$(VERSION)-debian-$*.deb'
2025-01-08 23:34:51 +00:00
2025-01-25 06:33:30 +00:00
# Run a RedHat install test
rockylinux-%-install-test:
2025-01-10 05:40:41 +00:00
docker run --rm \
2025-01-25 06:33:30 +00:00
-v ./$(BUILD_DIR):/output \
rockylinux:$* \
bash -c 'dnf makecache && dnf install -y /output/$(PACKAGE_NAME)-$(VERSION)-1.el$*.noarch.rpm'
2025-01-10 05:40:41 +00:00
2025-01-25 06:33:30 +00:00
# Run an Ubuntu install test
ubuntu-%-install-test:
2025-01-22 05:45:20 +00:00
docker run --rm \
2025-01-25 06:33:30 +00:00
-v ./$(BUILD_DIR):/output \
ubuntu:$* \
bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)-$(VERSION)-ubuntu-$*.deb'
2025-01-22 05:45:20 +00:00
2025-01-25 06:33:30 +00:00
# Run an OracleLinux install test (this is for EL7 since CentOS7 images no longer exist)
oraclelinux-%-install-test:
2025-01-10 05:40:41 +00:00
docker run --rm \
2025-01-25 06:33:30 +00:00
-v ./$(BUILD_DIR):/output \
oraclelinux:7 \
bash -c 'yum makecache && yum install -y /output/$(PACKAGE_NAME)-$(VERSION)-1.el7.noarch.rpm'
2025-01-08 23:34:51 +00:00
2025-01-10 05:40:41 +00:00
##
2025-01-25 06:33:30 +00:00
# Container targets
2025-01-10 05:40:41 +00:00
#
2025-01-25 06:33:30 +00:00
# These targets build the docker images used to create packages
2025-01-10 05:40:41 +00:00
##
2025-01-25 06:33:30 +00:00
# Target to build packaging images for all supported releases
.PHONY: all-package-images
all-package-images: $(foreach distro_release, $(SUPPORTED), package-image-$(distro_release))
2025-01-08 23:34:51 +00:00
2025-01-25 06:33:30 +00:00
# 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) .
2025-01-22 05:45:20 +00:00
2025-01-08 23:34:51 +00:00
2025-01-10 05:40:41 +00:00
##
2025-01-25 06:33:30 +00:00
# Inside-container targets
2025-01-10 05:40:41 +00:00
#
2025-01-25 06:33:30 +00:00
# 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.
2025-01-10 05:40:41 +00:00
##
2025-01-25 06:33:30 +00:00
.PHONY: actually-package-debian-% actually-package-rockylinux-% actually-package-ubuntu-% actually-package-oraclelinux-%
2025-01-10 05:40:41 +00:00
2025-01-25 06:33:30 +00:00
# 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"
2025-01-10 05:40:41 +00:00
2025-01-25 06:33:30 +00:00
# RedHat package creation
actually-package-rockylinux-%:
mkdir -p /output/rockylinux-$*/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
sed -e "s/@@VERSION@@/$(VERSION)/g" RPM/$(PACKAGE_NAME).spec > /output/rockylinux-$*/SPECS/$(PACKAGE_NAME).spec
2025-01-25 06:33:30 +00:00
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}
sed -e "s/@@VERSION@@/$(VERSION)/g" RPM/$(PACKAGE_NAME)-el7.spec > /output/oraclelinux-$*/SPECS/$(PACKAGE_NAME).spec
2025-01-25 06:33:30 +00:00
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/