|
| 1 | +# Building PostGIS Container Images for CloudNativePG |
| 2 | + |
| 3 | +This guide outlines the process for building PostGIS operand images for |
| 4 | +CloudNativePG using [Docker Bake](https://docs.docker.com/build/bake/) and a |
| 5 | +[GitHub workflow](.github/workflows/bake.yml). |
| 6 | + |
| 7 | +## Prerequisites and Requirements |
| 8 | + |
| 9 | +For prerequisites and requirements, refer to the [postgres-containers](https://github.com/cloudnative-pg/postgres-containers) documentation: |
| 10 | +- [Prerequisites](https://github.com/cloudnative-pg/postgres-containers/blob/main/BUILD.md#prerequisites) |
| 11 | +- [Verifying requirements](https://github.com/cloudnative-pg/postgres-containers/blob/main/BUILD.md#verifying-requirements) |
| 12 | + |
| 13 | +## How it works |
| 14 | + |
| 15 | +This project works as a dependent module of [postgres-containers](https://github.com/cloudnative-pg/postgres-containers), and requires |
| 16 | +to include [postgres-containers's docker-bake.hcl](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) as a source Bake file definition. |
| 17 | + |
| 18 | +The local [docker-bake.hcl](docker-bake.hcl) extends the source Bake file by adding a `postgis` target. |
| 19 | + |
| 20 | +## PostGIS Target |
| 21 | + |
| 22 | +The `postgis` target in Bake represents a Cartesian product of the following |
| 23 | +dimensions: |
| 24 | + |
| 25 | +- **Base Image** (e.g `18-standard-trixie`) |
| 26 | + - **PostgreSQL Major version** (e.g `18`) |
| 27 | + - **Type** (e.g. `standard`) |
| 28 | + - **OS** (e.g. `trixie`) |
| 29 | +- **Platforms** |
| 30 | +- **PostGIS version** |
| 31 | + |
| 32 | +## Building Images |
| 33 | + |
| 34 | +To build PostGIS images using the `postgis` target - all the available PostGIS combinations - run: |
| 35 | + |
| 36 | +```bash |
| 37 | +docker buildx bake --push \ |
| 38 | + -f docker-bake.hcl \ # The bake file relative to the remote URL |
| 39 | + -f cwd://docker-bake.hcl \ # The local bake file |
| 40 | + "https://github.com/cloudnative-pg/postgres-containers.git#main" \ # The remote URL |
| 41 | + postgis |
| 42 | +``` |
| 43 | + |
| 44 | +> *Important:* It's mandatory to set the `postgis` target (or a stricter one). |
| 45 | +> Without it, Bake will try building all targets, including the `default` one |
| 46 | +> which contains plain PostgreSQL images inherited from the remote bake file. |
| 47 | +
|
| 48 | +This setup, described in https://docs.docker.com/build/bake/remote-definition/, |
| 49 | +let's you combine multiple bake files so that all attributes from the source configuration |
| 50 | +are reused. At the same time, it allows you to override specific values in the local bake file, |
| 51 | +giving you flexible and maintainable build configurations. |
| 52 | + |
| 53 | +You can limit the build to a stricter combination or even to a specific image. |
| 54 | +Postgis targets use the following naming convention: |
| 55 | +``` |
| 56 | +postgis-<postgisVersion>-<postgresMajor>-<type>-<os> |
| 57 | +``` |
| 58 | + |
| 59 | +For example, you can limit the build to all PostGIS 3.6.0 on PostgreSQL 18 by using `postgis-360-17*` as a target, |
| 60 | +or even specify a full image like `postgis-360-17-standard-trixie`. |
| 61 | + |
0 commit comments