-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate.py
More file actions
executable file
·96 lines (69 loc) · 2.46 KB
/
generate.py
File metadata and controls
executable file
·96 lines (69 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2026 Daniel Wagner, SUSE LLC
#
# Author: Daniel Wagner <dwagner@suse.de>
import argparse
import sys
from pathlib import Path
import yaml
from jinja2 import Environment, FileSystemLoader
CONFIG_FILE = "ci-containers.yaml"
TEMPLATE_DIR = "templates"
def load_config():
with open(CONFIG_FILE, "r") as f:
return yaml.safe_load(f)
def build_package_list(config, distro, bundle_list):
packages = []
for bundle in bundle_list:
if bundle not in config["bundles"]:
print(f"Unknown bundle: {bundle}")
sys.exit(1)
bundle_block = config["bundles"][bundle]
if distro not in bundle_block:
print(f"Bundle '{bundle}' not defined for distro '{distro}'")
sys.exit(1)
packages.extend(bundle_block[distro])
# Deduplicate while preserving order
seen = set()
deduped = []
for pkg in packages:
if pkg not in seen:
deduped.append(pkg)
seen.add(pkg)
return deduped
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--distro", required=True,
choices=["debian", "fedora", "tumbleweed", "alpine"])
parser.add_argument("--bundles", required=True,
help="Comma separated bundle list (e.g. base,python)")
parser.add_argument("--features", default="",
help="Comma separated feature list (e.g. muon)")
parser.add_argument("--output", default=None)
args = parser.parse_args()
config = load_config()
bundle_list = [f.strip() for f in args.bundles.split(",")]
features = [f.strip() for f in args.features.split(",") if f.strip()]
packages = build_package_list(config, args.distro, bundle_list)
base_image = config["base_images"][args.distro]
env = Environment(
loader=FileSystemLoader(TEMPLATE_DIR),
trim_blocks=True,
lstrip_blocks=True,
)
template = env.get_template(f"Dockerfile.{args.distro}.j2")
rendered = template.render(
base_image=base_image,
packages=packages,
features=features,
)
output_file = args.output or f"Dockerfile.{args.distro}"
with open(output_file, "w") as f:
f.write(rendered)
print(f"Generated {output_file} "
f"(distro={args.distro}, bundles={args.bundles}, "
f"features={args.features})")
if __name__ == "__main__":
main()