From 219d1737a1507fe4adebd871d6ddb3b41f37b0fa Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Tue, 17 Jun 2025 11:17:41 +0200 Subject: [PATCH 01/17] chore: add blog post about building images with bake Signed-off-by: Jonathan Gonzalez V. --- content/blog/building-images-bake/bake.hcl | 31 +++++ content/blog/building-images-bake/index.md | 154 +++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 content/blog/building-images-bake/bake.hcl create mode 100644 content/blog/building-images-bake/index.md diff --git a/content/blog/building-images-bake/bake.hcl b/content/blog/building-images-bake/bake.hcl new file mode 100644 index 000000000..bd0f51ad1 --- /dev/null +++ b/content/blog/building-images-bake/bake.hcl @@ -0,0 +1,31 @@ +extensions = [ + "pgvector", +] +target "myimage" { + dockerfile-inline = < Date: Tue, 17 Jun 2025 12:46:22 +0200 Subject: [PATCH 02/17] chore: various grammar fixes Signed-off-by: Jaime Silvela --- content/blog/building-images-bake/index.md | 87 ++++++++++++---------- 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index c23a84c62..9ab2e9826 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -20,23 +20,26 @@ summary: Creating a container image for CloudNativePG Operator v2.0 --- ## Summary -In an almost [two years old blog post](https://cloudnative-pg.io/blog/creating-container-images/), we explained how -to build a custom container image for CloudNativePG. After two years, many things have changed in the containers world, -one of those things was the introduction of [Bake](https://www.docker.com/blog/bake/) in Docker, which allows you to build -images using a simple configuration file, and it is now our recommended way to build images for CloudNativePG. +In an almost [two years old blog post]({{% ref "/blog/creating-container-images/" %}}), we explained how +to build a custom container image for CloudNativePG. After two years, many things have changed in the world of containers. +One of those things was the introduction of [Bake](https://www.docker.com/blog/bake/) in Docker, which allows you to build +images using a simple configuration file. Bake is now our recommended way to build images for CloudNativePG. We will follow a simple cooking recipe to create a custom container image or a set of container images, since Bake -allows you to build multiple images at once in a pretty simple way. +allows you to build multiple images at once in a simple way. ## Ingredients -- A bake file, we will use the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) -Cooking time: 5 minutes +- A bake file. We will use the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) + +Cooking time: 5 minutes. ## Instructions ### Step 1: Prepare local bake file + In a local file with name `bake.hcl`, we add the following content, which is a simple bake file that will build a custom image + ```hcl extensions = [ "pgvector", @@ -70,33 +73,37 @@ EOT EXTENSIONS = "${getExtensionsString(pgVersion, extensions)}", } } - ``` -There's a couple of things that we can remark here: -* The `extensions` variable is a list of extensions that we want to include in the image, in this case we are using `pg_vector`, + +There are a few things that we should remark here: + +- The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pg_vector`, but you can add any other extension that you want to include in the image. -* The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely, will explain more about this later. -* The `target` and the `tgt` have the same name, you can use what ever you want here as a name -* The `pgVersion` is a variable list that contains basically, the MAJOR.MINOR version of PostgreSQL -* The `name` is the name that we will use later to refer to one element of the matrix that we created -* The `args` is all the arguments passed to the Dockerfile, will talk more about this later. -* The function `getExtensionsString()` is one that is inherited from a bake file that we reference in the [Ingredients](#ingredients) section +- The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain more about this later. +- The `target` and the `tgt` have the same name, you can use what ever you want here as a name +- The `pgVersion` is a variable list that contains basically, the MAJOR.MINOR version of PostgreSQL +- The `name` is the name that we will use later to refer to one element of the matrix that we created +- The `args` lists all the arguments passed to the Dockerfile. We will talk more about this later. +- The function `getExtensionsString()` is inherited from the bake file that we reference in the [Ingredients](#ingredients) section ### Step 2: Build the image We can now build the image using the following command: + ```bash docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage ``` -This will, by default, build the image for the bake matrix we previously created and will try to push the image to the registry -`localhost:5000`, which is the default registry defined for testing environments in the parent bake file, so let's explain the full command first. +This will, by default, build the image for the bake matrix we previously created, and will try to push the image to the registry at +`localhost:5000`, which is the default registry defined for testing environments in the parent bake file. Let's explain the full command first. -As is defined in the [Bake documentation about remote definition](https://docs.docker.com/build/bake/remote-definition/) -you can use a remote bake definition with all the functions and default targets and attach another local one that you can use to override -all the default values, in this case the `-f cwd://bake.hcl` is the local file that we created in the previous step, and -the `-f docker-bake.hcl` is the remote file that we're using to build the image, this is in the git repo. +As is defined in the [Bake documentation about remote definitions](https://docs.docker.com/build/bake/remote-definition/) +you can use a remote bake definition with all the functions and default targets, and attach another local one that you can use to override +all the default values. +In the command above, `-f cwd://bake.hcl` is the local file that we created in the previous step, and +`-f docker-bake.hcl` is the remote file that we're using to build the image, which is in the git repo. + +You can explore more about all the content generated and used inside the bake file by appending the `--print` flag, as in the following command: -You can explore more about all the content generated and used inside the bake file with the following command: ```bash docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage --print ``` @@ -104,35 +111,37 @@ docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/clou ### Step 3: Push the image to a registry Now you just need to push the image to a registry, you can do this by using the following command: + ```bash registry=your/registry:5000 docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage --push ``` -The previous command will push the images in the following format `your/registry:5000/postgresql-testing:17-standard-bookworm`, -using the `--print` you can explore the full list of tags created that are in the parent bake file. + +The previous command will push the images in the following format: `your/registry:5000/postgresql-testing:17-standard-bookworm`. +Using the `--print` flag you can explore the full list of tags created that are in the parent bake file. ### Step 4: Serve the image -You can now let your clusters to use the image that it's built and based on the CloudNativePG operand images provided +You can now let your clusters use the image that we've built based on the CloudNativePG operand images provided by the CloudNativePG project. ## Deep dive into the Bake and Dockerfile -The simplicity of Bake to bring more stuff is amazing and allows you to create a custom image in a very simple way. -But, how is this magic happens? Let's take a look at the Bake and the Docker file. +The simplicity of Bake to do even more stuff is amazing, and allows you to create custom images in a very simple way. +But, how does this magic happen? Let's take a look at the Bake and the Docker file. ### Bake file This is the base of our magic, but that magic starts in our postgres-containers repository, where we have a `docker-bake.hcl` file -that it's being used to build the images provided by the CloudNativePG project, and it's the base for our custom Bake file. +that is being used to build the images provided by the CloudNativePG project, and it's the base for our custom Bake file. - -The `docker-bake.hcl` file contains a lot of functions that are used to build the images, and one of them is the `getExtensionsString()`, -this one, using the list of extensions we provided, will return a string of the extensions with the correct package name -for a Debian-based distribution, in our case, Debian Bookworm, so the `pg_vector` extension will be translated into -`postgresql-16-pgvector` which will be the name of the package of pgvector extensions for PostgreSQL 16 in the Debian +The `docker-bake.hcl` file contains a lot of functions that are used to build the images, and one of them is the `getExtensionsString()`. +This function, using the list of extensions we provided, will return a string of the extensions with the correct package name +for a Debian-based distribution, in our case, Debian Bookworm. +So the `pg_vector` extension will be translated into +`postgresql-16-pgvector` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian Bookworm distribution. -Even the variable that are passed in the `args` variable to the Dockerfile are processed by the Bake file, in this case, +Even the variables that are passed in the `args` variable to the Dockerfile are processed by the Bake file, in this case, the variables we add, are being added and the ones we overwrite are being overwritten, so we can use the same variables and content used in the parent Bake file. @@ -145,10 +154,12 @@ on the CloudNativePG images, and we can add the extensions we want to use in our ## There's more! You may want to avoid building arm64 image by adding the following: + ```hcl platforms = ["linux/amd64"] ``` -This will overwrite the platforms variable and so, will build only for one platform -Also, if you want to build everything into your own repository and manage the same tags, it's possible, in the future -we may write another post explaining this +This will overwrite the platforms variable and so, will build only for one platform. + +Also, if you want to build everything into your own repository and manage the same tags, it's possible. In the future +we may write another post explaining this. From afe44aebebc82c5a720db99ab5de3a0c6ad624e7 Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Tue, 17 Jun 2025 14:59:56 +0200 Subject: [PATCH 03/17] chore: some reviews Signed-off-by: Jonathan Gonzalez V. --- content/blog/building-images-bake/index.md | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 9ab2e9826..43a844ae9 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -22,7 +22,7 @@ summary: Creating a container image for CloudNativePG Operator v2.0 ## Summary In an almost [two years old blog post]({{% ref "/blog/creating-container-images/" %}}), we explained how to build a custom container image for CloudNativePG. After two years, many things have changed in the world of containers. -One of those things was the introduction of [Bake](https://www.docker.com/blog/bake/) in Docker, which allows you to build +One of those things was the introduction of [Bake](https://docs.docker.com/build/) in Docker, which allows you to build images using a simple configuration file. Bake is now our recommended way to build images for CloudNativePG. We will follow a simple cooking recipe to create a custom container image or a set of container images, since Bake @@ -30,15 +30,15 @@ allows you to build multiple images at once in a simple way. ## Ingredients -- A bake file. We will use the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) +- A Bake file. We will use the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) Cooking time: 5 minutes. ## Instructions -### Step 1: Prepare local bake file +### Step 1: Prepare local Bake file -In a local file with name `bake.hcl`, we add the following content, which is a simple bake file that will build a custom image +In a local file with name `bake.hcl`, we add the following content, which is a simple Bake file that will build a custom image ```hcl extensions = [ @@ -84,7 +84,7 @@ There are a few things that we should remark here: - The `pgVersion` is a variable list that contains basically, the MAJOR.MINOR version of PostgreSQL - The `name` is the name that we will use later to refer to one element of the matrix that we created - The `args` lists all the arguments passed to the Dockerfile. We will talk more about this later. -- The function `getExtensionsString()` is inherited from the bake file that we reference in the [Ingredients](#ingredients) section +- The function `getExtensionsString()` is inherited from the Bake file that we reference in the [Ingredients](#ingredients) section ### Step 2: Build the image @@ -94,15 +94,15 @@ We can now build the image using the following command: docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage ``` This will, by default, build the image for the bake matrix we previously created, and will try to push the image to the registry at -`localhost:5000`, which is the default registry defined for testing environments in the parent bake file. Let's explain the full command first. +`localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain the full command first. As is defined in the [Bake documentation about remote definitions](https://docs.docker.com/build/bake/remote-definition/) -you can use a remote bake definition with all the functions and default targets, and attach another local one that you can use to override +you can use a remote Bake definition with all the functions and default targets, and attach another local one that you can use to override all the default values. In the command above, `-f cwd://bake.hcl` is the local file that we created in the previous step, and `-f docker-bake.hcl` is the remote file that we're using to build the image, which is in the git repo. -You can explore more about all the content generated and used inside the bake file by appending the `--print` flag, as in the following command: +You can explore more about all the content generated and used inside the Bake file by appending the `--print` flag, as in the following command: ```bash docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage --print @@ -117,7 +117,7 @@ registry=your/registry:5000 docker buildx bake -f docker-bake.hcl -f cwd://bake. ``` The previous command will push the images in the following format: `your/registry:5000/postgresql-testing:17-standard-bookworm`. -Using the `--print` flag you can explore the full list of tags created that are in the parent bake file. +Using the `--print` flag you can explore the full list of tags created that are in the parent Bake file. ### Step 4: Serve the image @@ -131,7 +131,7 @@ But, how does this magic happen? Let's take a look at the Bake and the Docker fi ### Bake file -This is the base of our magic, but that magic starts in our postgres-containers repository, where we have a `docker-bake.hcl` file +This is where the magic starts with our postgres-containers repository, where we have a `docker-bake.hcl` file that is being used to build the images provided by the CloudNativePG project, and it's the base for our custom Bake file. The `docker-bake.hcl` file contains a lot of functions that are used to build the images, and one of them is the `getExtensionsString()`. @@ -141,9 +141,8 @@ So the `pg_vector` extension will be translated into `postgresql-16-pgvector` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian Bookworm distribution. -Even the variables that are passed in the `args` variable to the Dockerfile are processed by the Bake file, in this case, -the variables we add, are being added and the ones we overwrite are being overwritten, so we can use the same variables -and content used in the parent Bake file. +When we add elements to, for example, the `args` variable, those variables are processed by the Bake file, and will be +merged, meaning that the non existent variables will be added, and the existing ones will be overwritten. ### Dockerfile file From cb2a26b252ac6d18441aacd0d75b95142f2eb05d Mon Sep 17 00:00:00 2001 From: Jaime Silvela Date: Tue, 17 Jun 2025 17:42:09 +0200 Subject: [PATCH 04/17] chore: some clarifications and corrections Signed-off-by: Jaime Silvela --- content/blog/building-images-bake/index.md | 39 +++++++++++----------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 43a844ae9..b633ad197 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -22,7 +22,7 @@ summary: Creating a container image for CloudNativePG Operator v2.0 ## Summary In an almost [two years old blog post]({{% ref "/blog/creating-container-images/" %}}), we explained how to build a custom container image for CloudNativePG. After two years, many things have changed in the world of containers. -One of those things was the introduction of [Bake](https://docs.docker.com/build/) in Docker, which allows you to build +One of those things has been the introduction of [Bake](https://docs.docker.com/build/) in Docker, which allows you to build images using a simple configuration file. Bake is now our recommended way to build images for CloudNativePG. We will follow a simple cooking recipe to create a custom container image or a set of container images, since Bake @@ -80,10 +80,10 @@ There are a few things that we should remark here: - The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pg_vector`, but you can add any other extension that you want to include in the image. - The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain more about this later. -- The `target` and the `tgt` have the same name, you can use what ever you want here as a name -- The `pgVersion` is a variable list that contains basically, the MAJOR.MINOR version of PostgreSQL +- The `target` and the `tgt` have the same name, you can use whatever you want here as a name +- The `pgVersion` variable is a list that contains basically the MAJOR.MINOR version of PostgreSQL - The `name` is the name that we will use later to refer to one element of the matrix that we created -- The `args` lists all the arguments passed to the Dockerfile. We will talk more about this later. +- The variable `args` lists all the arguments passed to the Dockerfile. We will talk more about this later. - The function `getExtensionsString()` is inherited from the Bake file that we reference in the [Ingredients](#ingredients) section ### Step 2: Build the image @@ -93,14 +93,15 @@ We can now build the image using the following command: ```bash docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage ``` + This will, by default, build the image for the bake matrix we previously created, and will try to push the image to the registry at -`localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain the full command first. +`localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain the full command: As is defined in the [Bake documentation about remote definitions](https://docs.docker.com/build/bake/remote-definition/) you can use a remote Bake definition with all the functions and default targets, and attach another local one that you can use to override all the default values. -In the command above, `-f cwd://bake.hcl` is the local file that we created in the previous step, and -`-f docker-bake.hcl` is the remote file that we're using to build the image, which is in the git repo. +In the command above, `-f cwd://bake.hcl` is the local file that we created in Step 1, and +`-f docker-bake.hcl` is the remote file in the git repo, that we're using to build the image. You can explore more about all the content generated and used inside the Bake file by appending the `--print` flag, as in the following command: @@ -110,7 +111,7 @@ docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/clou ### Step 3: Push the image to a registry -Now you just need to push the image to a registry, you can do this by using the following command: +Now you just need to push the image to a registry. You can do this by using the following command: ```bash registry=your/registry:5000 docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage --push @@ -126,29 +127,29 @@ by the CloudNativePG project. ## Deep dive into the Bake and Dockerfile -The simplicity of Bake to do even more stuff is amazing, and allows you to create custom images in a very simple way. +The simplicity of Bake to do even more stuff is amazing, and allows you to create custom images easily. But, how does this magic happen? Let's take a look at the Bake and the Docker file. ### Bake file -This is where the magic starts with our postgres-containers repository, where we have a `docker-bake.hcl` file -that is being used to build the images provided by the CloudNativePG project, and it's the base for our custom Bake file. +The magic starts with our postgres-containers repository, where we have a `docker-bake.hcl` file +that is being used to build the images provided by the CloudNativePG project.It's the base for our custom Bake file. -The `docker-bake.hcl` file contains a lot of functions that are used to build the images, and one of them is the `getExtensionsString()`. -This function, using the list of extensions we provided, will return a string of the extensions with the correct package name +The `docker-bake.hcl` file contains a lot of functions that are used to build the images. One of them is the `getExtensionsString()`. +This function, given the list of extensions we provided, will return a string of the extensions with the correct package name for a Debian-based distribution, in our case, Debian Bookworm. -So the `pg_vector` extension will be translated into -`postgresql-16-pgvector` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian +For example, the `pg_vector` extension will be translated into +`postgresql-16-pgvector,` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian Bookworm distribution. -When we add elements to, for example, the `args` variable, those variables are processed by the Bake file, and will be -merged, meaning that the non existent variables will be added, and the existing ones will be overwritten. +When we add elements to, for example, the `args` variable, those elements are processed by the Bake file, and will be +merged, meaning that the new elements will be added, and the existing ones will be overwritten. ### Dockerfile file -The Dockerfile is simple an inline content, because of the limitations of Bake to overwrite the remote Dockerfile with a +The Dockerfile is simply a heredoc string, because of the limitations of Bake to overwrite the remote Dockerfile with a local one, but it allows us to change the FROM in the image, which means we can create an image that it's directly based -on the CloudNativePG images, and we can add the extensions we want to use in our image, without building all of them +on the CloudNativePG images, and we can add the extensions we want to use in our image, without building all of them. ## There's more! From c9ef65ba152809bac12daf8e5b1b21136b0327ee Mon Sep 17 00:00:00 2001 From: Jaime Silvela Date: Tue, 17 Jun 2025 17:45:04 +0200 Subject: [PATCH 05/17] fix: bad newline Signed-off-by: Jaime Silvela --- content/blog/building-images-bake/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index b633ad197..81014a12b 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -133,7 +133,8 @@ But, how does this magic happen? Let's take a look at the Bake and the Docker fi ### Bake file The magic starts with our postgres-containers repository, where we have a `docker-bake.hcl` file -that is being used to build the images provided by the CloudNativePG project.It's the base for our custom Bake file. +that is being used to build the images provided by the CloudNativePG project. +It's the base for our custom Bake file. The `docker-bake.hcl` file contains a lot of functions that are used to build the images. One of them is the `getExtensionsString()`. This function, given the list of extensions we provided, will return a string of the extensions with the correct package name From 0b5db2a526f734f4340e472b51cd2f87e56e47a4 Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Tue, 17 Jun 2025 18:09:19 +0200 Subject: [PATCH 06/17] chore: more review Signed-off-by: Jonathan Gonzalez V. --- content/blog/building-images-bake/index.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 81014a12b..805563ec3 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -31,6 +31,7 @@ allows you to build multiple images at once in a simple way. ## Ingredients - A Bake file. We will use the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) +- Another Bake file, but this time a local one, this one is to overwrite the previous one. Cooking time: 5 minutes. @@ -38,7 +39,7 @@ Cooking time: 5 minutes. ### Step 1: Prepare local Bake file -In a local file with name `bake.hcl`, we add the following content, which is a simple Bake file that will build a custom image +In a local file with name [bake.hcl](bake.hcl), we add the following content, which is a simple Bake file that will build a custom image ```hcl extensions = [ @@ -132,8 +133,8 @@ But, how does this magic happen? Let's take a look at the Bake and the Docker fi ### Bake file -The magic starts with our postgres-containers repository, where we have a `docker-bake.hcl` file -that is being used to build the images provided by the CloudNativePG project. +The magic starts with our [postgres-containers repository](https://github.com/cloudnative-pg/postgres-containers), +where we have a `docker-bake.hcl` file that is being used to build the images provided by the CloudNativePG project. It's the base for our custom Bake file. The `docker-bake.hcl` file contains a lot of functions that are used to build the images. One of them is the `getExtensionsString()`. @@ -154,7 +155,7 @@ on the CloudNativePG images, and we can add the extensions we want to use in our ## There's more! -You may want to avoid building arm64 image by adding the following: +You may want to avoid building arm64 images by adding the following: ```hcl platforms = ["linux/amd64"] From 2d85677a2f682c3945bdcc02248544f67a60f349 Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Tue, 17 Jun 2025 18:11:30 +0200 Subject: [PATCH 07/17] Update content/blog/building-images-bake/index.md Co-authored-by: Jaime Silvela Signed-off-by: Jonathan Gonzalez V. --- content/blog/building-images-bake/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 805563ec3..e715c6f7b 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -22,7 +22,7 @@ summary: Creating a container image for CloudNativePG Operator v2.0 ## Summary In an almost [two years old blog post]({{% ref "/blog/creating-container-images/" %}}), we explained how to build a custom container image for CloudNativePG. After two years, many things have changed in the world of containers. -One of those things has been the introduction of [Bake](https://docs.docker.com/build/) in Docker, which allows you to build +One of those things has been the introduction of [Bake](https://docs.docker.com/build/bake/) in Docker, which allows you to build images using a simple configuration file. Bake is now our recommended way to build images for CloudNativePG. We will follow a simple cooking recipe to create a custom container image or a set of container images, since Bake From 7897ca3a4ec013f14135df8c6b2ccde5fc677cbb Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Tue, 17 Jun 2025 18:13:46 +0200 Subject: [PATCH 08/17] more changes Signed-off-by: Jonathan Gonzalez V. --- content/blog/building-images-bake/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index e715c6f7b..d9c7d6f6f 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -25,7 +25,7 @@ to build a custom container image for CloudNativePG. After two years, many thing One of those things has been the introduction of [Bake](https://docs.docker.com/build/bake/) in Docker, which allows you to build images using a simple configuration file. Bake is now our recommended way to build images for CloudNativePG. -We will follow a simple cooking recipe to create a custom container image or a set of container images, since Bake +We will follow a simple baking recipe to create a custom container image or a set of container images, since Bake allows you to build multiple images at once in a simple way. ## Ingredients @@ -33,7 +33,7 @@ allows you to build multiple images at once in a simple way. - A Bake file. We will use the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) - Another Bake file, but this time a local one, this one is to overwrite the previous one. -Cooking time: 5 minutes. +Baking time: 5 minutes. ## Instructions From 403198aa8ea269ccb81a2be770a8b78ba65f1b68 Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Wed, 18 Jun 2025 08:18:05 +0200 Subject: [PATCH 09/17] more tags Signed-off-by: Jonathan Gonzalez V. --- content/blog/building-images-bake/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index d9c7d6f6f..9d1fcce42 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -16,6 +16,8 @@ tags: - postgres - images - tutorial + - bake + - docker summary: Creating a container image for CloudNativePG Operator v2.0 --- From 751370331abdc98e4b4dd4a1f317327f01d366ee Mon Sep 17 00:00:00 2001 From: Floor Drees Date: Mon, 23 Jun 2025 10:18:06 +0200 Subject: [PATCH 10/17] Apply suggestions from code review Thank you Jaime! Co-authored-by: Jaime Silvela Signed-off-by: Floor Drees --- content/blog/building-images-bake/index.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 9d1fcce42..65b735732 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -22,13 +22,14 @@ summary: Creating a container image for CloudNativePG Operator v2.0 --- ## Summary -In an almost [two years old blog post]({{% ref "/blog/creating-container-images/" %}}), we explained how -to build a custom container image for CloudNativePG. After two years, many things have changed in the world of containers. +Almost two years ago, we wrote a [blog post on +building custom container images for CloudNativePG]({{% ref "/blog/creating-container-images/" %}}). +Since then, many things have changed in the world of containers. One of those things has been the introduction of [Bake](https://docs.docker.com/build/bake/) in Docker, which allows you to build images using a simple configuration file. Bake is now our recommended way to build images for CloudNativePG. -We will follow a simple baking recipe to create a custom container image or a set of container images, since Bake -allows you to build multiple images at once in a simple way. +We will follow a simple baking recipe to create a custom container image. +Bake will also allow you to easily build multiple images at the same time. ## Ingredients @@ -81,7 +82,7 @@ EOT There are a few things that we should remark here: - The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pg_vector`, - but you can add any other extension that you want to include in the image. + but you can add any other extension you want. - The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain more about this later. - The `target` and the `tgt` have the same name, you can use whatever you want here as a name - The `pgVersion` variable is a list that contains basically the MAJOR.MINOR version of PostgreSQL From 5ff38427be278b770e466e426535977e6ba2cf30 Mon Sep 17 00:00:00 2001 From: Floor Drees Date: Mon, 23 Jun 2025 13:16:35 +0000 Subject: [PATCH 11/17] Add Jaime's suggestions Signed-off-by: Floor Drees --- content/blog/building-images-bake/index.md | 41 ++++++++++------------ 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 65b735732..4f8d51702 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -1,6 +1,6 @@ --- title: "Creating a custom container image for CloudNativePG v2.0" -date: 2025-06-17 +date: 2025-06-23 draft: false image: url: @@ -18,15 +18,15 @@ tags: - tutorial - bake - docker -summary: Creating a container image for CloudNativePG Operator v2.0 +summary: Using Docker's Bake to create container images for the CloudNativePG Operator v2.0. --- ## Summary -Almost two years ago, we wrote a [blog post on -building custom container images for CloudNativePG]({{% ref "/blog/creating-container-images/" %}}). -Since then, many things have changed in the world of containers. -One of those things has been the introduction of [Bake](https://docs.docker.com/build/bake/) in Docker, which allows you to build -images using a simple configuration file. Bake is now our recommended way to build images for CloudNativePG. +Almost two years ago, we wrote a [blog post on building custom container images +for CloudNativePG]({{% ref "/blog/creating-container-images/" %}}). Since then, many things have changed in the world of containers. +One of those things has been the introduction of [Bake](https://docs.docker.com/build/bake/) in Docker, +which allows you to build images using a simple configuration file. Bake is now +our recommended way to build images for CloudNativePG. We will follow a simple baking recipe to create a custom container image. Bake will also allow you to easily build multiple images at the same time. @@ -34,7 +34,7 @@ Bake will also allow you to easily build multiple images at the same time. ## Ingredients - A Bake file. We will use the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) -- Another Bake file, but this time a local one, this one is to overwrite the previous one. +- Another (local) Bake file, to overwrite the previous one and have a Bake file with your changes applied and build the container images Baking time: 5 minutes. @@ -42,7 +42,7 @@ Baking time: 5 minutes. ### Step 1: Prepare local Bake file -In a local file with name [bake.hcl](bake.hcl), we add the following content, which is a simple Bake file that will build a custom image +To build a custom image we add the following content in a local file with name [bake.hcl](bake.hcl): ```hcl extensions = [ @@ -81,12 +81,11 @@ EOT There are a few things that we should remark here: -- The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pg_vector`, - but you can add any other extension you want. +- The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pgvector`. But you can add any other extension you want. - The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain more about this later. -- The `target` and the `tgt` have the same name, you can use whatever you want here as a name -- The `pgVersion` variable is a list that contains basically the MAJOR.MINOR version of PostgreSQL -- The `name` is the name that we will use later to refer to one element of the matrix that we created +- The `target` and the `tgt` have the same name. You can use whatever you want here as a name. +- The `pgVersion` variable is a list that contains basically the MAJOR.MINOR version of PostgreSQL. +- The `name` is the name that we will use later to refer to one element of the matrix that we created. - The variable `args` lists all the arguments passed to the Dockerfile. We will talk more about this later. - The function `getExtensionsString()` is inherited from the Bake file that we reference in the [Ingredients](#ingredients) section @@ -101,9 +100,9 @@ docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/clou This will, by default, build the image for the bake matrix we previously created, and will try to push the image to the registry at `localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain the full command: -As is defined in the [Bake documentation about remote definitions](https://docs.docker.com/build/bake/remote-definition/) -you can use a remote Bake definition with all the functions and default targets, and attach another local one that you can use to override -all the default values. +As explained in the [Bake documentation about remote definitions](https://docs.docker.com/build/bake/remote-definition/) you can use a remote Bake definition with all the functions and default targets, and attach another local one to override +all the default values. + In the command above, `-f cwd://bake.hcl` is the local file that we created in Step 1, and `-f docker-bake.hcl` is the remote file in the git repo, that we're using to build the image. @@ -126,13 +125,11 @@ Using the `--print` flag you can explore the full list of tags created that are ### Step 4: Serve the image -You can now let your clusters use the image that we've built based on the CloudNativePG operand images provided -by the CloudNativePG project. +You can now let your clusters use the image that we've built based on the CloudNativePG operand images. ## Deep dive into the Bake and Dockerfile -The simplicity of Bake to do even more stuff is amazing, and allows you to create custom images easily. -But, how does this magic happen? Let's take a look at the Bake and the Docker file. +The simplicity of Bake to do even more stuff is amazing, and allows you to create custom images easily. ### Bake file @@ -143,7 +140,7 @@ It's the base for our custom Bake file. The `docker-bake.hcl` file contains a lot of functions that are used to build the images. One of them is the `getExtensionsString()`. This function, given the list of extensions we provided, will return a string of the extensions with the correct package name for a Debian-based distribution, in our case, Debian Bookworm. -For example, the `pg_vector` extension will be translated into +For example, the `pgvector` extension will be translated into `postgresql-16-pgvector,` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian Bookworm distribution. From 2d7c65c177e88af076e89ae8cc72d7ed513a9e93 Mon Sep 17 00:00:00 2001 From: Floor Drees Date: Thu, 17 Jul 2025 13:57:50 +0200 Subject: [PATCH 12/17] Apply suggestions from code review Co-authored-by: Jaime Silvela Signed-off-by: Floor Drees --- content/blog/building-images-bake/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 4f8d51702..82fb66c3c 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -125,7 +125,7 @@ Using the `--print` flag you can explore the full list of tags created that are ### Step 4: Serve the image -You can now let your clusters use the image that we've built based on the CloudNativePG operand images. +You can now use the image that we've built for your clusters. ## Deep dive into the Bake and Dockerfile @@ -134,7 +134,7 @@ The simplicity of Bake to do even more stuff is amazing, and allows you to creat ### Bake file The magic starts with our [postgres-containers repository](https://github.com/cloudnative-pg/postgres-containers), -where we have a `docker-bake.hcl` file that is being used to build the images provided by the CloudNativePG project. +where we have a `docker-bake.hcl` file that is being used to build the images for the CloudNativePG project. It's the base for our custom Bake file. The `docker-bake.hcl` file contains a lot of functions that are used to build the images. One of them is the `getExtensionsString()`. From 551c96ab9cc844af954ee53266c67c036e21e84a Mon Sep 17 00:00:00 2001 From: Floor Drees Date: Thu, 17 Jul 2025 12:29:22 +0000 Subject: [PATCH 13/17] rewrite based on Jaime's review Signed-off-by: Floor Drees --- content/blog/building-images-bake/index.md | 55 +++++++++++----------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 82fb66c3c..e6eca9b7a 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -1,6 +1,6 @@ --- title: "Creating a custom container image for CloudNativePG v2.0" -date: 2025-06-23 +date: 2025-07-22 draft: false image: url: @@ -22,19 +22,21 @@ summary: Using Docker's Bake to create container images for the CloudNativePG Op --- ## Summary -Almost two years ago, we wrote a [blog post on building custom container images -for CloudNativePG]({{% ref "/blog/creating-container-images/" %}}). Since then, many things have changed in the world of containers. -One of those things has been the introduction of [Bake](https://docs.docker.com/build/bake/) in Docker, -which allows you to build images using a simple configuration file. Bake is now -our recommended way to build images for CloudNativePG. +Nearly two years ago, we shared a [blog post on building custom container +images for CloudNativePG]({{% ref "/blog/creating-container-images/" %}}). Since then, the container ecosystem has evolved +significantly—one notable development being the introduction of [Docker Bake]((https://docs.docker.com/build/bake/)). -We will follow a simple baking recipe to create a custom container image. -Bake will also allow you to easily build multiple images at the same time. +Docker Bake simplifies image builds using a straightforward configuration file, +and it’s now our recommended approach for building CloudNativePG images. + +In this post, we’ll walk through a simple baking recipe to create a custom +container image. With Bake, you can also easily build multiple images in +parallel. ## Ingredients -- A Bake file. We will use the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) -- Another (local) Bake file, to overwrite the previous one and have a Bake file with your changes applied and build the container images +- A Bake file, using the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) as a base. +- A second, local Bake file to override the base configuration—this lets you apply your custom changes and build the container images accordingly. Baking time: 5 minutes. @@ -79,15 +81,16 @@ EOT } ``` -There are a few things that we should remark here: +There are a few important points to highlight: + +- The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pgvector`, but you can add any others as needed. +- The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain why later. +- The `target` and the `tgt` values share the same name, but you can use any name you prefer. +- The `pgVersion` variable is a list specifying the PostgreSQL version(s) in MAJOR.MINOR format. +- The `name` field is used to identify individual entries in the matrix we’ve defined. +- The `args` variable contains the arguments passed to the Dockerfile—more on this later. +- The `getExtensionsString()` function is inherited from the base Bake file mentioned in the [Ingredients](#ingredients) section -- The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pgvector`. But you can add any other extension you want. -- The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain more about this later. -- The `target` and the `tgt` have the same name. You can use whatever you want here as a name. -- The `pgVersion` variable is a list that contains basically the MAJOR.MINOR version of PostgreSQL. -- The `name` is the name that we will use later to refer to one element of the matrix that we created. -- The variable `args` lists all the arguments passed to the Dockerfile. We will talk more about this later. -- The function `getExtensionsString()` is inherited from the Bake file that we reference in the [Ingredients](#ingredients) section ### Step 2: Build the image @@ -97,11 +100,10 @@ We can now build the image using the following command: docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage ``` -This will, by default, build the image for the bake matrix we previously created, and will try to push the image to the registry at +This will build the image for the bake matrix we previously created, and will try to push the image to the registry at `localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain the full command: -As explained in the [Bake documentation about remote definitions](https://docs.docker.com/build/bake/remote-definition/) you can use a remote Bake definition with all the functions and default targets, and attach another local one to override -all the default values. +As outlined in the [Bake documentation on remote definitions](https://docs.docker.com/build/bake/remote-definition/), you can use a remote Bake file that includes functions and default targets, then attach a local Bake file to override any default values as needed. In the command above, `-f cwd://bake.hcl` is the local file that we created in Step 1, and `-f docker-bake.hcl` is the remote file in the git repo, that we're using to build the image. @@ -144,14 +146,12 @@ For example, the `pgvector` extension will be translated into `postgresql-16-pgvector,` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian Bookworm distribution. -When we add elements to, for example, the `args` variable, those elements are processed by the Bake file, and will be +When we add elements to, for example, the `args` variable, those elements are processed by the Docker bake command, and will be merged, meaning that the new elements will be added, and the existing ones will be overwritten. ### Dockerfile file -The Dockerfile is simply a heredoc string, because of the limitations of Bake to overwrite the remote Dockerfile with a -local one, but it allows us to change the FROM in the image, which means we can create an image that it's directly based -on the CloudNativePG images, and we can add the extensions we want to use in our image, without building all of them. +The Dockerfile is defined as a heredoc string due to Bake's limitation in overriding a remote Dockerfile with a local one. However, this approach still lets us modify the FROM directive, allowing us to base our image directly on the CloudNativePG images and add only the specific extensions we need—without rebuilding all of them. ## There's more! @@ -161,7 +161,6 @@ You may want to avoid building arm64 images by adding the following: platforms = ["linux/amd64"] ``` -This will overwrite the platforms variable and so, will build only for one platform. +This will override the platforms variable, so the image will be built for a single platform only. -Also, if you want to build everything into your own repository and manage the same tags, it's possible. In the future -we may write another post explaining this. +If you’d like to build everything into your own repository while managing the same tags, that’s also possible. We may cover that in a future post. From c5db89625a5c01573384a348772d8fd058ffe7da Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Thu, 17 Jul 2025 16:14:07 +0200 Subject: [PATCH 14/17] chore: more changes Signed-off-by: Jonathan Gonzalez V. --- content/blog/building-images-bake/index.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index e6eca9b7a..f1b8b8dd2 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -101,9 +101,11 @@ docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/clou ``` This will build the image for the bake matrix we previously created, and will try to push the image to the registry at -`localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain the full command: +`localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain +the full command: -As outlined in the [Bake documentation on remote definitions](https://docs.docker.com/build/bake/remote-definition/), you can use a remote Bake file that includes functions and default targets, then attach a local Bake file to override any default values as needed. +As outlined in the [Bake documentation on remote definitions](https://docs.docker.com/build/bake/remote-definition/), you can use a remote Bake file that includes +functions and default targets, then attach a local Bake file to override any default values as needed. In the command above, `-f cwd://bake.hcl` is the local file that we created in Step 1, and `-f docker-bake.hcl` is the remote file in the git repo, that we're using to build the image. @@ -151,16 +153,18 @@ merged, meaning that the new elements will be added, and the existing ones will ### Dockerfile file -The Dockerfile is defined as a heredoc string due to Bake's limitation in overriding a remote Dockerfile with a local one. However, this approach still lets us modify the FROM directive, allowing us to base our image directly on the CloudNativePG images and add only the specific extensions we need—without rebuilding all of them. +The Dockerfile is defined as a heredoc string due to Bake's limitation in overriding a remote Dockerfile with a local +one. However, this approach still lets us modify the FROM directive, allowing us to base our image directly on the +CloudNativePG images and add only the specific extensions we need—without rebuilding all of them. -## There's more! +## Making your images for specific architectures -You may want to avoid building arm64 images by adding the following: +By default, we build the images for `amd64` and `arm64` architectures, which is the recommended approach for most users. +However, if you want to build images for your specific architecture and so, saving some space, you can override the +`platforms` variable in your local Bake file. ```hcl platforms = ["linux/amd64"] ``` -This will override the platforms variable, so the image will be built for a single platform only. - If you’d like to build everything into your own repository while managing the same tags, that’s also possible. We may cover that in a future post. From 7b4da18bad579824ce1e159f8581df7f0e07e39e Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Thu, 17 Jul 2025 16:40:11 +0200 Subject: [PATCH 15/17] chore: more few changes and wrap to 80 cols when possible Signed-off-by: Jonathan Gonzalez V. --- content/blog/building-images-bake/index.md | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index f1b8b8dd2..f9a49de4b 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -2,9 +2,6 @@ title: "Creating a custom container image for CloudNativePG v2.0" date: 2025-07-22 draft: false -image: - url: - attribution: author: jgonzalez tags: - blog @@ -38,8 +35,6 @@ parallel. - A Bake file, using the one provided in the [CloudNativePG repository](https://github.com/cloudnative-pg/postgres-containers/blob/main/docker-bake.hcl) as a base. - A second, local Bake file to override the base configuration—this lets you apply your custom changes and build the container images accordingly. -Baking time: 5 minutes. - ## Instructions ### Step 1: Prepare local Bake file @@ -83,8 +78,10 @@ EOT There are a few important points to highlight: -- The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pgvector`, but you can add any others as needed. -- The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain why later. +- The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using + `pgvector`, but you can add any others as needed. +- The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain + why later. - The `target` and the `tgt` values share the same name, but you can use any name you prefer. - The `pgVersion` variable is a list specifying the PostgreSQL version(s) in MAJOR.MINOR format. - The `name` field is used to identify individual entries in the matrix we’ve defined. @@ -110,7 +107,8 @@ functions and default targets, then attach a local Bake file to override any def In the command above, `-f cwd://bake.hcl` is the local file that we created in Step 1, and `-f docker-bake.hcl` is the remote file in the git repo, that we're using to build the image. -You can explore more about all the content generated and used inside the Bake file by appending the `--print` flag, as in the following command: +You can explore more about all the content generated and used inside the Bake file by appending the `--print` flag, as +in the following command: ```bash docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage --print @@ -145,7 +143,7 @@ The `docker-bake.hcl` file contains a lot of functions that are used to build th This function, given the list of extensions we provided, will return a string of the extensions with the correct package name for a Debian-based distribution, in our case, Debian Bookworm. For example, the `pgvector` extension will be translated into -`postgresql-16-pgvector,` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian +`postgresql-16-pgvector`, which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian Bookworm distribution. When we add elements to, for example, the `args` variable, those elements are processed by the Docker bake command, and will be @@ -159,12 +157,13 @@ CloudNativePG images and add only the specific extensions we need—without rebu ## Making your images for specific architectures -By default, we build the images for `amd64` and `arm64` architectures, which is the recommended approach for most users. -However, if you want to build images for your specific architecture and so, saving some space, you can override the -`platforms` variable in your local Bake file. +By default, images are built for both `amd64` and `arm64` architectures, which is the recommended setup for most users. +However, if you want to target a specific architecture and reduce image size, you can override the `platforms` variable +in your local Bake file. ```hcl platforms = ["linux/amd64"] ``` -If you’d like to build everything into your own repository while managing the same tags, that’s also possible. We may cover that in a future post. +If you’d like to build everything into your own repository while managing the same tags, that’s also possible. +We may cover that in a future post. From bd1303b3a309354cf567c410a694808919e272bc Mon Sep 17 00:00:00 2001 From: Floor Drees Date: Wed, 23 Jul 2025 15:22:20 +0200 Subject: [PATCH 16/17] Update index.md with Jaime's suggestions Signed-off-by: Floor Drees --- content/blog/building-images-bake/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index f9a49de4b..2c3c2bd66 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -1,6 +1,6 @@ --- title: "Creating a custom container image for CloudNativePG v2.0" -date: 2025-07-22 +date: 2025-07-23 draft: false author: jgonzalez tags: @@ -39,7 +39,7 @@ parallel. ### Step 1: Prepare local Bake file -To build a custom image we add the following content in a local file with name [bake.hcl](bake.hcl): +To build a custom image we add the following content in a local file with name `bake.hcl`: ```hcl extensions = [ @@ -153,13 +153,13 @@ merged, meaning that the new elements will be added, and the existing ones will The Dockerfile is defined as a heredoc string due to Bake's limitation in overriding a remote Dockerfile with a local one. However, this approach still lets us modify the FROM directive, allowing us to base our image directly on the -CloudNativePG images and add only the specific extensions we need—without rebuilding all of them. +CloudNativePG images and add only the extensions we need—without rebuilding everything. ## Making your images for specific architectures By default, images are built for both `amd64` and `arm64` architectures, which is the recommended setup for most users. -However, if you want to target a specific architecture and reduce image size, you can override the `platforms` variable -in your local Bake file. +However, if you want to build images only for one specific architecture, saving some space, you can override the +`platforms` variable in your local Bake file. ```hcl platforms = ["linux/amd64"] From b4d9b87d36abef3c27ada77de9be1f8e64b4776e Mon Sep 17 00:00:00 2001 From: Floor Drees Date: Wed, 23 Jul 2025 15:24:01 +0200 Subject: [PATCH 17/17] Update index.md Signed-off-by: Floor Drees --- content/blog/building-images-bake/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/blog/building-images-bake/index.md b/content/blog/building-images-bake/index.md index 2c3c2bd66..62f9917aa 100644 --- a/content/blog/building-images-bake/index.md +++ b/content/blog/building-images-bake/index.md @@ -79,7 +79,7 @@ EOT There are a few important points to highlight: - The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using - `pgvector`, but you can add any others as needed. + `pgvector`, but you can add others as needed. - The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain why later. - The `target` and the `tgt` values share the same name, but you can use any name you prefer.