From Fedora Project Wiki

(Add goal explanation)
(Finish the writeup of https://fedorahosted.org/fpc/ticket/675)
(19 intermediate revisions by 4 users not shown)
Line 1: Line 1:
= Fedora.next Per-Product Configuration Packaging =
{{DISPLAYTITLE:Per-Product Configuration Packaging Guidelines}}
{{admon/warning|This document is a DRAFT. It has not been approved for use yet.}}
<div style="float: right; margin-left: 0.5em" class="toclimit-2">__TOC__</div>


This is an interim solution for Fedora 21 only. Work is in progress for Fedora 22 to simplify this using the new advanced dependencies available in RPM 4.11 and later
In the Fedora.next world, we have a set of curated Fedora Products as well as the availability of classic Fedora. Historically, we have maintained a single set of configuration defaults for all Fedora installs, but different target use-cases have different needs. The goal of this document is to set out the guidelines for creating per-Product configuration defaults.
 
== Goals ==
In the Fedora.next world, we will have a set of curated Fedora Products as well as the availability of classic Fedora. Historically, we have maintained a single set of configuration defaults for all Fedora installs, but different target use-cases have different needs. The goal of this document is to set out the guidelines for creating per-Product configuration defaults.


We want to ensure that all packages have sensible defaults for whichever Product on which they are installed, while also avoiding situations where users would have some packages installed with one Product's defaults and some packages with another.
We want to ensure that all packages have sensible defaults for whichever Product on which they are installed, while also avoiding situations where users would have some packages installed with one Product's defaults and some packages with another.


== Per-product Configuration Packaging ==
{{admon/warning|These guidelines are not needed for all packages|Only packages whose defaults differ between Fedora Products are required to follow these instructions. Packages whose configuration is the same for all products can simply install the config files as they normally would.}}


== Definitions ==
=== Requirements ===
* All packages MUST have a global default configuration. This configuration will be used whenever a Product-specific default configuration is not required. (For example, if a non-Product install is in use or only Fedora Cloud has a custom configuration and Fedora Workstation was installed).
* Any package that requires a per-product default configuration MUST provide all alternate configuration files in the same package.
* Any package that requires a configuration that differs between Products MUST obtain permission from that Product's Working Group before packaging it.


<b>Fedora.next</b>: Umbrella term for planning Fedora's future. Currently covering the creation of the Fedora Products, Fedora Base Design and Fedora Environments and Stacks.<br>
=== Global Default Configuration ===
<b>$PRODUCT</b>: One of the Fedora.next Product deliverables, currently "cloud", "server" and "workstation".<br>
* The global default configuration MUST be provided by the package that requires it.
<b>yum/dnf</b>: Package managers for Fedora used for installing and updating software.<br>
* The global default configuration MUST be named based on the package's normal naming scheme, with the main part of the name being suffixed by -default. For example, if the package normally uses foo.conf, then the global default configuration MUST be named foo-default.conf


== Sub-package definition ==
=== Per-Product Default Configuration ===
{{admon/warning|Only packages whose defaults differ between Fedora Products are required to follow these instructions}}
* For each Product requiring a unique default configuration, the packager MUST provide a copy of the default configuration file, modified as appropriate for the specific product.
* The product-specific configuration file MUST be named based on the package's normal naming scheme, with the main part of the name being suffixed by a dash followed by the name of the product. For example, if the package normally uses <code>foo.conf</code>, then the Server version MUST be named <code>foo-server.conf</code>.
* If the configuration will be symlinked in place, the product-specific configuration file MUST be located in an appropriate part of the /etc hierarchy. The divergent config file MUST be specified as `%config(noreplace)` in %files as per the usual /etc packaging guidelines.
* If the configuration will be copied in place, the product-specific configuration file MUST be located in an appropriate part of the /usr/share hierarchy. The divergent config file MUST be specified as a normal file in the %files section.


=== Requirements ===
* All packages must have a global default configuration. This configuration will be used whenever a Product-specific default configuration is not required. (For example, if a non-Product install is in use or only Fedora Cloud has a custom configuration and Fedora Workstation was installed).
* Any package that requires a per-product default configuration must provide a sub-package containing that configuration.


=== Global Default Configuration ===
=== Applying Configuration ===
* The global default configuration <b>must</b> be specified by a sub-package named "foo-config-standard", where foo is the base package name.
In order to apply the configuration, the packager MUST implement a mechanism in the <code>%posttrans</code> section of the specfile that behaves as follows:
* The global default configuration sub-package <b>must</b> "Requires: foo = %{version}-%{release}" (or appropriate variant including epoch)
* It MUST first check whether the final config file already exists. If so, the script MUST make no changes.
* The global default configuration sub-package <b>must</b> include a virtual "Provides: foo-config"
<pre>
* The global default configuration sub-package <b>must</b> explicitly "Conflicts: system-release-$PRODUCT" for all Products for which there exists a separate configuration.
%posttrans
* The global default configuration sub-package <b>must</b> explicitly "Conflicts: foo-config-$PRODUCT" for all Products for which there exists a separate configuration.
if [ ! -e %{_sysconfdir}/foo/foo.conf ]; then
    ...
fi
</pre>


=== Per-Product Default Configuration ===
* Then it MUST use the value of the Fedora <code>VARIANT_ID</code> to symlink or copy one of the divergent config files (or the default) to the final config file location. It will get this value by importing the contents of /etc/os-release as shell values.  Known values of this field at the time of this writing are "atomichost", "cloud", "server" and "workstation". For more detail, see [http://www.freedesktop.org/software/systemd/man/os-release.html#VARIANT_ID= the os-release(5) man page].
* For each Product requiring a unique default configuration, the packager <b>must</b> provide a sub-package named "foo-config-$PRODUCT", where foo is the base package name and $PRODUCT is the Fedora Product in question. If the global default is sufficient, the packager <b>must not</b> create a Product-specific sub-package.
<pre>
* Each Product sub-package <b>must</b> include a virtual "Provides: foo-config".
    . /etc/os-release || :
* Each Product sub-package <b>must</b> "Requires: foo = %{version}-%{release}" (or appropriate variant including epoch)
    case "$VARIANT_ID" in
* Each Product sub-package <b>must</b> "Requires: system-release-$PRODUCT", for the matching Product.
        server)
* Each Product sub-package <b>must</b> explicitly "Conflicts: foo-config-standard"
            ln -sf foo-server.conf %{_sysconfdir}/foo/foo.conf || :
* Each Product sub-package <b>must</b> explicitly "Conflicts: foo-config-$PRODUCT" for all other Products for which there exists a separate configuration.
            ;;
        *)
            ln -sf foo-default.conf %{_sysconfdir}/foo/foo.conf || :
            ;;
        esac
</pre>


* Lastly, the final config file location MUST be listed in the %files section with %ghost:
<pre>
%ghost %config(noreplace) %{_sysconfdir}/foo/foo.conf
</pre>


* For tracking purposes, the package providing the various configuration files MUST also contain a virtual Provides: for each variant configuration that may be applied:
<pre>
Provides: variant_config(Atomic.host)
Provides: variant_config(Cloud)
Provides: variant_config(Server)
Provides: variant_config(Workstation)
</pre>


=== Example (firewalld) ===
=== Example (firewalld) ===
Line 44: Line 65:


<pre>
<pre>
...
Provides: variant_config(Server)
Provides: variant_config(Workstation)
...


Name: firewalld
%posttrans
Version: 0.3.10
# If we don't yet have a symlink or existing file for firewalld.conf,
Release: 1{?dist}
# create it. Note: this will intentionally reset the policykit policy
Requires: firewalld-config
# at the same time, so they are in sync.
 
if [ ! -e %{_sysconfdir}/firewalld/firewalld.conf ]; then
%package config-standard
    # Import /etc/os-release to get the variant definition
Requires: firewalld = %{version}-%{release}
    . /etc/os-release || :
Provides: firewalld-config
Conflicts: system-release-server
Conflicts: firewalld-config-server
Conflicts: system-release-workstation
Conflicts: firewalld-config-workstation


%package config-server
    case "$VARIANT_ID" in
Provides: firewalld-config
        server)
Requires: firewalld = %{version}-%{release}
            ln -sf firewalld-server.conf %{_sysconfdir}/firewalld/firewalld.conf || :
Requires: system-release-server
            ln -sf org.fedoraproject.FirewallD1.server.policy %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
Conflicts: firewalld-config-workstation
            ;;
Conflicts: firewalld-config-standard
        workstation)
            ln -sf firewalld-workstation.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            ln -sf org.fedoraproject.FirewallD1.desktop.policy %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
            ;;
        *)
            ln -sf firewalld-default.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            # The default firewall policy will be the same as Server
            ln -sf org.fedoraproject.FirewallD1.server.policy %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
            ;;
        esac
fi


%package config-workstation
...
Provides: firewalld-config = 1.0
Requires: firewalld = %{version}-%{release}
Requires: system-release-workstation
Conflicts: firewalld-config-server
Conflicts: firewalld-config-standard


%files -f %{name}.lang
...
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld
%ghost %config(noreplace) %{_sysconfdir}/firewalld/firewalld.conf
%config(noreplace) %{_sysconfdir}/firewalld/firewalld-default.conf
%config(noreplace) %{_sysconfdir}/firewalld/firewalld-server.conf
%config(noreplace) %{_sysconfdir}/firewalld/firewalld-workstation.conf
...
%ghost %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy
%{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.desktop.policy
%{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.server.policy
</pre>
</pre>


== Reasoning ==
[[Category:Packaging guidelines]]
 
The configuration sub-packages Requires: the main package in order to guarantee that they always update together (since the reverse dependency is not versioned).
 
The version comparison algorithm used by yum will attempt to resolve the dependencies through whichever one best matches the Requires/Conflicts or whichever one will install the fewest dependencies. This should result in the appropriate Product configuration being installed or the standard configuration as the fallback.
 
 
== References ==
* http://yum.baseurl.org/wiki/CompareProviders

Revision as of 03:50, 16 February 2017

In the Fedora.next world, we have a set of curated Fedora Products as well as the availability of classic Fedora. Historically, we have maintained a single set of configuration defaults for all Fedora installs, but different target use-cases have different needs. The goal of this document is to set out the guidelines for creating per-Product configuration defaults.

We want to ensure that all packages have sensible defaults for whichever Product on which they are installed, while also avoiding situations where users would have some packages installed with one Product's defaults and some packages with another.

Per-product Configuration Packaging

Warning.png
These guidelines are not needed for all packages
Only packages whose defaults differ between Fedora Products are required to follow these instructions. Packages whose configuration is the same for all products can simply install the config files as they normally would.

Requirements

  • All packages MUST have a global default configuration. This configuration will be used whenever a Product-specific default configuration is not required. (For example, if a non-Product install is in use or only Fedora Cloud has a custom configuration and Fedora Workstation was installed).
  • Any package that requires a per-product default configuration MUST provide all alternate configuration files in the same package.
  • Any package that requires a configuration that differs between Products MUST obtain permission from that Product's Working Group before packaging it.

Global Default Configuration

  • The global default configuration MUST be provided by the package that requires it.
  • The global default configuration MUST be named based on the package's normal naming scheme, with the main part of the name being suffixed by -default. For example, if the package normally uses foo.conf, then the global default configuration MUST be named foo-default.conf

Per-Product Default Configuration

  • For each Product requiring a unique default configuration, the packager MUST provide a copy of the default configuration file, modified as appropriate for the specific product.
  • The product-specific configuration file MUST be named based on the package's normal naming scheme, with the main part of the name being suffixed by a dash followed by the name of the product. For example, if the package normally uses foo.conf, then the Server version MUST be named foo-server.conf.
  • If the configuration will be symlinked in place, the product-specific configuration file MUST be located in an appropriate part of the /etc hierarchy. The divergent config file MUST be specified as %config(noreplace) in %files as per the usual /etc packaging guidelines.
  • If the configuration will be copied in place, the product-specific configuration file MUST be located in an appropriate part of the /usr/share hierarchy. The divergent config file MUST be specified as a normal file in the %files section.


Applying Configuration

In order to apply the configuration, the packager MUST implement a mechanism in the %posttrans section of the specfile that behaves as follows:

  • It MUST first check whether the final config file already exists. If so, the script MUST make no changes.
%posttrans
if [ ! -e %{_sysconfdir}/foo/foo.conf ]; then
    ...
fi
  • Then it MUST use the value of the Fedora VARIANT_ID to symlink or copy one of the divergent config files (or the default) to the final config file location. It will get this value by importing the contents of /etc/os-release as shell values. Known values of this field at the time of this writing are "atomichost", "cloud", "server" and "workstation". For more detail, see the os-release(5) man page.
    . /etc/os-release || :
    case "$VARIANT_ID" in
        server)
            ln -sf foo-server.conf %{_sysconfdir}/foo/foo.conf || :
            ;;
        *)
            ln -sf foo-default.conf %{_sysconfdir}/foo/foo.conf || :
            ;;
        esac
  • Lastly, the final config file location MUST be listed in the %files section with %ghost:
%ghost %config(noreplace) %{_sysconfdir}/foo/foo.conf
  • For tracking purposes, the package providing the various configuration files MUST also contain a virtual Provides: for each variant configuration that may be applied:
Provides: variant_config(Atomic.host)
Provides: variant_config(Cloud)
Provides: variant_config(Server)
Provides: variant_config(Workstation)

Example (firewalld)

We will assume for the sake of demonstration that firewalld will need a custom configuration for Fedora Server and Fedora Workstation, but that Fedora Cloud will not require any changes from the global default.

...
Provides: variant_config(Server)
Provides: variant_config(Workstation)
...

%posttrans
# If we don't yet have a symlink or existing file for firewalld.conf,
# create it. Note: this will intentionally reset the policykit policy
# at the same time, so they are in sync.
if [ ! -e %{_sysconfdir}/firewalld/firewalld.conf ]; then
    # Import /etc/os-release to get the variant definition
    . /etc/os-release || :

    case "$VARIANT_ID" in
        server)
            ln -sf firewalld-server.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            ln -sf org.fedoraproject.FirewallD1.server.policy %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
            ;;
        workstation)
            ln -sf firewalld-workstation.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            ln -sf org.fedoraproject.FirewallD1.desktop.policy %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
            ;;
        *)
            ln -sf firewalld-default.conf %{_sysconfdir}/firewalld/firewalld.conf || :
            # The default firewall policy will be the same as Server
            ln -sf org.fedoraproject.FirewallD1.server.policy %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy || :
            ;;
        esac
fi

...

%files -f %{name}.lang
...
%attr(0750,root,root) %dir %{_sysconfdir}/firewalld
%ghost %config(noreplace) %{_sysconfdir}/firewalld/firewalld.conf
%config(noreplace) %{_sysconfdir}/firewalld/firewalld-default.conf
%config(noreplace) %{_sysconfdir}/firewalld/firewalld-server.conf
%config(noreplace) %{_sysconfdir}/firewalld/firewalld-workstation.conf
...
%ghost %{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.policy
%{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.desktop.policy
%{_datadir}/polkit-1/actions/org.fedoraproject.FirewallD1.server.policy