github.com/afbjorklund/moby@v20.10.5+incompatible/hack/make/.detect-daemon-osarch (about)

     1  #!/usr/bin/env bash
     2  set -e
     3  
     4  docker-version-osarch() {
     5  	if ! type docker &> /dev/null; then
     6  		# docker is not installed
     7  		return
     8  	fi
     9  	local target="$1" # "Client" or "Server"
    10  	local fmtStr="{{.${target}.Os}}/{{.${target}.Arch}}"
    11  	if docker version -f "$fmtStr" 2> /dev/null; then
    12  		# if "docker version -f" works, let's just use that!
    13  		return
    14  	fi
    15  	docker version | awk '
    16  		$1 ~ /^(Client|Server):$/ { section = 0 }
    17  		$1 == "'"$target"':" { section = 1; next }
    18  		section && $1 == "OS/Arch:" { print $2 }
    19  
    20  		# old versions of Docker
    21  		$1 == "OS/Arch" && $2 == "('"${target,,}"'):" { print $3 }
    22  	'
    23  }
    24  
    25  # Retrieve OS/ARCH of docker daemon, e.g. linux/amd64
    26  export DOCKER_ENGINE_OSARCH="${DOCKER_ENGINE_OSARCH:=$(docker-version-osarch 'Server')}"
    27  export DOCKER_ENGINE_GOOS="${DOCKER_ENGINE_OSARCH%/*}"
    28  export DOCKER_ENGINE_GOARCH="${DOCKER_ENGINE_OSARCH##*/}"
    29  DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:=amd64}
    30  
    31  # and the client, just in case
    32  export DOCKER_CLIENT_OSARCH="$(docker-version-osarch 'Client')"
    33  export DOCKER_CLIENT_GOOS="${DOCKER_CLIENT_OSARCH%/*}"
    34  export DOCKER_CLIENT_GOARCH="${DOCKER_CLIENT_OSARCH##*/}"
    35  DOCKER_CLIENT_GOARCH=${DOCKER_CLIENT_GOARCH:=amd64}
    36  
    37  DOCKERFILE='Dockerfile'
    38  
    39  if [ "${DOCKER_ENGINE_GOOS:-$DOCKER_CLIENT_GOOS}" = "windows" ]; then
    40  	DOCKERFILE='Dockerfile.windows'
    41  fi
    42  
    43  export DOCKERFILE