Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qm: introduction to qm dropin sub-packages(s) #585

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ SPECFILE=rpm/qm.spec
RPM_TOPDIR ?= $(PWD)/rpmbuild
VERSION ?= $(shell cat VERSION)

# Default help target
.PHONY: help
help:
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@grep -E '^##@ .*$$' $(MAKEFILE_LIST) | sed 's/##@/\n\033[1;32m/' | sed 's/$$/\033[0m/'

.PHONY: file_contexts
file_contexts: qm.fc
file_contexts: qm.fc ## - Generates the qm_file_contexts
sed \
-e "s|${QMDIR}/rootfs||" \
-e "s/gen_context(//g" \
Expand All @@ -21,7 +28,7 @@ file_contexts: qm.fc
all: selinux file_contexts man

.PHONY: selinux
selinux: qm.pp
selinux: qm.pp ## - Compresses the QM SELinux policy file (qm.pp)
@echo Compressing $^ -\> $@
bzip2 -f -9 $^

Expand All @@ -34,35 +41,47 @@ selinux: qm.pp
cp tmp/qm.pp .; rm -rf tmp

.PHONY: codespell
codespell:
codespell: ## - Runs codespell to check for spelling errors
@codespell -S tmp,.git -L te -w

clean:
clean: ## - Removes generated files and dirs
rm -f *~ *.tc *.pp *.pp.bz2
rm -rf tmp *.tar.gz ${RPM_TOPDIR}

man: qm.8.md
man: qm.8.md ## - Generates the QM man page
go-md2man --in qm.8.md --out qm.8

.PHONY: dist
dist:
dist: ## - Creates the QM distribution package
tar cvz --transform s/qm/qm-${VERSION}/ -f /tmp/v${VERSION}.tar.gz ../qm
mv /tmp/v${VERSION}.tar.gz ./rpm

.PHONY: rpm
rpm: clean dist
rpm: clean dist ## - Creates a local RPM package, useful for development
mkdir -p ${RPM_TOPDIR}/{RPMS,SRPMS,BUILD,SOURCES}
cp ./rpm/v${VERSION}.tar.gz ${RPM_TOPDIR}/SOURCES
rpmbuild -ba \
--define="enable_qm_dropin_img_tempdir 0" \
--define="_topdir ${RPM_TOPDIR}" \
--define="version ${VERSION}" \
${SPECFILE}

install-policy: all
# ostree target is a helper for everything required for ostree
.PHONY: ostree
ostree: qm_dropin_img_tempdir ## - A helper for creating QM packages for ostree based distros

.PHONY: qm_dropin_img_tempdir
qm_dropin_img_tempdir: ## - Creates a QM RPM sub-package qm_dropin_img_tempdir
sed -i 's/%define enable_qm_dropin_img_tempdir 0/%define enable_qm_dropin_img_tempdir 1/' ${SPECFILE}
sed -i 's/^Version:.*/Version: ${VERSION}/' ${SPECFILE}
make VERSION=${VERSION} rpm


install-policy: all ## - Install selinux policies only
semodule -i ${TARGETS}.pp.bz2
sepolicy manpage --path . --domain ${TARGETS}_t

install: man all
install: man all ## - Install QM files (including selinux)
install -D -pm 644 ${TARGETS}.pp.bz2 ${DESTDIR}${DATADIR}/selinux/packages/qm.pp.bz2
install -D -pm 644 qm.if ${DESTDIR}${DATADIR}/selinux/devel/include/services/qm.if
install -D -pm 644 qm_selinux.8 ${DESTDIR}${DATADIR}/man/man8/qm_selinux.8
Expand Down
27 changes: 26 additions & 1 deletion docs/devel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- [Building QM rpm manually with changes](#building-qm-rpm-manually-with-changes)
- [Building CentOS AutoSD and QM manually](#building-centos-autosd-and-qm-manually)
- [QM Drop-in sub-packages](#qm-drop-in-sub-packages)
- [Creating your own drop-in QM sub-package](#creating-your-own-drop-in-qm-sub-package)
- [Useful Commands](#useful-commands)
- [Installing software inside QM partition](#installing-software-inside-qm-partition)
- [Removing software inside QM partition](#removing-software-inside-qm-partition)
Expand Down Expand Up @@ -46,7 +48,7 @@ Make necessary changes using your preferred editor (e.g., vi/emacs).
**4.** Build the RPM

```bash
VERSION=1.0 make rpm
make clean && VERSION=1.0 make rpm
dougsland marked this conversation as resolved.
Show resolved Hide resolved
```

The rpm is created at the `${RPM_TOPDIR}/RPMS` folder, by default
Expand Down Expand Up @@ -244,3 +246,26 @@ bash-5.1# podman --root /usr/share/containers/storage pull alpine
Error: creating runtime static files directory "/usr/share/containers/storage/libpod":
mkdir /usr/share/containers/storage: read-only file system
```

## QM Drop-in sub-packages

QM developers are always looking for ways to help new users and engineers onboard more easily. With this in mind, they decided to break complex configurations into drop-in sub-package(s) when possible for adjusting the Podman engine configurations specifically within the QM environment. Why? This approach provides an easy way to extend or override settings without modifying the core (original) configuration files.

### Creating your own drop-in QM sub-package

We recommend using the existing drop-in files as a guide and adapting them to your specific needs. However, here are the step-by-step instructions:

1) Create a drop-in file in the directory: `etc/qm/containers/containers.conf.d`
2) Add it as a sub-package to `rpm/qm.spec`
3) Test it by running: `make clean && VERSION=YOURVERSIONHERE make rpm`
4) Additionally, test it with and without enabling the sub-package using (by default it should be disabled but there are cases where it will be enabled by default if QM community decide):

Example changing the spec and triggering the build via make (feel free to automate via sed, awk etc):

```bash
# Define the feature flag: 1 to enable, 0 to disable
# By default it's disabled: 0
%define enable_qm_dropin_img_tempdir 1

$ make clean && VERSION=YOURVERSIONHERE make rpm
```
13 changes: 13 additions & 0 deletions etc/qm/containers/containers.conf.d/qm_dropin_img_tempdir.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This configuration file was generated by qm-dropin sub-package:
# - qm-dropin-img-tempdir
#
# It configures the temporary directory used by the container engine
# for image copy operations. This setting is useful for performance
# optimizations or managing disk space.
#
# How it works?
#=================
# [engine] <- section
# image_copy_tmp_dir <- Specifies the directory for temporary image storage.
[engine]
image_copy_tmp_dir="/var/tmp.dir"
30 changes: 28 additions & 2 deletions rpm/qm.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
%global debug_package %{nil}

# Define the feature flag: 1 to enable, 0 to disable
# By default it's disabled: 0
%define enable_qm_dropin_img_tempdir 0

# Some bits borrowed from the openstack-selinux package
%global selinuxtype targeted
%global moduletype services
Expand All @@ -22,8 +26,6 @@
%bcond_without copr
%endif



%if 0%{?fedora}
%global podman_epoch 5
%else
Expand Down Expand Up @@ -91,6 +93,14 @@ sed -i 's/^install: man all/install:/' Makefile
%{__make} all

%install
# Create the directory for drop-in configurations
install -d %{buildroot}%{_sysconfdir}/qm/containers/containers.conf.d

%if %{enable_qm_dropin_img_tempdir}
install -m 644 %{_builddir}/qm-%{version}/etc/qm/containers/containers.conf.d/qm_dropin_img_tempdir.conf \
%{buildroot}%{_sysconfdir}/qm/containers/containers.conf.d/qm_dropin_img_tempdir.conf
%endif

# install policy modules
%_format MODULES $x.pp.bz2
%{__make} DESTDIR=%{buildroot} DATADIR=%{_datadir} install
Expand Down Expand Up @@ -127,6 +137,7 @@ fi
%license LICENSE
%doc CODE-OF-CONDUCT.md NOTICE README.md SECURITY.md
%dir %{_datadir}/selinux
%dir %{_sysconfdir}/qm/containers/containers.conf.d
%{_datadir}/selinux/*
%dir %{_datadir}/qm
%{_datadir}/qm/containers.conf
Expand All @@ -146,6 +157,21 @@ fi
%ghost %dir %{_installscriptdir}/rootfs
%ghost %{_installscriptdir}/rootfs/*

%if %{enable_qm_dropin_img_tempdir}
%package -n qm-dropin-img-tempdir
Summary: Drop-in configuration for QM containers
Requires: %{name} = %{version}-%{release}
BuildArch: noarch

%description -n qm-dropin-img-tempdir
This sub-package installs a drop-in configurations for the QM.
It creates the `/etc/qm/containers/containers.conf.d/` directory for adding
additional drop-in configurations.

%files -n qm-dropin-img-tempdir
%{_sysconfdir}/qm/containers/containers.conf.d/qm_dropin_img_tempdir.conf
%endif

%changelog
%if %{defined autochangelog}
%autochangelog
Expand Down
Loading