Improve packaging

This commit is contained in:
James Campbell 2025-01-25 01:33:30 -05:00
parent 15c26e1a29
commit 466e4e7073
Signed by: james
GPG Key ID: 2287C33A40DC906A
6 changed files with 175 additions and 117 deletions

206
Makefile
View File

@ -1,3 +1,4 @@
# Package details
PACKAGE_NAME := pgmon PACKAGE_NAME := pgmon
VERSION := 1.0 VERSION := 1.0
@ -6,51 +7,41 @@ SCRIPT := src/$(PACKAGE_NAME).py
# Where packages are built # Where packages are built
BUILD_DIR := build BUILD_DIR := build
# OS images used to build packages # List of distros we support
# These are created with: make docker SUPPORTED := ubuntu-20.04 \
# Targets are at the bottom of this file ubuntu-22.04 \
DEB_IMAGE := debian-package-builder ubuntu-24.04 \
RPM_IMAGE := rpm-package-builder debian-10 \
EL7_IMAGE := el7-package-builder debian-11 \
rockylinux-8 \
# List of versions to test for each distro rockylinux-9 \
INSTALL_TEST_DEBIAN_RELEASES := 10 11 oraclelinux-7
INSTALL_TEST_REDHAT_RELEASES := 8 9
INSTALL_TEST_REDHAT_OLD_RELEASES := 7
INSTALL_TEST_UBUNTU_RELEASES := 20.04 22.04 24.04
# The default release to test for each distro (basically pick the last one in the list)
INSTALL_TEST_DEBIAN_RELEASE := $(lastword $(INSTALL_TEST_DEBIAN_RELEASES))
INSTALL_TEST_REDHAT_RELEASE := $(lastword $(INSTALL_TEST_REDHAT_RELEASES))
INSTALL_TEST_REDHAT_OLD_RELEASE := $(lastword $(INSTALL_TEST_REDHAT_OLD_RELEASES))
INSTALL_TEST_UBUNTU_RELEASE := $(lastword $(INSTALL_TEST_UBUNTU_RELEASES))
## ##
# These targets are the main ones to use for most things. # These targets are the main ones to use for most things.
## ##
.PHONY: all clean deb rpm test install install-tests .PHONY: all clean tgz test install
# Build all packages
.PHONY: package-all
all: $(foreach distro_release, $(SUPPORTED), package-$(distro_release))
all: deb rpm
# Create a deb package # Create a deb package
deb: .PHONY: package-%
mkdir -p $(BUILD_DIR)/deb package-%: PARTS=$(subst -, ,$*)
package-%: DISTRO=$(word 1, $(PARTS))
package-%: RELEASE=$(word 2, $(PARTS))
package-%:
mkdir -p $(BUILD_DIR)
docker run --rm \ docker run --rm \
-v .:/src:ro \ -v .:/src:ro \
-v ./$(BUILD_DIR)/deb:/output \ -v ./$(BUILD_DIR):/output \
--user $(shell id -u):$(shell id -g) \ --user $(shell id -u):$(shell id -g) \
$(DEB_IMAGE) "$(DISTRO)-packager:$(RELEASE)"
# Create an rpm package
rpm:
mkdir -p $(BUILD_DIR)/rpm
docker run --rm \
-v .:/src:ro \
-v ./$(BUILD_DIR)/rpm:/output \
--user $(shell id -u):$(shell id -g) \
$(RPM_IMAGE)
# Create a tarball # Create a tarball
tgz: tgz:
@ -95,56 +86,57 @@ install:
# Run all of the install tests # Run all of the install tests
install-tests: all-debian-install-tests all-redhat-install-tests all-ubuntu-install-tests .PHONY: install-tests debian-%-install-test rockylinux-%-install-test ubuntu-%-install-test
install-tests: $(foreach distro_release, $(SUPPORTED), $(distro_release)-install-test)
.PHONY: all-debian-install-tests all-redhat-install-tests all-ubuntu-install-tests
# Run all of the Debian install tests
all-debian-install-tests:
$(foreach version, $(INSTALL_TEST_DEBIAN_RELEASES), $(MAKE) debian-install-test INSTALL_TEST_DEBIAN_RELEASE=$(version) ;)
# Run all of the RedHat install tests
all-redhat-install-tests:
$(foreach version, $(INSTALL_TEST_REDHAT_RELEASES), $(MAKE) redhat-install-test INSTALL_TEST_REDHAT_RELEASE=$(version) ;)
# Run all of the *old* RedHat install tests
all-redhat-old-install-tests:
$(foreach version, $(INSTALL_TEST_REDHAT_OLD_RELEASES), $(MAKE) redhat-old-install-test INSTALL_TEST_REDHAT_OLD_RELEASE=$(version) ;)
# Run all of the Ubuntu install tests
all-ubuntu-install-tests:
$(foreach version, $(INSTALL_TEST_REDHAT_RELEASES), $(MAKE) ubuntu-install-test INSTALL_TEST_REDHAT_RELEASE=$(version) ;)
.PHONY: debian-install-test redhat-install-test rhel-old-install-test ubuntu-install-test # Run a Debian install test
debian-%-install-test:
# Run the specified (or latest) Debian install test
debian-install-test:
docker run --rm \ docker run --rm \
-v ./$(BUILD_DIR)/deb:/output \ -v ./$(BUILD_DIR):/output \
debian:$(INSTALL_TEST_DEBIAN_RELEASE) \ debian:$* \
bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)_$(VERSION).deb' bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)-$(VERSION)-debian-$*.deb'
# Run the specified (or latest) RedHat install test # Run a RedHat install test
redhat-install-test: rockylinux-%-install-test:
docker run --rm \ docker run --rm \
-v ./$(BUILD_DIR)/rpm:/output \ -v ./$(BUILD_DIR):/output \
rockylinux:$(INSTALL_TEST_REDHAT_RELEASE) \ rockylinux:$* \
bash -c 'dnf makecache && dnf install -y /output/$(PACKAGE_NAME)-$(VERSION).rpm' bash -c 'dnf makecache && dnf install -y /output/$(PACKAGE_NAME)-$(VERSION)-1.el$*.noarch.rpm'
# Run the specified (or latest) *old* RedHat install test # Run an Ubuntu install test
rhel-old-install-test: ubuntu-%-install-test:
docker run --rm \ docker run --rm \
-v ./$(BUILD_DIR)/rpm:/output \ -v ./$(BUILD_DIR):/output \
rockylinux:$(INSTALL_TEST_REDHAT_OLD_RELEASE) \ ubuntu:$* \
bash -c 'yum makecache && yum install -y /output/$(PACKAGE_NAME)-$(VERSION).el$(INSTALL_TEST_REDHAT_OLD_RELEASE).rpm' bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)-$(VERSION)-ubuntu-$*.deb'
# Run the specified (or latest) Ubuntu install test # Run an OracleLinux install test (this is for EL7 since CentOS7 images no longer exist)
ubuntu-install-test: oraclelinux-%-install-test:
docker run --rm \ docker run --rm \
-v ./$(BUILD_DIR)/deb:/output \ -v ./$(BUILD_DIR):/output \
ubuntu:$(INSTALL_TEST_UBUNTU_RELEASE) \ oraclelinux:7 \
bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)_$(VERSION).deb' 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) .
## ##
@ -155,48 +147,34 @@ ubuntu-install-test:
# /output. # /output.
## ##
.PHONY: package-deb package-rpm .PHONY: actually-package-debian-% actually-package-rockylinux-% actually-package-ubuntu-% actually-package-oraclelinux-%
# Debian package creation logic # Debian package creation
package-deb: actually-package-debian-%:
$(MAKE) install DESTDIR=/output $(MAKE) install DESTDIR=/output/debian-$*
cp -r --preserve=mode DEBIAN /output/ cp -r --preserve=mode DEBIAN /output/debian-$*/
dpkg-deb -Zgzip --build /output /output/$(PACKAGE_NAME)_$(VERSION).deb dpkg-deb -Zgzip --build /output/debian-$* "/output/$(PACKAGE_NAME)-$(VERSION)-debian-$*.deb"
# RPM package creation logic # RedHat package creation
package-rpm: actually-package-rockylinux-%:
mkdir -p /output/{BUILD,RPMS,SOURCES,SPECS,SRPMS} mkdir -p /output/rockylinux-$*/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
cp RPM/$(PACKAGE_NAME).spec /output/SPECS/ cp RPM/$(PACKAGE_NAME).spec /output/rockylinux-$*/SPECS/
rpmbuild --define '_topdir /output' \ rpmbuild --define '_topdir /output/rockylinux-$*' \
--define 'version $(VERSION)' \ --define 'version $(VERSION)' \
-bb /output/SPECS/$(PACKAGE_NAME).spec -bb /output/rockylinux-$*/SPECS/$(PACKAGE_NAME).spec
cp /output/RPMS/noarch/*.rpm /output/ cp /output/rockylinux-$*/RPMS/noarch/$(PACKAGE_NAME)-$(VERSION)-1.el$*.noarch.rpm /output/
# RPM package creation logic for old versions of RedHat (ie: 7) # Ubuntu package creation
package-rpm-old: actually-package-ubuntu-%:
mkdir -p /output/{BUILD,RPMS,SOURCES,SPECS,SRPMS} $(MAKE) install DESTDIR=/output/ubuntu-$*
cp RPM-OLD/$(PACKAGE_NAME).spec /output/SPECS/ cp -r --preserve=mode DEBIAN /output/ubuntu-$*/
rpmbuild --define '_topdir /output' \ 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)' \ --define 'version $(VERSION)' \
-bb /output/SPECS/$(PACKAGE_NAME).spec -bb /output/oraclelinux-$*/SPECS/$(PACKAGE_NAME).spec
cp /output/RPMS/noarch/*.rpm /output/ cp /output/oraclelinux-$*/RPMS/noarch/$(PACKAGE_NAME)-$(VERSION)-1.el$*.noarch.rpm /output/
##
# Container targets
#
# These targets build the docker images used to create packages
##
.PHONY: docker deb-package-image rpm-package-image
docker: deb-package-image rpm-package-image
deb-package-image: docker/Dockerfile-deb
docker build -t $(DEB_IMAGE) -f docker/Dockerfile-deb .
rpm-package-image: docker/Dockerfile-rpm
docker build -t $(RPM_IMAGE) -f docker/Dockerfile-rpm .
el7-package-image: docker/Dockerfile-el7
docker build -t $(EL7_IMAGE) -f docker/Dockerfile-el7 .

40
RPM/pgmon-el7.spec Normal file
View File

@ -0,0 +1,40 @@
Name: pgmon
Version: 1.0
Release: 1%{?dist}
Summary: A bridge to sit between monitoring tools and PostgreSQL
License: MIT
URL: https://www.commandprompt.com
BuildArch: noarch
Requires: logrotate, python, python-psycopg2, PyYAML, systemd
%description
A bridge to sit between monitoring tools and PostgreSQL
%prep
# Do nothing since we don't need a tarball
%build
# Do nothing since we have nothing to build
%install
make -C /src install DESTDIR=%{buildroot}
%files
/etc/logrotate.d/pgmon
/etc/pgmon/pgmon.yml
/etc/pgmon/pgmon-metrics.yml
/etc/pgmon/pgmon-service.conf
/lib/systemd/system/pgmon.service
/lib/systemd/system/pgmon@.service
/usr/local/bin/pgmon
/usr/share/man/man1/pgmon.1.gz
%post
mkdir -p -m 0755 /var/log/pgmon
chown root:root /var/log/pgmon
%changelog
* Wed Jan 08 2025 James Campbell <james@commandprompt.com> - 1.0-1
- Initial RPM release.

20
docker/Dockerfile-debian Normal file
View File

@ -0,0 +1,20 @@
ARG DISTRO=debian
ARG RELEASE=11
FROM ${DISTRO}:${RELEASE}
ARG DISTRO
ARG RELEASE
RUN apt-get update && apt-get install -y \
dpkg-dev \
build-essential \
fakeroot \
make \
&& rm -rf /var/lib/apt/lists/*
RUN echo -e "#!/bin/bash\nmake actually-package-${DISTRO}-${RELEASE}" > /init.sh \
&& chmod 755 /init.sh
WORKDIR /src
CMD ["/bin//bash", "/init.sh"]

View File

@ -5,11 +5,18 @@ ARG RELEASE=7
FROM ${DISTRO}:${RELEASE} FROM ${DISTRO}:${RELEASE}
ARG DISTRO
ARG RELEASE
RUN yum install -y \ RUN yum install -y \
rpm-build \ rpm-build \
make \ make \
oracle-epel-release-el7 \ oracle-epel-release-el7 \
&& yum clean all && yum clean all
RUN echo -e "#!/bin/bash\nmake actually-package-${DISTRO}-${RELEASE}" > /init.sh \
&& chmod 755 /init.sh
WORKDIR /src WORKDIR /src
CMD ["make", "package-rpm"]
CMD ["/bin/bash", "/init.sh"]

View File

@ -5,10 +5,17 @@ ARG RELEASE=9
FROM ${DISTRO}:${RELEASE} FROM ${DISTRO}:${RELEASE}
ARG DISTRO
ARG RELEASE
RUN dnf install -y \ RUN dnf install -y \
rpm-build \ rpm-build \
make \ make \
&& dnf clean all && dnf clean all
RUN echo -e "#!/bin/bash\nmake actually-package-${DISTRO}-${RELEASE}" > /init.sh \
&& chmod 755 /init.sh
WORKDIR /src WORKDIR /src
CMD ["make", "package-rpm"]
CMD ["/bin/bash", "/init.sh"]

View File

@ -3,6 +3,9 @@ ARG RELEASE=noble
FROM ${DISTRO}:${RELEASE} FROM ${DISTRO}:${RELEASE}
ARG DISTRO
ARG RELEASE
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
dpkg-dev \ dpkg-dev \
build-essential \ build-essential \
@ -10,5 +13,8 @@ RUN apt-get update && apt-get install -y \
make \ make \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN echo -e "#!/bin/bash\nmake actually-package-${DISTRO}-${RELEASE}" > /init.sh \
&& chmod 755 /init.sh
WORKDIR /src WORKDIR /src
CMD ["make", "package-deb"] CMD ["/bin/bash", "/init.sh"]