From 877e7e94e1d4a11c4d02aa29f3a840c7a6584cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20G=C3=BCnzler?= Date: Wed, 5 Aug 2020 17:33:22 +0200 Subject: [PATCH] wip: add build script using buildx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Repo type remains unchanged even though CI will trigger the build-in-container task for the engine now. We need the balena-engine type here to ensure versioning works with the engine specific quirks. Change-type: patch Signed-off-by: Robert Günzler --- build-docker.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 34 ++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100755 build-docker.sh create mode 100644 docker-compose.yml diff --git a/build-docker.sh b/build-docker.sh new file mode 100755 index 0000000000..37886ec1f5 --- /dev/null +++ b/build-docker.sh @@ -0,0 +1,65 @@ +#!/bin/sh +set -e + +[ -z "$HERE" ] && HERE="$(dirname "$(readlink -f -- "$0")")" + +# __ __ +# / /____ _____/ /_ +# / __/ _ \/ ___/ __/ +# / /_/ __(__ ) /_ +# \__/\___/____/\__/ +# + +[ -z "$SKIP_TEST" ] && DOCKER_BUILDKIT=1 make test-unit # test-integration + +# install buildx +BUILDX_VERSION="0.4.1" +BUILDX_BIN="${HOME}/.docker/cli-plugins/docker-buildx" +if [ ! -e "${BUILDX_BIN}" ]; then + curl -LO "https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION}/buildx-v${BUILDX_VERSION}.linux-amd64" + mkdir -vp "$(dirname "${BUILDX_BIN}")" + mv -vf "buildx-v${BUILDX_VERSION}.linux-amd64" "${BUILDX_BIN}" + chmod a+x "${BUILDX_BIN}" +fi + +# create builder instance for this build +# BUILDX_BUILDER="builder-$(date +%s)" +# docker buildx create --name="${BUILDX_BUILDER}" \ +# --driver=docker-container \ +# --node="${BUILDX_BUILDER}-0" \ +# --use + +VERSION=$(cat VERSION) +export VERSION + +mkdir -p "${HERE}/deploy" +pack() { + echo "* packing $1" + [ -n "$2" ] && postfix="-${2}" + cd "${BUNDLE_DIR}/cross/$1" || exit 1 + md5sum "balena-engine-${VERSION}.md5" + tar cvzf "${HERE}/deploy/balena-engine-v${VERSION}${postfix}-$(echo "$1" | sed 's/\//-/g').tar.gz" . + cd "${HERE}" || exit 1 +} + +# __ _ __ __ +# / /_ __ __(_) /___/ / +# / __ \/ / / / / / __ / +# / /_/ / /_/ / / / /_/ / +# /_.___/\__,_/_/_/\__,_/ +# + +BUNDLE_DIR="${HERE}/bundles" +if [ ! -e "${BUNDLE_DIR}" ]; then + mkdir -p "${BUNDLE_DIR}" +fi + +rm -rf "${BUNDLE_DIR:?}/*" +BUILDTAGS="no_btrfs no_cri no_devmapper no_zfs exclude_disk_quota exclude_graphdriver_btrfs exclude_graphdriver_devicemapper exclude_graphdriver_zfs no_buildkit" +export BUILDTAGS +docker buildx bake --progress=plain \ + --set=*.output=type=local,dest="${BUNDLE_DIR}" + +pack linux/amd64 +pack linux/arm64 +pack linux/arm/v7 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..dd580e837b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +# needed because buildx only supports >=3 +# 3.4 is needed for the 'target' field +version: '3.4' + +services: + binary-amd64: + image: balena/balena-engine:${VERSION:?err}-amd64 + build: + target: cross + args: + - "CROSS=false" + - "VERSION=${VERSION}" + - "DOCKER_CROSSPLATFORMS=linux/amd64" + - "DOCKER_BUILDTAGS=${BUILDTAGS:?err}" + + binary-aarch64: + image: balena/balena-engine:${VERSION:?err}-aarch64 + build: + target: cross + args: + - "CROSS=true" + - "VERSION=${VERSION}" + - "DOCKER_CROSSPLATFORMS=linux/arm64" + - "DOCKER_BUILDTAGS=${BUILDTAGS:?err}" + + binary-rpi: + image: balena/balena-engine:${VERSION:?err}-rpi + build: + target: cross + args: + - "CROSS=rpi" + - "VERSION=${VERSION}" + - "DOCKER_CROSSPLATFORMS=linux/arm/v7" + - "DOCKER_BUILDTAGS=${BUILDTAGS:?err}"