Skip to content

Commit e960a19

Browse files
committed
build system: simplify docker image pinning
It turns out that the ID mechanics of docker are even more crazy than realized before: On Linux (x86_64) they use a different SHA256 when referring to a locally installed image than when referring to the same image at dockerhub. On Mac OS (Apple Silicon), the use the repo SHA256 also when referring to the local image. Instead of increasing the complexity of the current solution even more by covering both cases, we now use `docker.io/riot/riotbuild@sha256:<SHA256_OF_DOCKERHUB_IMAGE>` to refer to a specific docker image, which hopefully works across systems. Instead of pulling the image explicitly, we now can rely on docker to do so automatically if the pinned image is not found locally. As a result, the knob to disable automatic pulling has been dropped. Fixes #20853
1 parent 85172ed commit e960a19

File tree

3 files changed

+7
-39
lines changed

3 files changed

+7
-39
lines changed

dist/tools/buildsystem_sanity_check/check.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,20 +382,12 @@ check_tests_application_path() {
382382
}
383383

384384
check_pinned_docker_version_is_up_to_date() {
385-
local pinned_digest
386385
local pinned_repo_digest
387-
local upstream_digest
388386
local upstream_repo_digest
389-
pinned_digest="$(awk '/^DOCKER_TESTED_IMAGE_ID := (.*)$/ { print substr($0, index($0, $3)); exit }' "$RIOTMAKE/docker.inc.mk")"
390387
pinned_repo_digest="$(awk '/^DOCKER_TESTED_IMAGE_REPO_DIGEST := (.*)$/ { print substr($0, index($0, $3)); exit }' "$RIOTMAKE/docker.inc.mk")"
391388
# not using docker and jq here but a python script to not have to install
392389
# more stuff for the static test docker image
393-
IFS=' ' read -r upstream_digest upstream_repo_digest <<< "$("$RIOTTOOLS/buildsystem_sanity_check/get_dockerhub_digests.py" "riot/riotbuild")"
394-
395-
if [ "$pinned_digest" != "$upstream_digest" ]; then
396-
git -C "${RIOTBASE}" grep -n '^DOCKER_TESTED_IMAGE_ID :=' "$RIOTMAKE/docker.inc.mk" \
397-
| error_with_message "Update docker image SHA256 to ${upstream_digest}"
398-
fi
390+
IFS=' ' read -r upstream_repo_digest <<< "$("$RIOTTOOLS/buildsystem_sanity_check/get_dockerhub_digests.py" "riot/riotbuild")"
399391

400392
if [ "$pinned_repo_digest" != "$upstream_repo_digest" ]; then
401393
git -C "${RIOTBASE}" grep -n '^DOCKER_TESTED_IMAGE_REPO_DIGEST :=' "$RIOTMAKE/docker.inc.mk" \

dist/tools/buildsystem_sanity_check/get_dockerhub_digests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ def get_upstream_digests(repo, tag="latest", token=None):
8787
if len(sys.argv) != 2:
8888
sys.exit(f"Usage {sys.argv[0]} <REPO_NAME>")
8989

90-
digest, repo_digest = get_upstream_digests(sys.argv[1])
91-
print(f"{digest} {repo_digest}")
90+
_, repo_digest = get_upstream_digests(sys.argv[1])
91+
print(f"{repo_digest}")

makefiles/docker.inc.mk

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
# When the docker image is updated, checks at
66
# dist/tools/buildsystem_sanity_check/check.sh start complaining in CI, and
77
# provide the latest values to verify and fill in.
8-
DOCKER_TESTED_IMAGE_ID := 1329f419ec1a045a5830361f288536a56a0671a3b0db216e469369b00719cdff
98
DOCKER_TESTED_IMAGE_REPO_DIGEST := d5a70c06703731ddfebb98e9227eb03a69f02c393d9e89bbbcd65d71f3ef056e
109

1110
DOCKER_PULL_IDENTIFIER := docker.io/riot/riotbuild@sha256:$(DOCKER_TESTED_IMAGE_REPO_DIGEST)
12-
DOCKER_IMAGE_DEFAULT := sha256:$(DOCKER_TESTED_IMAGE_ID)
13-
DOCKER_AUTO_PULL ?= 1
14-
export DOCKER_IMAGE ?= $(DOCKER_IMAGE_DEFAULT)
11+
export DOCKER_IMAGE ?= $(DOCKER_PULL_IDENTIFIER)
1512
export DOCKER_BUILD_ROOT ?= /data/riotbuild
1613
DOCKER_RIOTBASE ?= $(DOCKER_BUILD_ROOT)/riotbase
1714

@@ -39,25 +36,6 @@ else
3936
export INSIDE_DOCKER := 0
4037
endif
4138

42-
ifeq (0:1,$(INSIDE_DOCKER):$(BUILD_IN_DOCKER))
43-
ifeq ($(DOCKER_IMAGE),$(DOCKER_IMAGE_DEFAULT))
44-
IMAGE_PRESENT:=$(shell $(DOCKER) image inspect $(DOCKER_IMAGE) 2>/dev/null >/dev/null && echo 1 || echo 0)
45-
ifeq (0,$(IMAGE_PRESENT))
46-
$(warning Required docker image $(DOCKER_IMAGE) not installed)
47-
ifeq (1,$(DOCKER_AUTO_PULL))
48-
$(info Pulling required image automatically. You can disable this with DOCKER_AUTO_PULL=0)
49-
DEPS_FOR_RUNNING_DOCKER += docker-pull
50-
else
51-
$(info Building with latest available riotbuild image. You can pull the correct image automatically with DOCKER_AUTO_PULL=1)
52-
# The currently set DOCKER_IMAGE is not locally available, and the
53-
# user opted out to automatically pull it. Fall back to the
54-
# latest (locally) available riot/riotbuild image instead.
55-
export DOCKER_IMAGE := docker.io/riot/riotbuild:latest
56-
endif
57-
endif
58-
endif
59-
endif
60-
6139
# Default target for building inside a Docker container if nothing was given
6240
export DOCKER_MAKECMDGOALS ?= all
6341
# List of all exported environment variables that shall be passed on to the
@@ -164,6 +142,9 @@ DOCKER_USER ?= $$(id -u)
164142
DOCKER_USER_OPT = $(if $(_docker_is_podman),--userns keep-id,--user $(DOCKER_USER))
165143
DOCKER_RUN_FLAGS ?= --rm --tty $(DOCKER_USER_OPT)
166144

145+
# Explicitly set the platform to what the image is expecting
146+
DOCKER_RUN_FLAGS += --platform linux/amd64
147+
167148
# allow setting make args from command line like '-j'
168149
DOCKER_MAKE_ARGS ?=
169150

@@ -378,11 +359,6 @@ docker_run_make = \
378359
-w '$(DOCKER_APPDIR)' '$2' \
379360
$(MAKE) $(DOCKER_OVERRIDE_CMDLINE) $4 $1
380361

381-
# This target pulls the docker image required for BUILD_IN_DOCKER
382-
.PHONY: docker-pull
383-
docker-pull:
384-
$(DOCKER) pull '$(DOCKER_PULL_IDENTIFIER)'
385-
386362
# This will execute `make $(DOCKER_MAKECMDGOALS)` inside a Docker container.
387363
# We do not push the regular $(MAKECMDGOALS) to the container's make command in
388364
# order to only perform building inside the container and defer executing any

0 commit comments

Comments
 (0)