github.com/skf/moby@v1.13.1/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, e.g. 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  			solaris)
    60  				DOCKERFILE='Dockerfile.solaris'
    61  				;;
    62  		esac
    63  		;;
    64  	*)
    65  		DOCKERFILE="Dockerfile.$PACKAGE_ARCH"
    66  		TEST_IMAGE_NAMESPACE="$PACKAGE_ARCH"
    67  		;;
    68  esac
    69  export DOCKERFILE TEST_IMAGE_NAMESPACE