Skip to content

Commit 987aa90

Browse files
committed
dockerfiles: Allow passing arbitrary arguments to build.sh
To allow customizing the arguments passed to docker/podman build(x) beyond just the platform, modify build.sh to pass all its arguments through to the build command. For the platform case, this means it is now necessary to pass "--platform linux/arm64" instead of just "linux/arm64" so modify README.md to reflect this. This change also has the effect of automatically using buildx if supported, even if no arguments are passed, so move the information about buildx further up in the text. The link to podman's buildx is dropped as (unlike Docker) "podman buildx" is just an alias for "podman build". Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
1 parent a3c068f commit 987aa90

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

dockerfiles/README.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ Example showing how to build labgrid-client image:
2727
Using `BuildKit <https://docs.docker.com/develop/develop-images/build_enhancements/>`_
2828
is recommended to reduce build times.
2929

30-
You can also choose to build all 3 images,
31-
with the included script.
30+
You can also choose to build all 3 images with the included script. The script
31+
will automatically use `docker buildx
32+
<https://docs.docker.com/engine/reference/commandline/buildx/>`` if available.
3233

3334
.. code-block:: bash
3435
@@ -43,15 +44,13 @@ The script supports ``podman`` as well.
4344
$ ./dockerfiles/build.sh
4445
4546
It builds for the native platform by default. However, building
46-
for foreign platforms is also supported using `docker buildx
47-
<https://docs.docker.com/build/building/multi-platform/>` or `podman
48-
buildx <https://docs.podman.io/en/latest/markdown/podman-build.1.html>`
49-
by passing the platform of choice, e.g. `linux/arm64`.
47+
for foreign platforms is also supported by passing the platform(s) of choice,
48+
e.g. `linux/arm64` as an additional argument.
5049

5150
.. code-block:: bash
5251
5352
$ pip install --upgrade setuptools_scm
54-
$ ./dockerfiles/build.sh linux/arm64
53+
$ ./dockerfiles/build.sh --platform linux/arm64
5554
5655
5756
Usage

dockerfiles/build.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ perform_regular_build() {
5353
docker_cmd="${1}"
5454
script_dir="${2}"
5555
version="${3}"
56+
extra_args=("${@:4}")
5657

5758
log_info "building for native platform only."
5859

5960
for t in client exporter coordinator; do
6061
"${docker_cmd}" build --build-arg VERSION="${version}" \
61-
--target labgrid-${t} -t labgrid-${t}:latest -f "${script_dir}/Dockerfile" .
62+
--target labgrid-${t} -t labgrid-${t}:latest -f "${script_dir}/Dockerfile" \
63+
"${extra_args[@]}" .
6264
done
6365
}
6466

@@ -67,16 +69,17 @@ perform_docker_buildx_build() {
6769
docker_cmd="${1}"
6870
script_dir="${2}"
6971
version="${3}"
72+
extra_args=("${@:4}")
7073

7174
for t in client exporter coordinator; do
72-
"${docker_cmd}" buildx build --platform "${platform}" --build-arg VERSION="${version}" \
73-
--target labgrid-${t} -t labgrid-${t}:latest -f "${script_dir}/Dockerfile" .
75+
"${docker_cmd}" buildx build --build-arg VERSION="${version}" \
76+
--target labgrid-${t} -t labgrid-${t}:latest -f "${script_dir}/Dockerfile" \
77+
"${extra_args[@]}" .
7478
done
7579
}
7680

7781
main() {
78-
local platform script_dir version
79-
platform="${1}"
82+
local script_dir version
8083

8184
if ! has_docker && ! has_podman; then
8285
die "Neither docker nor podman could be found."
@@ -88,11 +91,11 @@ main() {
8891

8992
cd "${script_dir}/.." || die "Could not cd into repo root dir"
9093

91-
if has_buildx "${docker_cmd}" && [ -n "${platform}" ]; then
92-
perform_docker_buildx_build "${docker_cmd}" "${script_dir}" "${version}" "${platform}"
94+
if has_buildx "${docker_cmd}"; then
95+
perform_docker_buildx_build "${docker_cmd}" "${script_dir}" "${version}" "${@}"
9396
else
94-
perform_regular_build "${docker_cmd}" "${script_dir}" "${version}"
97+
perform_regular_build "${docker_cmd}" "${script_dir}" "${version}" "${@}"
9598
fi
9699
}
97100

98-
main "${1}"
101+
main "${@}"

0 commit comments

Comments
 (0)