mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #21108 from tianon/detect-daemon-osarch
Adjust "hack/make/.detect-daemon-osarch" to be the source of truth for "platform detection"
This commit is contained in:
commit
133b3cccb5
3 changed files with 56 additions and 63 deletions
27
Makefile
27
Makefile
|
@ -1,30 +1,8 @@
|
||||||
.PHONY: all binary build cross default docs docs-build docs-shell shell test test-docker-py test-integration-cli test-unit validate
|
.PHONY: all binary build cross default docs docs-build docs-shell shell test test-docker-py test-integration-cli test-unit validate
|
||||||
|
|
||||||
# get OS/Arch of docker engine
|
# get OS/Arch of docker engine
|
||||||
DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH:+$$DOCKER_CLIENT_OSARCH}')
|
DOCKER_OSARCH := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKER_ENGINE_OSARCH:-$$DOCKER_CLIENT_OSARCH}')
|
||||||
# default for linux/amd64 and others
|
DOCKERFILE := $(shell bash -c 'source hack/make/.detect-daemon-osarch && echo $${DOCKERFILE}')
|
||||||
DOCKERFILE := Dockerfile
|
|
||||||
# switch to different Dockerfile for linux/arm
|
|
||||||
ifeq ($(DOCKER_OSARCH), linux/arm)
|
|
||||||
DOCKERFILE := Dockerfile.armhf
|
|
||||||
else
|
|
||||||
ifeq ($(DOCKER_OSARCH), linux/arm64)
|
|
||||||
DOCKERFILE := Dockerfile.aarch64
|
|
||||||
else
|
|
||||||
ifeq ($(DOCKER_OSARCH), linux/ppc64le)
|
|
||||||
DOCKERFILE := Dockerfile.ppc64le
|
|
||||||
else
|
|
||||||
ifeq ($(DOCKER_OSARCH), linux/s390x)
|
|
||||||
DOCKERFILE := Dockerfile.s390x
|
|
||||||
else
|
|
||||||
ifeq ($(DOCKER_OSARCH), windows/amd64)
|
|
||||||
DOCKERFILE := Dockerfile.windows
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
export DOCKERFILE
|
|
||||||
|
|
||||||
# env vars passed through directly to Docker's build scripts
|
# env vars passed through directly to Docker's build scripts
|
||||||
# to allow things like `make DOCKER_CLIENTONLY=1 binary` easily
|
# to allow things like `make DOCKER_CLIENTONLY=1 binary` easily
|
||||||
|
@ -37,7 +15,6 @@ DOCKER_ENVS := \
|
||||||
-e DOCKER_CLIENTONLY \
|
-e DOCKER_CLIENTONLY \
|
||||||
-e DOCKER_DEBUG \
|
-e DOCKER_DEBUG \
|
||||||
-e DOCKER_EXPERIMENTAL \
|
-e DOCKER_EXPERIMENTAL \
|
||||||
-e DOCKERFILE \
|
|
||||||
-e DOCKER_GRAPHDRIVER \
|
-e DOCKER_GRAPHDRIVER \
|
||||||
-e DOCKER_INCREMENTAL_BINARY \
|
-e DOCKER_INCREMENTAL_BINARY \
|
||||||
-e DOCKER_REMAP_ROOT \
|
-e DOCKER_REMAP_ROOT \
|
||||||
|
|
|
@ -1,34 +1,66 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
docker-version-osarch() {
|
||||||
|
local target="$1" # "Client" or "Server"
|
||||||
|
local fmtStr="{{.${target}.Os}}/{{.${target}.Arch}}"
|
||||||
|
if docker version -f "$fmtStr" 2>/dev/null; then
|
||||||
|
# if "docker version -f" works, let's just use that!
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
docker version | awk '
|
||||||
|
$1 ~ /^(Client|Server):$/ { section = 0 }
|
||||||
|
$1 == "'"$target"':" { section = 1; next }
|
||||||
|
section && $1 == "OS/Arch:" { print $2 }
|
||||||
|
|
||||||
|
# old versions of Docker
|
||||||
|
$1 == "OS/Arch" && $2 == "('"${target,,}"'):" { print $3 }
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
# Retrieve OS/ARCH of docker daemon, eg. linux/amd64
|
# Retrieve OS/ARCH of docker daemon, eg. linux/amd64
|
||||||
export DOCKER_ENGINE_OSARCH="$(docker version | awk '
|
export DOCKER_ENGINE_OSARCH="$(docker-version-osarch 'Server')"
|
||||||
$1 == "Client:" { server = 0; next }
|
|
||||||
$1 == "Server:" { server = 1; next }
|
|
||||||
server && $1 == "OS/Arch:" { print $2 }
|
|
||||||
')"
|
|
||||||
export DOCKER_ENGINE_GOOS="${DOCKER_ENGINE_OSARCH%/*}"
|
export DOCKER_ENGINE_GOOS="${DOCKER_ENGINE_OSARCH%/*}"
|
||||||
export DOCKER_ENGINE_GOARCH="${DOCKER_ENGINE_OSARCH##*/}"
|
export DOCKER_ENGINE_GOARCH="${DOCKER_ENGINE_OSARCH##*/}"
|
||||||
DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:=amd64}
|
DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:=amd64}
|
||||||
|
|
||||||
# and the client, just in case
|
# and the client, just in case
|
||||||
export DOCKER_CLIENT_OSARCH="$(docker version | awk '
|
export DOCKER_CLIENT_OSARCH="$(docker-version-osarch 'Client')"
|
||||||
$1 == "Client:" { client = 1; next }
|
export DOCKER_CLIENT_GOOS="${DOCKER_CLIENT_OSARCH%/*}"
|
||||||
$1 == "Server:" { client = 0; next }
|
export DOCKER_CLIENT_GOARCH="${DOCKER_CLIENT_OSARCH##*/}"
|
||||||
client && $1 == "OS/Arch:" { print $2 }
|
DOCKER_CLIENT_GOARCH=${DOCKER_CLIENT_GOARCH:=amd64}
|
||||||
')"
|
|
||||||
|
|
||||||
# Retrieve the architecture used in contrib/builder/(deb|rpm)/$PACKAGE_ARCH/
|
# Retrieve the architecture used in contrib/builder/(deb|rpm)/$PACKAGE_ARCH/
|
||||||
PACKAGE_ARCH="amd64"
|
PACKAGE_ARCH='amd64'
|
||||||
case "$DOCKER_ENGINE_OSARCH" in
|
case "${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}" in
|
||||||
linux/arm)
|
arm)
|
||||||
PACKAGE_ARCH='armhf'
|
PACKAGE_ARCH='armhf'
|
||||||
;;
|
;;
|
||||||
linux/ppc64le)
|
arm64)
|
||||||
PACKAGE_ARCH='ppc64le'
|
PACKAGE_ARCH='aarch64'
|
||||||
;;
|
;;
|
||||||
linux/s390x)
|
amd64|ppc64le|s390x)
|
||||||
PACKAGE_ARCH='s390x'
|
PACKAGE_ARCH="${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo >&2 "warning: not sure how to convert '$DOCKER_ENGINE_GOARCH' to a 'Docker' arch, assuming '$PACKAGE_ARCH'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
export PACKAGE_ARCH
|
export PACKAGE_ARCH
|
||||||
|
|
||||||
|
DOCKERFILE='Dockerfile'
|
||||||
|
TEST_IMAGE_NAMESPACE=
|
||||||
|
case "$PACKAGE_ARCH" in
|
||||||
|
amd64)
|
||||||
|
case "${DOCKER_ENGINE_GOOS:-$DOCKER_CLIENT_GOOS}" in
|
||||||
|
windows)
|
||||||
|
DOCKERFILE='Dockerfile.windows'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
DOCKERFILE="Dockerfile.$PACKAGE_ARCH"
|
||||||
|
TEST_IMAGE_NAMESPACE="$PACKAGE_ARCH"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
export DOCKERFILE TEST_IMAGE_NAMESPACE
|
||||||
|
|
|
@ -9,25 +9,9 @@ images=(
|
||||||
hello-world:latest
|
hello-world:latest
|
||||||
)
|
)
|
||||||
|
|
||||||
imagePrefix=
|
if [ "$TEST_IMAGE_NAMESPACE" ]; then
|
||||||
case "$DOCKER_ENGINE_OSARCH" in
|
|
||||||
linux/arm)
|
|
||||||
imagePrefix='armhf'
|
|
||||||
;;
|
|
||||||
linux/arm64)
|
|
||||||
imagePrefix='aarch64'
|
|
||||||
;;
|
|
||||||
linux/ppc64le)
|
|
||||||
imagePrefix='ppc64le'
|
|
||||||
;;
|
|
||||||
linux/s390x)
|
|
||||||
imagePrefix='s390x'
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ "$imagePrefix" ]; then
|
|
||||||
for (( i = 0; i < ${#images[@]}; i++ )); do
|
for (( i = 0; i < ${#images[@]}; i++ )); do
|
||||||
images[$i]="$imagePrefix/${images[$i]}"
|
images[$i]="$TEST_IMAGE_NAMESPACE/${images[$i]}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -58,7 +42,7 @@ if ! docker inspect "${images[@]}" &> /dev/null; then
|
||||||
inCont = 0;
|
inCont = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' "${DOCKERFILE:=Dockerfile}" | sh -x
|
' "$DOCKERFILE" | sh -x
|
||||||
# Do not use a subshell for the following command. Windows to Linux CI
|
# Do not use a subshell for the following command. Windows to Linux CI
|
||||||
# runs bash 3.x so will not trap an error in a subshell.
|
# runs bash 3.x so will not trap an error in a subshell.
|
||||||
# http://stackoverflow.com/questions/22630363/how-does-set-e-work-with-subshells
|
# http://stackoverflow.com/questions/22630363/how-does-set-e-work-with-subshells
|
||||||
|
@ -66,9 +50,9 @@ if ! docker inspect "${images[@]}" &> /dev/null; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$imagePrefix" ]; then
|
if [ "$TEST_IMAGE_NAMESPACE" ]; then
|
||||||
for image in "${images[@]}"; do
|
for image in "${images[@]}"; do
|
||||||
target="${image#$imagePrefix/}"
|
target="${image#$TEST_IMAGE_NAMESPACE/}"
|
||||||
if [ "$target" != "$image" ]; then
|
if [ "$target" != "$image" ]; then
|
||||||
# tag images to ensure that all integrations work with the defined image names
|
# tag images to ensure that all integrations work with the defined image names
|
||||||
docker tag "$image" "$target"
|
docker tag "$image" "$target"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue