Skip to content

Commit cb2a26b

Browse files
jsilvelasxd
authored andcommitted
chore: some clarifications and corrections
Signed-off-by: Jaime Silvela <[email protected]>
1 parent afe44ae commit cb2a26b

File tree

1 file changed

+20
-19
lines changed
  • content/blog/building-images-bake

1 file changed

+20
-19
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ 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://docs.docker.com/build/) in Docker, which allows you to build
25+
One of those things has been 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
@@ -80,10 +80,10 @@ There are a few things that we should remark here:
8080
- The `extensions` variable is a list of extensions that we want to include in the image. In our recipe we are using `pg_vector`,
8181
but you can add any other extension that you want to include in the image.
8282
- The `dockerfile-inline` variable contains our Dockerfile definition, which cannot be used remotely. We will explain more about this later.
83-
- The `target` and the `tgt` have the same name, you can use what ever you want here as a name
84-
- The `pgVersion` is a variable list that contains basically, the MAJOR.MINOR version of PostgreSQL
83+
- The `target` and the `tgt` have the same name, you can use whatever you want here as a name
84+
- The `pgVersion` variable is a 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
86-
- The `args` lists all the arguments passed to the Dockerfile. We will talk more about this later.
86+
- The variable `args` lists all the arguments passed to the Dockerfile. We will talk more about this later.
8787
- The function `getExtensionsString()` is inherited from the Bake file that we reference in the [Ingredients](#ingredients) section
8888

8989
### Step 2: Build the image
@@ -93,14 +93,15 @@ We can now build the image using the following command:
9393
```bash
9494
docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/cloudnative-pg/postgres-containers.git" myimage
9595
```
96+
9697
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.
98+
`localhost:5000`, which is the default registry defined for testing environments in the parent Bake file. Let's explain the full command:
9899

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

105106
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:
106107

@@ -110,7 +111,7 @@ docker buildx bake -f docker-bake.hcl -f cwd://bake.hcl "https://github.com/clou
110111

111112
### Step 3: Push the image to a registry
112113

113-
Now you just need to push the image to a registry, you can do this by using the following command:
114+
Now you just need to push the image to a registry. You can do this by using the following command:
114115

115116
```bash
116117
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.
126127

127128
## Deep dive into the Bake and Dockerfile
128129

129-
The simplicity of Bake to do even more stuff is amazing, and allows you to create custom images in a very simple way.
130+
The simplicity of Bake to do even more stuff is amazing, and allows you to create custom images easily.
130131
But, how does this magic happen? Let's take a look at the Bake and the Docker file.
131132

132133
### Bake file
133134

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

137-
The `docker-bake.hcl` file contains a lot of functions that are used to build the images, and one of them is the `getExtensionsString()`.
138-
This function, using the list of extensions we provided, will return a string of the extensions with the correct package name
138+
The `docker-bake.hcl` file contains a lot of functions that are used to build the images. One of them is the `getExtensionsString()`.
139+
This function, given the list of extensions we provided, will return a string of the extensions with the correct package name
139140
for a Debian-based distribution, in our case, Debian Bookworm.
140-
So the `pg_vector` extension will be translated into
141-
`postgresql-16-pgvector` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian
141+
For example, the `pg_vector` extension will be translated into
142+
`postgresql-16-pgvector,` which is the name of the package for pgvector extensions for PostgreSQL 16 in the Debian
142143
Bookworm distribution.
143144

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.
145+
When we add elements to, for example, the `args` variable, those elements are processed by the Bake file, and will be
146+
merged, meaning that the new elements will be added, and the existing ones will be overwritten.
146147

147148
### Dockerfile file
148149

149-
The Dockerfile is simple an inline content, because of the limitations of Bake to overwrite the remote Dockerfile with a
150+
The Dockerfile is simply a heredoc string, because of the limitations of Bake to overwrite the remote Dockerfile with a
150151
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
151-
on the CloudNativePG images, and we can add the extensions we want to use in our image, without building all of them
152+
on the CloudNativePG images, and we can add the extensions we want to use in our image, without building all of them.
152153

153154
## There's more!
154155

0 commit comments

Comments
 (0)