Skip to content

Commit 6dc6012

Browse files
committed
Merge bitcoin/bitcoin#31657: ci: Supply --platform argument to docker commands.
6e29de2 ci: Supply `platform` argument to docker commands. (David Gumberg) Pull request description: I ran into this issue when following the instructions in `ci/README.md` for running CI locally. Newer versions of docker require a `--platform` argument when building from a platform-specific image that differs from the host platform, I'm not sure when this change took place, but trying to build any of the cross-platform CI images on Docker 27.5.0 fails in the following manner: ```console $ # From ci/README.md $ env -i HOME="$HOME" PATH="$PATH" USER="$USER" bash -c 'FILE_ENV="./ci/test/00_setup_env_arm.sh" ./ci/test_run_all.sh' WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64/v4) and no specific platform was requested Creating docker.io/arm64v8/debian:bookworm container to run in + docker build --file $BITCOIN_SRC/ci/test_imagefile --build-arg CI_IMAGE_NAME_TAG=docker.io/arm64v8/debian:bookworm --build-arg FILE_ENV=./ci/test/00_setup_env_arm.sh --label=bitcoin-ci-test --tag=ci_arm_linux $BITCOIN_SRC [+] Building 0.6s (2/2) FINISHED docker:default => [internal] load build definition from test_imagefile 0.0s => => transferring dockerfile: 600B 0.0s => WARN: InvalidDefaultArgInFrom: Default value for ARG ${CI_IMAGE_NAME_TAG} results in empty or invalid base image name (line 8) 0.0s => ERROR [internal] load metadata for docker.io/arm64v8/debian:bookworm 0.5s ------ > [internal] load metadata for docker.io/arm64v8/debian:bookworm: ------ 1 warning found (use docker --debug to expand): - InvalidDefaultArgInFrom: Default value for ARG ${CI_IMAGE_NAME_TAG} results in empty or invalid base image name (line 8) test_imagefile:8 -------------------- 6 | 7 | ARG CI_IMAGE_NAME_TAG 8 | >>> FROM ${CI_IMAGE_NAME_TAG} 9 | 10 | ARG FILE_ENV -------------------- ERROR: failed to solve: docker.io/arm64v8/debian:bookworm: failed to resolve source metadata for docker.io/arm64v8/debian:bookworm: no match for platform in manifest: not found ``` This branch fixes this by setting the `--platform` argument of `docker build` and `docker run` with an environment variable `CI_IMAGE_PLATFORM` for each platform specific job, and `linux/{$cpuarch}` for any native jobs. Thi ## Steps to reproduce 1. Install relevant dependencies, on Ubuntu: ```bash sudo apt install bash docker.io python3 qemu-user-static ``` 2. Run one of the platform-specific CI images, e.g.: ```bash env -i HOME="$HOME" PATH="$PATH" USER="$USER" bash -c 'FILE_ENV="./ci/test/00_setup_env_arm.sh" ./ci/test_run_all.sh' ``` ACKs for top commit: maflcko: lgtm ACK 6e29de2 hebasto: ACK 6e29de2 Tree-SHA512: 81b9fa8ec1f3d21619d37d864047c8d7917ef2c8536851f80facf7f1973dfe14628d7755f12d2a9c6edebb6cb16877c582d4d41cdab52b73b23c44f08c6e6b30
2 parents 4e52a63 + 6e29de2 commit 6dc6012

File tree

6 files changed

+14
-5
lines changed

6 files changed

+14
-5
lines changed

ci/test/00_setup_env.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ export CI_BASE_PACKAGES=${CI_BASE_PACKAGES:-build-essential pkgconf curl ca-cert
6868
export GOAL=${GOAL:-install}
6969
export DIR_QA_ASSETS=${DIR_QA_ASSETS:-${BASE_SCRATCH_DIR}/qa-assets}
7070
export CI_RETRY_EXE=${CI_RETRY_EXE:-"retry --"}
71+
72+
# The --platform argument used with `docker build` and `docker run`.
73+
export CI_IMAGE_PLATFORM=${CI_IMAGE_PLATFORM:-"linux"} # Force linux, but use native arch by default

ci/test/00_setup_env_arm.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export HOST=arm-linux-gnueabihf
1010
export DPKG_ADD_ARCH="armhf"
1111
export PACKAGES="python3-zmq g++-arm-linux-gnueabihf busybox libc6:armhf libstdc++6:armhf libfontconfig1:armhf libxcb1:armhf"
1212
export CONTAINER_NAME=ci_arm_linux
13-
export CI_IMAGE_NAME_TAG="docker.io/arm64v8/debian:bookworm" # Check that https://packages.debian.org/bookworm/g++-arm-linux-gnueabihf (version 12.2, similar to guix) can cross-compile
13+
export CI_IMAGE_NAME_TAG="docker.io/debian:bookworm" # Check that https://packages.debian.org/bookworm/g++-arm-linux-gnueabihf (version 12.2, similar to guix) can cross-compile
14+
export CI_IMAGE_PLATFORM="linux/arm64"
1415
export USE_BUSY_BOX=true
1516
export RUN_UNIT_TESTS=true
1617
export RUN_FUNCTIONAL_TESTS=false

ci/test/00_setup_env_i686_multiprocess.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export LC_ALL=C.UTF-8
88

99
export HOST=i686-pc-linux-gnu
1010
export CONTAINER_NAME=ci_i686_multiprocess
11-
export CI_IMAGE_NAME_TAG="docker.io/amd64/ubuntu:24.04"
11+
export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04"
12+
export CI_IMAGE_PLATFORM="linux/amd64"
1213
export PACKAGES="llvm clang g++-multilib"
1314
export DEP_OPTS="DEBUG=1 MULTIPROCESS=1"
1415
export GOAL="install"

ci/test/00_setup_env_s390x.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export LC_ALL=C.UTF-8
99
export HOST=s390x-linux-gnu
1010
export PACKAGES="python3-zmq"
1111
export CONTAINER_NAME=ci_s390x
12-
export CI_IMAGE_NAME_TAG="docker.io/s390x/ubuntu:24.04"
12+
export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04"
13+
export CI_IMAGE_PLATFORM="linux/s390x"
1314
export TEST_RUNNER_EXTRA="--exclude rpc_bind,feature_bind_extra" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547
1415
export RUN_FUNCTIONAL_TESTS=true
1516
export GOAL="install"

ci/test/00_setup_env_win64.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
export LC_ALL=C.UTF-8
88

99
export CONTAINER_NAME=ci_win64
10-
export CI_IMAGE_NAME_TAG="docker.io/amd64/debian:bookworm" # Check that https://packages.debian.org/bookworm/g++-mingw-w64-x86-64-posix (version 12.2, similar to guix) can cross-compile
10+
export CI_IMAGE_NAME_TAG="docker.io/debian:bookworm" # Check that https://packages.debian.org/bookworm/g++-mingw-w64-x86-64-posix (version 12.2, similar to guix) can cross-compile
11+
export CI_IMAGE_PLATFORM="linux/amd64"
1112
export HOST=x86_64-w64-mingw32
1213
export DPKG_ADD_ARCH="i386"
1314
export PACKAGES="nsis g++-mingw-w64-x86-64-posix wine-binfmt wine64 wine32 file"

ci/test/02_run_container.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
1414
# Though, exclude those with newlines to avoid parsing problems.
1515
python3 -c 'import os; [print(f"{key}={value}") for key, value in os.environ.items() if "\n" not in value and "HOME" != key and "PATH" != key and "USER" != key]' | tee "/tmp/env-$USER-$CONTAINER_NAME"
1616
# System-dependent env vars must be kept as is. So read them from the container.
17-
docker run --rm "${CI_IMAGE_NAME_TAG}" bash -c "env | grep --extended-regexp '^(HOME|PATH|USER)='" | tee --append "/tmp/env-$USER-$CONTAINER_NAME"
17+
docker run --platform="${CI_IMAGE_PLATFORM}" --rm "${CI_IMAGE_NAME_TAG}" bash -c "env | grep --extended-regexp '^(HOME|PATH|USER)='" | tee --append "/tmp/env-$USER-$CONTAINER_NAME"
1818

1919
# Env vars during the build can not be changed. For example, a modified
2020
# $MAKEJOBS is ignored in the build process. Use --cpuset-cpus as an
@@ -31,6 +31,7 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
3131
--build-arg "CI_IMAGE_NAME_TAG=${CI_IMAGE_NAME_TAG}" \
3232
--build-arg "FILE_ENV=${FILE_ENV}" \
3333
$MAYBE_CPUSET \
34+
--platform="${CI_IMAGE_PLATFORM}" \
3435
--label="${CI_IMAGE_LABEL}" \
3536
--tag="${CONTAINER_NAME}" \
3637
"${BASE_READ_ONLY_DIR}"
@@ -100,6 +101,7 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
100101
--env-file /tmp/env-$USER-$CONTAINER_NAME \
101102
--name "$CONTAINER_NAME" \
102103
--network ci-ip6net \
104+
--platform="${CI_IMAGE_PLATFORM}" \
103105
"$CONTAINER_NAME")
104106
export CI_CONTAINER_ID
105107
export CI_EXEC_CMD_PREFIX="docker exec ${CI_CONTAINER_ID}"

0 commit comments

Comments
 (0)