Skip to content

Commit fb862b9

Browse files
Merge pull request #3186 from balena-io/alanb128-balenalib-cleanup7
Update dockerfile.template section of develop/dockerfile/
2 parents 8f413c0 + 4f296fc commit fb862b9

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

.cspell/balena-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ balena-build
66
balena-builder
77
balenacli
88
balenahup
9+
balenalabs
910
balenalib
1011
balenista
1112
balenistas

.cspell/computer-terms.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ toidentifier
414414
tooltipped
415415
topo
416416
TOTP
417+
trixie
417418
tuneables
418419
typer
419420
tzdata
@@ -461,4 +462,4 @@ yallist
461462
yocto
462463
Yocto
463464
zenbook
464-
zerotier
465+
zerotier

pages/learn/develop/dockerfile.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,23 @@ __Note:__ You *don't* need to worry about ignoring `.git` as the builders alread
6767

6868
## Dockerfile templates
6969

70-
One of the goals of {{ $names.company.lower }} is code portability and ease of use, so you can easily manage and deploy a whole fleet of different devices. This is why Docker containers were such a natural choice. However, there are cases where Dockerfiles fall short and can't easily target multiple different device architectures.
70+
Dockerfile templates are a balena-specific feature that allow our builders to substitute a value for one of the following variables at build time:
7171

72-
To allow our builders to build containers for multiple architectures from one code repository, we implemented simple Dockerfile templates.
72+
{{> "deployment/build-variables" }}
73+
74+
The original purpose of these templates was to allow our builders to build containers for multiple architectures from one code repository when using the deprecated balenalib base images. For new projects, we recommend using standard Dockerfiles and either specifying the architecture in your FROM line, or utilizing base images that are published with the [multi-platform feature](https://docs.docker.com/build/building/multi-platform/). For example:
75+
76+
`FROM bh.cr/balenalabs/browser-aarch64`
77+
78+
Here, we are pulling an ARMv8 (aarch64) architecture-specific container image. This image can only be used for fleets with devices of that architecture.
79+
80+
`FROM debian:trixie`
81+
82+
This Debian Official Docker image is a multi-arch image instead. Upon build time, the balena builders would pull the correct architecture of the image based on the default device type of your fleet. This reduces complexity and provides a similar feature set to Dockerfile templates in the past.
7383

74-
It is now possible to define a `Dockerfile.template` file that looks like this:
84+
It is possible to have different device types in the same fleet, as long as they have the same or compatible architectures. You need to ensure that your packages and modules are also available in that target architecture, otherwise, your application might throw errors or fail during runtime.
85+
86+
If you are still using balenalib base images for an existing project, you can use dockerfile templates as described below:
7587

7688
```Dockerfile
7789
FROM {{ $names.base_images.lib }}/%%{{ $names.company.allCaps }}_MACHINE_NAME%%-node
@@ -83,22 +95,16 @@ COPY src/ /usr/src/app
8395
CMD ["node", "/usr/src/app/main.js"]
8496
```
8597

86-
This template will build and deploy a Node.js project for any of the devices supported by {{ $names.company.lower }}, regardless of whether the device architecture is [ARM][ARM-link] or [x86][x86-link].
87-
In this example, you can see the build variable `%%{{ $names.company.allCaps }}_MACHINE_NAME%%`. This will be replaced by the machine name (i.e.: `raspberry-pi`) at build time. See below for a list of machine names.
88-
89-
The machine name is inferred from the device type of the fleet you are deploying on. So if you have a NanoPi Neo Air fleet, the machine name will be `nanopi-neo-air` and an `armv7hf` architecture base image will be built.
90-
91-
__Note:__ You need to ensure that your dependencies and Node.js modules are also multi-architecture, otherwise you will have a bad time.
98+
This `dockerfile.template` file will build and deploy a Node.js project for any of the devices supported by {{ $names.company.lower }}, regardless of device architecture, whether is [ARM][ARM-link] or [x86][x86-link].
9299

93-
Currently our builder supports the following build variables:
100+
In this example, the build variable `%%{{ $names.company.allCaps }}_MACHINE_NAME%%`. This will be replaced by the machine name (i.e.: `raspberry-pi`) at build time. Refer to [supported machine names and architectures][supported-devices].
94101

95-
{{> "deployment/build-variables" }}
102+
The machine name is inferred from the device type of the fleet you are deploying on. So if you have a NanoPi Neo Air fleet, the machine name will be `nanopi-neo-air` and an `armv7hf` architecture base image will be built.
96103

97104
__Note:__ If your fleet contains devices of different types, the `%%{{ $names.company.allCaps }}_MACHINE_NAME%%` build variable **will not** evaluate correctly for all devices. Your fleet services are built once for all devices, and the `%%{{ $names.company.allCaps }}_MACHINE_NAME%%` variable will pull from the device type associated with the fleet, rather than the target device. In this scenario, you can use `%%{{ $names.company.allCaps }}_ARCH%%` to pull a base image that matches the shared architecture of the devices in your fleet.
98105

99106
If you want to see an example of build variables in action, have a look at this [basic openssh example]({{ $links.githubPlayground }}/balena-openssh).
100107

101-
Here are the [supported machine names and architectures][supported-devices].
102108

103109
## Multiple Dockerfiles
104110

@@ -214,4 +220,4 @@ The {{ $names.company.lower }} Supervisor requires that the directory `/tmp/bale
214220
[aptitude]:https://wiki.debian.org/Aptitude
215221

216222
[services-masterclass]:/learn/more/masterclasses/services-masterclass/
217-
[update-locks]:/learn/deploy/release-strategy/update-locking/
223+
[update-locks]:/learn/deploy/release-strategy/update-locking/

0 commit comments

Comments
 (0)