Skip to content

Commit 17900f7

Browse files
committed
feat: required inputs and documentation
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
1 parent 6255d42 commit 17900f7

3 files changed

Lines changed: 104 additions & 12 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Image Catalogs Generator Action
2+
3+
This composite GitHub Action generates [CloudNativePG's ImageCatalogs](https://cloudnative-pg.io/documentation/current/image_catalog/)
4+
from a container registry.
5+
It wraps the [catalogs_generator.py](./catalogs_generator.py) Python script and makes it easy to run in CI pipelines.
6+
7+
## How it works
8+
9+
The script uses a regular expression on the tags retrieved from the registry to match the tags that should be used inside the ImageCatalog,
10+
then it sorts them using [semantic versioning](https://semver.org/), and for each available PostgreSQL major version it
11+
selects the latest tag entry.
12+
13+
A new ImageCatalog YAML file is generated for each distribution and image_type requested, alongside a `kustomization.yaml` that
14+
can be used to install all the catalogs at once.
15+
16+
## Inputs
17+
18+
| Name | Required | Description | Example |
19+
| --------------- | -------- | --------------------------------------------------------------- | --------------------------------------------|
20+
| `registry` | ✅ yes | The container registry to interrogate. | `ghcr.io/cloudnative-pg/postgres` |
21+
| `image-types` | ✅ yes | Comma-separated list of image types. | `minimal,standard` |
22+
| `distributions` | ✅ yes | Comma-separated list of supported OS distributions. | `bookworm,trixie` |
23+
| `regex` | ✅ yes | Regular expression used to match image tags. | See [Regex Input](#regex) |
24+
| `output-dir` | ✅ yes | Path to the directory where generated catalogs are written. | `path/to/the/directory` |
25+
| `family` | ❌ no | Family name assigned to the catalogs (used as filename prefix). | `my-custom-family` (it can be any string) |
26+
27+
### regex
28+
29+
This is the regular expression used to match the tags that should be added to the ImageCatalog.
30+
The first capturing group **must** be the PostgreSQL major version: `(\d+)` (e.g `18`)
31+
Subsequent capturing groups are optional, and can contain
32+
* an additional version: `(\d+(?:\.\d+)+)` (e.g `1.2.3`)
33+
* a 12 digit timestamp: `(\d{12})` (e.g `202509161052`)
34+
35+
Example of valid regex:
36+
```
37+
## Matches '18-202509161052', '18.1-202509161052' etc..
38+
'(\d+)(?:\.\d+|beta\d+|rc\d+|alpha\d+)-(\d{12})'
39+
40+
## Matches '18-3.0.6-202509161052', '18.1-3.0.6-202509161052' etc..
41+
'(\d+)(?:\.\d+|beta\d+|rc\d+|alpha\d+)-(\d+(?:\.\d+){1,3})-(\d{12})'
42+
```
43+
44+
> **Note:** Each `image-types` and `distributions` will be combined together
45+
> to form a suffix, `-<img_type>-<distribution>`, which will internally be
46+
> appended to the `regex` provided. Tags that do not contain explicit
47+
> image type and distribution as a suffix are currently not supported.
48+
49+
### family
50+
51+
The `family` is an optional string input which can be used to customize:
52+
1. The prefix used to create the ImageCatalog YAML files (e.g `<my-family>-minimal-trixie.yaml`)
53+
2. The `metadata.name` of the ImageCatalog object (e.g `<my-family>-minimal-trixie`)
54+
3. The value assigned to the `images.cnpg.io/family` label of the ImageCatalog object
55+
56+
## Usage
57+
58+
In a workflow, call the action like this:
59+
60+
```
61+
jobs:
62+
generate-catalogs:
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Generate image catalogs
66+
uses: cloudnative-pg/postgres-containers/.github/actions/generate-catalogs@main
67+
with:
68+
registry: ghcr.io/cloudnative-pg/postgres
69+
image-types: minimal,standard
70+
distributions: bookworm,trixie
71+
regex: '(\d+)(?:\.\d+|beta\d+|rc\d+|alpha\d+)-(\d{12})'
72+
output-dir: .
73+
```
74+
75+
This would output ImageCatalogs such as:
76+
77+
```
78+
./catalog-minimal-bookworm.yaml
79+
./catalog-standard-bookworm.yaml
80+
./catalog-minimal-trixie.yaml
81+
./catalog-standard-trixie.yaml
82+
```
83+
84+
plus a `kustomization.yaml` which would look like this:
85+
86+
```
87+
apiVersion: kustomize.config.k8s.io/v1beta1
88+
kind: Kustomization
89+
resources:
90+
- catalog-minimal-bookworm.yaml
91+
- catalog-standard-bookworm.yaml
92+
- catalog-minimal-trixie.yaml
93+
- catalog-standard-trixie.yaml
94+
```

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,22 @@ description: Generate Image Catalogs
33
inputs:
44
registry:
55
description: "The registry to interrogate"
6-
required: false
7-
type: string
6+
required: true
87
image-types:
98
description: "Image types to retrieve - comma separated values"
10-
required: false
11-
type: string
9+
required: true
1210
distributions:
1311
description: "OS distributions to retrieve - comma separated values"
14-
required: false
15-
type: string
12+
required: true
1613
regex:
1714
description: "The regular expression used to retrieve container images"
18-
required: false
19-
type: string
15+
required: true
2016
output-dir:
2117
description: "The path to output directory"
22-
required: false
23-
type: string
24-
default: "."
18+
required: true
2519
family:
2620
description: "The family name to assign to the catalogs"
2721
required: false
28-
type: string
2922

3023
runs:
3124
using: composite

.github/workflows/catalogs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ jobs:
3434
uses: ./postgres-containers/.github/actions/generate-catalogs
3535
with:
3636
output-dir: artifacts/image-catalogs/
37+
registry: ghcr.io/cloudnative-pg/postgres
38+
family: postgresql
39+
distributions: bullseye,bookworm,trixie
40+
image-types: minimal,standard,system
41+
regex: '(\d+)(?:\.\d+|beta\d+|rc\d+|alpha\d+)-(\d{12})'
3742

3843
# TODO: remove this step once system images are EOL
3944
- name: Update legacy catalogs

0 commit comments

Comments
 (0)