Skip to content

Commit afe44ae

Browse files
committed
chore: some reviews
Signed-off-by: Jonathan Gonzalez V. <[email protected]>
1 parent db28c28 commit afe44ae

File tree

1 file changed

+12
-13
lines changed
  • content/blog/building-images-bake

1 file changed

+12
-13
lines changed

content/blog/building-images-bake/index.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ summary: Creating a container image for CloudNativePG Operator v2.0
2222
## Summary
2323
In an almost [two years old blog post]({{% ref "/blog/creating-container-images/" %}}), we explained how
2424
to build a custom container image for CloudNativePG. After two years, many things have changed in the world of containers.
25-
One of those things was the introduction of [Bake](https://www.docker.com/blog/bake/) in Docker, which allows you to build
25+
One of those things was the introduction of [Bake](https://docs.docker.com/build/) in Docker, which allows you to build
2626
images using a simple configuration file. Bake is now our recommended way to build images for CloudNativePG.
2727

2828
We will follow a simple cooking recipe to create a custom container image or a set of container images, since Bake
2929
allows you to build multiple images at once in a simple way.
3030

3131
## Ingredients
3232

33-
- 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)
33+
- 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)
3434

3535
Cooking time: 5 minutes.
3636

3737
## Instructions
3838

39-
### Step 1: Prepare local bake file
39+
### Step 1: Prepare local Bake file
4040

41-
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
41+
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
4242

4343
```hcl
4444
extensions = [
@@ -84,7 +84,7 @@ There are a few things that we should remark here:
8484
- The `pgVersion` is a variable list that contains basically, the MAJOR.MINOR version of PostgreSQL
8585
- The `name` is the name that we will use later to refer to one element of the matrix that we created
8686
- The `args` lists all the arguments passed to the Dockerfile. We will talk more about this later.
87-
- The function `getExtensionsString()` is inherited from the bake file that we reference in the [Ingredients](#ingredients) section
87+
- The function `getExtensionsString()` is inherited from the Bake file that we reference in the [Ingredients](#ingredients) section
8888

8989
### Step 2: Build the image
9090

@@ -94,15 +94,15 @@ We can now build the image using the following command:
9494
docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage
9595
```
9696
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
97-
`localhost:5000`, which is the default registry defined for testing environments in the parent bake file. Let's explain the full command first.
97+
`localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain the full command first.
9898

9999
As is defined in the [Bake documentation about remote definitions](https://docs.docker.com/build/bake/remote-definition/)
100-
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
100+
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
101101
all the default values.
102102
In the command above, `-f cwd://bake.hcl` is the local file that we created in the previous step, and
103103
`-f docker-bake.hcl` is the remote file that we're using to build the image, which is in the git repo.
104104

105-
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:
105+
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:
106106

107107
```bash
108108
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.
117117
```
118118

119119
The previous command will push the images in the following format: `your/registry:5000/postgresql-testing:17-standard-bookworm`.
120-
Using the `--print` flag you can explore the full list of tags created that are in the parent bake file.
120+
Using the `--print` flag you can explore the full list of tags created that are in the parent Bake file.
121121

122122
### Step 4: Serve the image
123123

@@ -131,7 +131,7 @@ But, how does this magic happen? Let's take a look at the Bake and the Docker fi
131131

132132
### Bake file
133133

134-
This is the base of our magic, but that magic starts in our postgres-containers repository, where we have a `docker-bake.hcl` file
134+
This is where the magic starts with our postgres-containers repository, where we have a `docker-bake.hcl` file
135135
that is being used to build the images provided by the CloudNativePG project, and it's the base for our custom Bake file.
136136

137137
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
141141
`postgresql-16-pgvector` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian
142142
Bookworm distribution.
143143

144-
Even the variables that are passed in the `args` variable to the Dockerfile are processed by the Bake file, in this case,
145-
the variables we add, are being added and the ones we overwrite are being overwritten, so we can use the same variables
146-
and content used in the parent Bake file.
144+
When we add elements to, for example, the `args` variable, those variables are processed by the Bake file, and will be
145+
merged, meaning that the non existent variables will be added, and the existing ones will be overwritten.
147146

148147
### Dockerfile file
149148

0 commit comments

Comments
 (0)