Skip to content

Instantly share code, notes, and snippets.

@imdurgadas
Created November 3, 2018 14:12
Show Gist options
  • Save imdurgadas/755f4f86bc48cd51177413bf877e7869 to your computer and use it in GitHub Desktop.
Save imdurgadas/755f4f86bc48cd51177413bf877e7869 to your computer and use it in GitHub Desktop.
Make docker file to support multi platform
ARCHS=(arm s390x amd64 ppc64le)
QEMUARCHS=(arm s390x x86_64 ppc64le)
makeDockerfile() {
local arch=$1
local dockerfile
dockerfile="Dockerfile-${arch}"
/bin/cp -f Dockerfile.template "$dockerfile"
# Make the Dockerfile after we set the base image
sed -i "s|BASEIMAGE|${BASEIMAGE}|g" "$dockerfile"
if [[ "${arch}" == "amd64" ]]; then
sed -i "/CROSS_BUILD_/d" "$dockerfile"
else
if [[ "${arch}" == "arm64" ]]; then
sed -i "s|ARCH|aarch64|g" "$dockerfile"
else
sed -i "s|ARCH|${arch}|g" "$dockerfile"
fi
sed -i "s/CROSS_BUILD_//g" "$dockerfile"
fi
}
get-base-image() {
local arch=$1
# Parse architectures and variants
if [[ $arch == amd64 ]]; then
BASEIMAGE="ubuntu"
elif [[ $arch == arm ]]; then
BASEIMAGE="arm32v7/ubuntu"
elif [[ $arch == s390x ]]; then
BASEIMAGE="s390x/ubuntu"
elif [[ $arch == ppc64le ]]; then
BASEIMAGE="ppc64le/ubuntu"
fi
makeDockerfile "${arch}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment