Skip to content

Commit a667cd8

Browse files
committed
Adjust "hack/make/.detect-daemon-osarch" to be the source of truth for "platform detection"
Instead of being split between three files, let's let `hack/make/.detect-daemon-osarch` be our single source of truth for multiarch detection/vars. Not only does it make it slightly easier to make sure we change everything properly when these bits have to change, but it also makes it so that all bits of `hack/make.sh` (especially `hack/make/.ensure-frozen-images`) work properly outside the context of the `Makefile` on all platforms. Signed-off-by: Andrew "Tianon" Page <admwiggin@gmail.com>
1 parent 1d09425 commit a667cd8

File tree

3 files changed

+53
-63
lines changed

3 files changed

+53
-63
lines changed

Makefile

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
.PHONY: all binary build cross default docs docs-build docs-shell shell test test-docker-py test-integration-cli test-unit validate
22

33
# get OS/Arch of docker engine
4-
DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH:+$$DOCKER_CLIENT_OSARCH}')
5-
# default for linux/amd64 and others
6-
DOCKERFILE := Dockerfile
7-
# switch to different Dockerfile for linux/arm
8-
ifeq ($(DOCKER_OSARCH), linux/arm)
9-
DOCKERFILE := Dockerfile.armhf
10-
else
11-
ifeq ($(DOCKER_OSARCH), linux/arm64)
12-
DOCKERFILE := Dockerfile.aarch64
13-
else
14-
ifeq ($(DOCKER_OSARCH), linux/ppc64le)
15-
DOCKERFILE := Dockerfile.ppc64le
16-
else
17-
ifeq ($(DOCKER_OSARCH), linux/s390x)
18-
DOCKERFILE := Dockerfile.s390x
19-
else
20-
ifeq ($(DOCKER_OSARCH), windows/amd64)
21-
DOCKERFILE := Dockerfile.windows
22-
endif
23-
endif
24-
endif
25-
endif
26-
endif
27-
export DOCKERFILE
4+
DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH:-$$DOCKER_CLIENT_OSARCH}')
5+
DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}')
286

297
# env vars passed through directly to Docker's build scripts
308
# to allow things like `make DOCKER_CLIENTONLY=1 binary` easily
@@ -37,7 +15,6 @@ DOCKER_ENVS := \
3715
-e DOCKER_CLIENTONLY \
3816
-e DOCKER_DEBUG \
3917
-e DOCKER_EXPERIMENTAL \
40-
-e DOCKERFILE \
4118
-e DOCKER_GRAPHDRIVER \
4219
-e DOCKER_INCREMENTAL_BINARY \
4320
-e DOCKER_REMAP_ROOT \

hack/make/.detect-daemon-osarch

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,63 @@
11
#!/bin/bash
22
set -e
33

4+
docker-version-osarch() {
5+
local target="$1" # "Client" or "Server"
6+
local fmtStr="{{.${target}.Os}}/{{.${target}.Arch}}"
7+
if docker version -f "$fmtStr" 2>/dev/null; then
8+
# if "docker version -f" works, let's just use that!
9+
return
10+
fi
11+
docker version | awk '
12+
$1 ~ /^(Client|Server):$/ { section = 0 }
13+
$1 == "'"$target"':" { section = 1; next }
14+
section && $1 == "OS/Arch:" { print $2 }
15+
'
16+
}
17+
418
# Retrieve OS/ARCH of docker daemon, eg. linux/amd64
5-
export DOCKER_ENGINE_OSARCH="$(docker version | awk '
6-
$1 == "Client:" { server = 0; next }
7-
$1 == "Server:" { server = 1; next }
8-
server && $1 == "OS/Arch:" { print $2 }
9-
')"
19+
export DOCKER_ENGINE_OSARCH="$(docker-version-osarch 'Server')"
1020
export DOCKER_ENGINE_GOOS="${DOCKER_ENGINE_OSARCH%/*}"
1121
export DOCKER_ENGINE_GOARCH="${DOCKER_ENGINE_OSARCH##*/}"
1222
DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:=amd64}
1323

1424
# and the client, just in case
15-
export DOCKER_CLIENT_OSARCH="$(docker version | awk '
16-
$1 == "Client:" { client = 1; next }
17-
$1 == "Server:" { client = 0; next }
18-
client && $1 == "OS/Arch:" { print $2 }
19-
')"
25+
export DOCKER_CLIENT_OSARCH="$(docker-version-osarch 'Client')"
26+
export DOCKER_CLIENT_GOOS="${DOCKER_CLIENT_OSARCH%/*}"
27+
export DOCKER_CLIENT_GOARCH="${DOCKER_CLIENT_OSARCH##*/}"
28+
DOCKER_CLIENT_GOARCH=${DOCKER_CLIENT_GOARCH:=amd64}
2029

2130
# Retrieve the architecture used in contrib/builder/(deb|rpm)/$PACKAGE_ARCH/
22-
PACKAGE_ARCH="amd64"
23-
case "$DOCKER_ENGINE_OSARCH" in
24-
linux/arm)
31+
PACKAGE_ARCH='amd64'
32+
case "${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}" in
33+
arm)
2534
PACKAGE_ARCH='armhf'
2635
;;
27-
linux/ppc64le)
28-
PACKAGE_ARCH='ppc64le'
36+
arm64)
37+
PACKAGE_ARCH='aarch64'
38+
;;
39+
amd64|ppc64le|s390x)
40+
PACKAGE_ARCH="${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}"
2941
;;
30-
linux/s390x)
31-
PACKAGE_ARCH='s390x'
42+
*)
43+
echo >&2 "warning: not sure how to convert '$DOCKER_ENGINE_GOARCH' to a 'Docker' arch, assuming '$PACKAGE_ARCH'"
3244
;;
3345
esac
3446
export PACKAGE_ARCH
47+
48+
DOCKERFILE='Dockerfile'
49+
TEST_IMAGE_NAMESPACE=
50+
case "$PACKAGE_ARCH" in
51+
amd64)
52+
case "${DOCKER_ENGINE_GOOS:-$DOCKER_CLIENT_GOOS}" in
53+
windows)
54+
DOCKERFILE='Dockerfile.windows'
55+
;;
56+
esac
57+
;;
58+
*)
59+
DOCKERFILE="Dockerfile.$PACKAGE_ARCH"
60+
TEST_IMAGE_NAMESPACE="$PACKAGE_ARCH"
61+
;;
62+
esac
63+
export DOCKERFILE TEST_IMAGE_NAMESPACE

hack/make/.ensure-frozen-images

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,9 @@ images=(
99
hello-world:latest
1010
)
1111

12-
imagePrefix=
13-
case "$DOCKER_ENGINE_OSARCH" in
14-
linux/arm)
15-
imagePrefix='armhf'
16-
;;
17-
linux/arm64)
18-
imagePrefix='aarch64'
19-
;;
20-
linux/ppc64le)
21-
imagePrefix='ppc64le'
22-
;;
23-
linux/s390x)
24-
imagePrefix='s390x'
25-
;;
26-
esac
27-
28-
if [ "$imagePrefix" ]; then
12+
if [ "$TEST_IMAGE_NAMESPACE" ]; then
2913
for (( i = 0; i < ${#images[@]}; i++ )); do
30-
images[$i]="$imagePrefix/${images[$i]}"
14+
images[$i]="$TEST_IMAGE_NAMESPACE/${images[$i]}"
3115
done
3216
fi
3317

@@ -58,17 +42,17 @@ if ! docker inspect "${images[@]}" &> /dev/null; then
5842
inCont = 0;
5943
}
6044
}
61-
' "${DOCKERFILE:=Dockerfile}" | sh -x
45+
' "$DOCKERFILE" | sh -x
6246
# Do not use a subshell for the following command. Windows to Linux CI
6347
# runs bash 3.x so will not trap an error in a subshell.
6448
# http://stackoverflow.com/questions/22630363/how-does-set-e-work-with-subshells
6549
set -x; tar -cC "$dir" . | docker load; set +x
6650
fi
6751
fi
6852

69-
if [ "$imagePrefix" ]; then
53+
if [ "$TEST_IMAGE_NAMESPACE" ]; then
7054
for image in "${images[@]}"; do
71-
target="${image#$imagePrefix/}"
55+
target="${image#$TEST_IMAGE_NAMESPACE/}"
7256
if [ "$target" != "$image" ]; then
7357
# tag images to ensure that all integrations work with the defined image names
7458
docker tag "$image" "$target"

0 commit comments

Comments
 (0)