Skip to content

Commit

Permalink
wip: add build script using buildx
Browse files Browse the repository at this point in the history
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 <robertg@balena.io>
  • Loading branch information
robertgzr committed Sep 9, 2020
1 parent 6a51890 commit 877e7e9
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
65 changes: 65 additions & 0 deletions 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
34 changes: 34 additions & 0 deletions 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}"

0 comments on commit 877e7e9

Please sign in to comment.