switch to using docker buildx with multi-arch

This commit is contained in:
John
2021-11-10 20:16:26 +01:00
parent c09ba1e686
commit 6faa52bdd4
14 changed files with 139 additions and 453 deletions
+20 -46
View File
@@ -1,63 +1,37 @@
#!/bin/bash
DEFAULT_IMAGE=debian:bullseye
EBUSD_VERSION=`cat ../../VERSION`
archs='amd64 i386 arm32v5:arm arm32v7:arm arm64v8:aarch64'
function replaceTemplate () {
prefix=
suffix=
qemu_from_line=
qemu_from_copy=
extra_rm=
if [ "$arch" != "amd64" ]; then
qemu="${arch##*:}"
arch="${arch%%:*}"
prefix="$arch/"
suffix=".$arch"
qemu_from_line="FROM multiarch/qemu-user-static as qemu"
qemu_from_copy="COPY --from=qemu /usr/bin/qemu-$qemu-static /usr/bin/"
extra_rm=" /usr/bin/qemu-$qemu-static"
fi
file="${dir}Dockerfile${namesuffix}${suffix}"
file="Dockerfile${namesuffix}"
sed \
-e "s#%QEMU_FROM_LINE%#${qemu_from_line}#g" \
-e "s#%BASE_IMAGE%#${prefix}${BASE_IMAGE:-$DEFAULT_IMAGE}#g" \
-e "s#%QEMU_FROM_COPY%#${qemu_from_copy}#g" \
-e "s#%EBUSD_MAKE%#${make}#g" \
-e "s#%EBUSD_VERSION%#${EBUSD_VERSION}#g" \
-e "s#%EBUSD_VERSION_VARIANT%#${version_variant}#g" \
-e "s#%EBUSD_ARCH%#${arch}#g" \
-e "s#%EXTRA_RM%#${extra_rm}#g" \
-e "s#%EBUSD_UPLOAD_LINES%#${upload_lines}#g" \
-e "s#%EBUSD_COPYDEB%#${copydeb}#g" \
-e "s#%EBUSD_COPYENTRY%#${copyentry}#g" \
Dockerfile.template > "$file"
echo "updated $file"
}
if [[ -z "$1" ]]; then
# devel updates
version_variant='-devel'
make='./make_debian.sh'
dir=''
upload_line=''
namesuffix=''
for arch in $archs; do
replaceTemplate
done
fi
# devel update
version_variant='-devel'
make='./make_debian.sh'
upload_lines=''
copydeb='COPY --from=build /build/ebusd-*_mqtt1.deb ebusd.deb'
copyentry='COPY --from=build /build/contrib/docker/docker-entrypoint.sh /'
namesuffix=''
replaceTemplate
# release updates
# release update
version_variant=''
dir="$1"
copydeb="ADD https://github.com/john30/ebusd/releases/download/v\${EBUSD_VERSION}/ebusd-\${EBUSD_VERSION}_\${TARGETARCH}\${TARGETVARIANT}-\${EBUSD_IMAGE}_mqtt1.deb ebusd.deb"
copyentry='COPY contrib/docker/docker-entrypoint.sh /'
namesuffix='.release'
replaceTemplate
if [[ -n "$1" ]]; then
# build releases update
make='./make_all.sh'
upload_lines='ARG UPLOAD_URL\nARG UPLOAD_CREDENTIALS\nARG UPLOAD_OS\nRUN if [ -n "\$UPLOAD_URL" ] \&\& [ -n "\$UPLOAD_CREDENTIALS" ]; then for img in ebusd-*.deb; do echo -n "upload \$img: "; curl -fs -u "\$UPLOAD_CREDENTIALS" -X POST --data-binary "@\$img" -H "Content-Type: application/octet-stream" "\$UPLOAD_URL/\$img?a=\$EBUSD_ARCH\&o=\$UPLOAD_OS\&v=\$EBUSD_VERSION" || echo "failed"; done; fi'
namesuffix=''
else
make='./make_debian.sh'
namesuffix='.release'
fi
for arch in $archs; do
namesuffix='.build'
replaceTemplate
done
fi