Skip to content

Commit 566c43d

Browse files
committed
feat: allow customizing family
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
1 parent a30e03e commit 566c43d

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

.github/actions/generate-catalogs/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ inputs:
2222
required: false
2323
type: string
2424
default: "."
25+
family:
26+
description: "The family name to assign to the catalogs"
27+
required: false
28+
type: string
2529

2630
runs:
2731
using: composite
@@ -44,6 +48,7 @@ runs:
4448
DISTRIBUTIONS: ${{ inputs.distributions }}
4549
REGEX: ${{ inputs.regex }}
4650
OUTPUT_DIR: ${{ inputs.output-dir }}
51+
FAMILY: ${{ inputs.family }}
4752
run: |
4853
set -euo pipefail
4954
ARGS=()
@@ -66,6 +71,10 @@ runs:
6671
ARGS+=( --regex "$REGEX" )
6772
fi
6873
74+
if [[ -n "${FAMILY:-}" ]]; then
75+
ARGS+=( --family "$FAMILY" )
76+
fi
77+
6978
ARGS+=( --output-dir "$OUTPUT_DIR" )
7079
7180
python "$GITHUB_ACTION_PATH/catalogs_generator.py" "${ARGS[@]}"

.github/actions/generate-catalogs/catalogs_generator.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
min_supported_major = 13
3333

3434
default_registry = "ghcr.io/cloudnative-pg/postgresql"
35+
default_family = "postgresql"
3536
default_regex = r"(\d+)(?:\.\d+|beta\d+|rc\d+|alpha\d+)-(\d{12})"
3637
_token_cache = {"value": None, "expires_at": 0}
3738

@@ -124,6 +125,14 @@ def get_digest(repository_name, tag):
124125
return digest
125126

126127

128+
def get_filename(family, img_type, os):
129+
filename_prefix = "catalog"
130+
if family != default_family:
131+
filename_prefix = family
132+
133+
return f"{filename_prefix}-{img_type}-{os}.yaml"
134+
135+
127136
def write_catalog(tags, version_re, img_type, os_name, output_dir="."):
128137
image_suffix = f"-{img_type}-{os_name}"
129138
version_re = re.compile(rf"^{version_re}{re.escape(image_suffix)}$")
@@ -161,9 +170,9 @@ def write_catalog(tags, version_re, img_type, os_name, output_dir="."):
161170
"apiVersion": "postgresql.cnpg.io/v1",
162171
"kind": "ClusterImageCatalog",
163172
"metadata": {
164-
"name": f"postgresql{image_suffix}",
173+
"name": f"{args.family}{image_suffix}",
165174
"labels": {
166-
"images.cnpg.io/family": "postgresql",
175+
"images.cnpg.io/family": args.family,
167176
"images.cnpg.io/type": img_type,
168177
"images.cnpg.io/os": os_name,
169178
"images.cnpg.io/date": time.strftime("%Y%m%d"),
@@ -179,7 +188,7 @@ def write_catalog(tags, version_re, img_type, os_name, output_dir="."):
179188
}
180189

181190
os.makedirs(output_dir, exist_ok=True)
182-
output_file = os.path.join(output_dir, f"catalog{image_suffix}.yaml")
191+
output_file = os.path.join(output_dir, get_filename(args.family, img_type, os_name))
183192
with open(output_file, "w") as f:
184193
yaml.dump(catalog, f, sort_keys=False)
185194

@@ -213,6 +222,11 @@ def write_catalog(tags, version_re, img_type, os_name, output_dir="."):
213222
default=supported_os_names,
214223
help=f"Distributions to retrieve (default: {supported_os_names})",
215224
)
225+
parser.add_argument(
226+
"--family",
227+
default=default_family,
228+
help=f"The family name to assign to the catalogs (default: {default_family})",
229+
)
216230
args = parser.parse_args()
217231

218232
repo_json = get_json(args.registry)
@@ -221,7 +235,7 @@ def write_catalog(tags, version_re, img_type, os_name, output_dir="."):
221235
catalogs = []
222236
for img_type in args.image_types:
223237
for os_name in args.distributions:
224-
filename = f"catalog-{img_type}-{os_name}.yaml"
238+
filename = get_filename(args.family, img_type, os)
225239
print(f"Generating {filename}")
226240
write_catalog(tags, args.regex, img_type, os_name, args.output_dir)
227241
catalogs.append(filename)

0 commit comments

Comments
 (0)