|
| 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 | +``` |
0 commit comments