1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/hack/make/.detect-daemon-osarch
Dieter Reuter 0d7e118f01 Add support for running builds within an QEMU emulation
With this change we can run a Docker build in QEMU and build ARM or ARM64 binaries directly on an Intel build machine. This feature already supports building with Docker4Mac (Beta31). So it's easy for a developer to compile and test the Docker binaries locally on his dev machine w/o the need of the target hardware. Another use case would be to run builds on a clound CI like Travis to get an instant feedback loop for PR's, all on a common Intel platform w/o the need to set up the CI system on the target hardware.

Usage: build static Docker binaries for ARM 32-bit
```
DOCKER_ENGINE_OSARCH="linux/arm" make binary
```

Usage: build static Docker binaries for ARM64 aka AARCH64
```
DOCKER_ENGINE_OSARCH="linux/arm64" make binary
```

Signed-off-by: Dieter Reuter <dieter.reuter@me.com>
2016-12-03 13:53:59 +01:00

69 lines
1.9 KiB
Bash

#!/bin/bash
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, e.g. linux/amd64
export DOCKER_ENGINE_OSARCH="${DOCKER_ENGINE_OSARCH:=$(docker-version-osarch 'Server')}"
export DOCKER_ENGINE_GOOS="${DOCKER_ENGINE_OSARCH%/*}"
export DOCKER_ENGINE_GOARCH="${DOCKER_ENGINE_OSARCH##*/}"
DOCKER_ENGINE_GOARCH=${DOCKER_ENGINE_GOARCH:=amd64}
# and the client, just in case
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}
# Retrieve the architecture used in contrib/builder/(deb|rpm)/$PACKAGE_ARCH/
PACKAGE_ARCH='amd64'
case "${DOCKER_ENGINE_GOARCH:-$DOCKER_CLIENT_GOARCH}" in
arm)
PACKAGE_ARCH='armhf'
;;
arm64)
PACKAGE_ARCH='aarch64'
;;
amd64|ppc64le|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
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'
;;
solaris)
DOCKERFILE='Dockerfile.solaris'
;;
esac
;;
*)
DOCKERFILE="Dockerfile.$PACKAGE_ARCH"
TEST_IMAGE_NAMESPACE="$PACKAGE_ARCH"
;;
esac
export DOCKERFILE TEST_IMAGE_NAMESPACE