2017-02-13 14:01:54 -05:00
|
|
|
#!/usr/bin/env bash
|
2016-01-05 00:50:15 -05:00
|
|
|
set -e
|
|
|
|
|
2016-03-10 22:19:33 -05:00
|
|
|
docker-version-osarch() {
|
2020-03-02 22:27:49 -05:00
|
|
|
if ! type docker &> /dev/null; then
|
2017-04-04 09:12:33 -04:00
|
|
|
# docker is not installed
|
|
|
|
return
|
|
|
|
fi
|
2016-03-10 22:19:33 -05:00
|
|
|
local target="$1" # "Client" or "Server"
|
|
|
|
local fmtStr="{{.${target}.Os}}/{{.${target}.Arch}}"
|
2020-03-02 22:27:49 -05:00
|
|
|
if docker version -f "$fmtStr" 2> /dev/null; then
|
2016-03-10 22:19:33 -05:00
|
|
|
# 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 }
|
2016-03-14 12:30:45 -04:00
|
|
|
|
|
|
|
# old versions of Docker
|
|
|
|
$1 == "OS/Arch" && $2 == "('"${target,,}"'):" { print $3 }
|
2016-03-10 22:19:33 -05:00
|
|
|
'
|
|
|
|
}
|
|
|
|
|
2016-09-21 01:48:06 -04:00
|
|
|
# Retrieve OS/ARCH of docker daemon, e.g. linux/amd64
|
2016-12-03 05:32:37 -05:00
|
|
|
export DOCKER_ENGINE_OSARCH="${DOCKER_ENGINE_OSARCH:=$(docker-version-osarch 'Server')}"
|
2016-01-05 00:50:15 -05:00
|
|
|
export DOCKER_ENGINE_GOOS="${DOCKER_ENGINE_OSARCH%/*}"
|
|
|
|
export DOCKER_ENGINE_GOARCH="${DOCKER_ENGINE_OSARCH##*/}"
|
2015-11-23 14:00:43 -05:00
|
|
|
DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:=amd64}
|
2016-01-05 00:50:15 -05:00
|
|
|
|
|
|
|
# and the client, just in case
|
2016-03-10 22:19:33 -05:00
|
|
|
export DOCKER_CLIENT_OSARCH="$(docker-version-osarch 'Client')"
|
|
|
|
export DOCKER_CLIENT_GOOS="${DOCKER_CLIENT_OSARCH%/*}"
|
|
|
|
export DOCKER_CLIENT_GOARCH="${DOCKER_CLIENT_OSARCH##*/}"
|
|
|
|
DOCKER_CLIENT_GOARCH=${DOCKER_CLIENT_GOARCH:=amd64}
|
2015-11-23 14:00:43 -05:00
|
|
|
|
2016-03-10 22:19:33 -05:00
|
|
|
DOCKERFILE='Dockerfile'
|
2018-03-09 01:49:26 -05:00
|
|
|
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ "${DOCKER_ENGINE_GOOS:-$DOCKER_CLIENT_GOOS}" = "windows" ]; then
|
2018-03-09 01:49:26 -05:00
|
|
|
DOCKERFILE='Dockerfile.windows'
|
|
|
|
fi
|
|
|
|
|
2018-01-04 22:13:24 -05:00
|
|
|
export DOCKERFILE
|