github.com/ojongerius/docker@v1.11.2/hack/make/.detect-daemon-osarch (about) 1 #!/bin/bash 2 set -e 3 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 # old versions of Docker 17 $1 == "OS/Arch" && $2 == "('"${target,,}"'):" { print $3 } 18 ' 19 } 20 21 # Retrieve OS/ARCH of docker daemon, eg. linux/amd64 22 export DOCKER_ENGINE_OSARCH="$(docker-version-osarch 'Server')" 23 export DOCKER_ENGINE_GOOS="${DOCKER_ENGINE_OSARCH%/*}" 24 export DOCKER_ENGINE_GOARCH="${DOCKER_ENGINE_OSARCH##*/}" 25 DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:=amd64} 26 27 # and the client, just in case 28 export DOCKER_CLIENT_OSARCH="$(docker-version-osarch 'Client')" 29 export DOCKER_CLIENT_GOOS="${DOCKER_CLIENT_OSARCH%/*}" 30 export DOCKER_CLIENT_GOARCH="${DOCKER_CLIENT_OSARCH##*/}" 31 DOCKER_CLIENT_GOARCH=${DOCKER_CLIENT_GOARCH:=amd64} 32 33 # Retrieve the architecture used in contrib/builder/(deb|rpm)/$PACKAGE_ARCH/ 34 PACKAGE_ARCH='amd64' 35 case "${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}" in 36 arm) 37 PACKAGE_ARCH='armhf' 38 ;; 39 arm64) 40 PACKAGE_ARCH='aarch64' 41 ;; 42 amd64|ppc64le|s390x) 43 PACKAGE_ARCH="${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}" 44 ;; 45 *) 46 echo >&2 "warning: not sure how to convert '$DOCKER_ENGINE_GOARCH' to a 'Docker' arch, assuming '$PACKAGE_ARCH'" 47 ;; 48 esac 49 export PACKAGE_ARCH 50 51 DOCKERFILE='Dockerfile' 52 TEST_IMAGE_NAMESPACE= 53 case "$PACKAGE_ARCH" in 54 amd64) 55 case "${DOCKER_ENGINE_GOOS:-$DOCKER_CLIENT_GOOS}" in 56 windows) 57 DOCKERFILE='Dockerfile.windows' 58 ;; 59 esac 60 ;; 61 *) 62 DOCKERFILE="Dockerfile.$PACKAGE_ARCH" 63 TEST_IMAGE_NAMESPACE="$PACKAGE_ARCH" 64 ;; 65 esac 66 export DOCKERFILE TEST_IMAGE_NAMESPACE