Skip to content

Commit e2f928f

Browse files
committed
Add global config reasearch
1 parent 31ef632 commit e2f928f

File tree

1 file changed

+281
-0
lines changed

1 file changed

+281
-0
lines changed

research/global-config/index.md

+281
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
---
2+
title: Global configuration
3+
authors:
4+
- mmassari
5+
sidebar_position: 1
6+
---
7+
8+
# Global configuration styles
9+
10+
I will analyze 3 approaches for managing configuration relationships:
11+
12+
- templating
13+
- global configuration + overlays
14+
- inheritance
15+
16+
# 1. Templating
17+
18+
## https://github.com/packit/templeates/config/simple-pull-from-upstream.yaml.j2
19+
20+
```yml
21+
# Packit pull-from-upstream config
22+
specfile_path: { { specfile_path } }
23+
24+
upstream_package_name: { { upstream_package_name } }
25+
downstream_package_name: { { downstream_package_name } }
26+
upstream_project_url: { { upstream_package_url } }
27+
upstream_tag_template: v{version}
28+
29+
jobs:
30+
- job: pull_from_upstream
31+
trigger: release
32+
dist_git_branches:
33+
- fedora-rawhide
34+
- job: koji_build
35+
trigger: commit
36+
allowed_pr_authors: ["packit", { { allowed_pr_authors } }]
37+
dist_git_branches:
38+
- fedora-rawhide
39+
```
40+
41+
## https://gitlab.gnome.org/packit/templates/configs/gnome-tests.yaml.j2
42+
43+
```yml
44+
# Gnome default tests config
45+
jobs:
46+
- job: tests
47+
trigger: pull_request
48+
packages: [{{ downstream_package_name }}]
49+
tmt_plan: "smoke|full|packit-integration|{{ tmt_other_plans }}"
50+
targets:
51+
- fedora-rawhide
52+
{% if tests_on_commit %}
53+
- job: tests
54+
trigger: commit
55+
packages: [{{ downstream_package_name }}]
56+
tmt_plan: "smoke|full|packit-integration|{{ tmt_other_plans }}"
57+
targets:
58+
- fedora-rawhide
59+
{% endif %}
60+
```
61+
62+
## https://gitlab.gnome.org/package/packit.yaml
63+
64+
```yml
65+
# A gnome package packit config
66+
templates:
67+
- https://github.com/packit/templeates/config/simple-pull-from-upstream.yaml.j2
68+
vars:
69+
specfile_path: specfile_path
70+
upstream_package_name: upstream_package_name
71+
downstream_package_name: downstream_package_name
72+
upstream_project_url: upstream_project_url
73+
allowed_pr_authors: allowed_pr_authors
74+
- https://gitlab.gnome.org/packit/templates/configs/gnome-tests.yaml.j2
75+
downstream_package_name: downstream_package_name
76+
tmt_other_plans: tmt_other_plans
77+
tests_on_commit: false
78+
```
79+
80+
# 2. Global config + overlay
81+
82+
## https://github.com/packit/templates/configs/standard-pull-from-upstream.yaml.j2
83+
84+
```yml
85+
# Packit pull-from-upstream config
86+
specfile_path: { { specfile_path } }
87+
88+
upstream_package_name: { { upstream_package_name } }
89+
downstream_package_name: { { downstream_package_name } }
90+
upstream_project_url: { { upstream_package_url } }
91+
upstream_tag_template: v{version}
92+
93+
jobs:
94+
- job: pull_from_upstream
95+
trigger: release
96+
dist_git_branches:
97+
- fedora-rawhide
98+
- job: koji_build
99+
trigger: commit
100+
allowed_pr_authors: ["packit", { { allowed_pr_authors } }]
101+
dist_git_branches:
102+
- fedora-rawhide
103+
```
104+
105+
## https://gitlab.gnome.org/packit/templates/configs/default_packit.yaml.j2
106+
107+
```yml
108+
# Gnome default packit config
109+
config:
110+
base: https://github.com/packit/templates/configs/standard-pull-from-upstream.yaml.j2
111+
values:
112+
allowed_pr_authors: gnome-admins
113+
114+
jobs:
115+
- job: tests
116+
trigger: pull_request
117+
packages: [{{ downstream_package_name }}]
118+
tmt_plan: "smoke|full|packit-integration|{{ tmt_other_plans }}"
119+
targets:
120+
- fedora-rawhide
121+
{% if tests_on_commit %}
122+
- job: tests
123+
trigger: commit
124+
packages: [{{ downstream_package_name }}]
125+
tmt_plan: "smoke|full|packit-integration|{{ tmt_other_plans }}"
126+
targets:
127+
- fedora-rawhide
128+
{% endif %}
129+
```
130+
131+
## https://gitlab.gnome.org/package/packit.yaml
132+
133+
```yml
134+
# A gnome package packit config
135+
config:
136+
base: https://gitlab.gnome.org/packit/templates/configs/default_packit.yaml.j2
137+
values:
138+
specfile_path: specfile_path
139+
upstream_package_name: upstream_package_name
140+
downstream_package_name: downstream_package_name
141+
upstream_project_url: upstream_package_url
142+
tmt_other_plans: package-tests
143+
tests_on_commit: false
144+
```
145+
146+
# 3. Inheritance
147+
148+
## https://github.com/packit/templates/configs/standard-pull-from-upstream.yaml
149+
150+
```yml
151+
# Packit pull-from-upstream config
152+
specfile_path: -OVERRIDE ME-
153+
154+
upstream_package_name: -OVERRIDE ME-
155+
downstream_package_name: -OVERRIDE ME-
156+
upstream_project_url: -OVERRIDE ME-
157+
158+
upstream_tag_template: v{version}
159+
160+
jobs:
161+
- job: pull_from_upstream
162+
trigger: release
163+
dist_git_branches:
164+
- fedora-rawhide
165+
- job: koji_build
166+
trigger: commit
167+
allowed_pr_authors: ["packit"]
168+
dist_git_branches:
169+
- fedora-rawhide
170+
```
171+
172+
## https://gitlab.gnome.org/packit/templates/configs/default_packit.yaml
173+
174+
```yml
175+
# Gnome default packit config
176+
inherit: https://github.com/packit/templates/configs/standard-pull-from-upstream.yaml
177+
178+
jobs:
179+
- job: koji_build
180+
allowed_pr_authors: ["packit", "gnome-admins"]
181+
182+
- job: tests
183+
trigger: pull_request
184+
tmt_plan: "smoke|full|packit-integration"
185+
targets:
186+
- fedora-rawhide
187+
```
188+
189+
## https://gitlab.gnome.org/package/packit.yaml
190+
191+
```yml
192+
# A gnome package packit config
193+
inherit: https://gitlab.gnome.org/packit/templates/configs/default_packit.yaml
194+
195+
specfile_path: specfile_path
196+
upstream_package_name: upstream_package_name
197+
downstream_package_name: downstream_package_name
198+
upstream_project_url: upstream_package_url
199+
200+
jobs:
201+
- job: tests
202+
packages: ["downstream_package_name"]
203+
tmt_plan: "smoke|full|packit-integration|package-tests"
204+
```
205+
206+
# PROs and CONs
207+
208+
## Templating
209+
210+
### Pros
211+
212+
Flexible, probably the most flexible implementation that allows to freely mix configuration snippets for creating a customized final configuration.
213+
214+
### Cons
215+
216+
The "pure" templating mechanism, in the above example, requires the package maintainer to know that koji builds, in the gnome ecosystem, should be allowed for any **gnome-admin**, instead _inheritance_ and _global config + overlays_ encapsulate well the knowledge in the middle layer packit config.
217+
218+
Templating is flexible but on the other end it is more error prone; there is no _base configuration_ and a packager can list templates in the wrong order.
219+
220+
Probably, in the end, the packager will use smaller config snippets, decreasing performance and readability.
221+
222+
## Global config + overlays
223+
224+
### Pros
225+
226+
Good knowledge encapsulation in middle layers (see the **gnome-admin** for allowed_pr_authors in the above example).
227+
228+
Explicit and thus easily readable, since the use of templating.
229+
230+
Flexible, config snippets can easily be removed using template conditional functionalities (as in the above example for the test job with trigger commit).
231+
232+
### Cons
233+
234+
The templating syntax can be more error prone if compared with inheritance.
235+
236+
## Inheritance
237+
238+
### Pros
239+
240+
Concise, it's the most concise syntax we could use and probably the least error prone.
241+
242+
### Cons
243+
244+
Poor flexibility, I don't see an easy way to disable the above test job with trigger commit.
245+
246+
Not really explicit, even though we use a placeholder it is harder to recognize the keys that need overriding.
247+
248+
# Implementation
249+
250+
Personally I find the _global config + overlays_ approach the best and in this case we would need to:
251+
252+
- add the following keys to the `PackageConfig` class:
253+
254+
```yml
255+
config:
256+
base: https://gitlab.gnome.org/packit/templates/configs/default_packit.yaml.j2
257+
values: ...
258+
```
259+
260+
- load the packit.yaml file and search for the `config` key in it. If a `config` key is found we need to **recursively** look for the _base config_ and start processing all the templates in the chain, creating a new temporary packit.yml that will be used instead of the original one.
261+
I see this code tied with the `LocalProject` class but I can be wrong.
262+
We should make the new code work both for the packit CLI and the packit-service. Thinking at packit CLI, we should probably stay flexible and let the `base: URI` be also a local url (like `file:///`).
263+
264+
- let the user know what the final configuration looks like (both for CLI and service).
265+
266+
## Jinja2 vs Ansible library
267+
268+
For template management I would probably just use the **jinja2 template library**, even though we can also think about the ansible library.
269+
The ansible library could let us use `built-in filters and functions` but I don't see use cases for them and as a cons it has a heavier dependency footprint.
270+
271+
# Performances
272+
273+
Splitting the configuration in multiple configuration files will lead obviously to worst performance. Personally I don't see a way to prevent it.
274+
275+
We can limit the number of recursion steps; 3/4 steps are, from my point of view, more than enough. Having a recursion limit will avoid an infinite recursion for malformed configurations.
276+
277+
# packit-service defaults
278+
279+
It could happen that the packit-service config defaults for the "Fedora CI instance" and those for the "Usual instance" (as an example) diverge.
280+
281+
If it happens we could create two _hidden_, _inner_ packit config bases, one per instance, which will always be used for merging any packit config we process; in this way the differences will be grouped explicitly in a single place and we could, probably, enable and disable jobs for one instance or the other (as an example `pull-from-upstream` should not appear in fedora ci packit configuration) just using templating.

0 commit comments

Comments
 (0)