#!/usr/bin/env bash ## This script helps to setup a buildx environment for CI set -euo pipefail function help { echo echo "-h|--help: To display this usage information" echo "--prepare: Prepare docker buildx environment (only once for each setup)" echo "--src_dir : EMQ X source ode in this dir, default to PWD" echo "--profile : EMQ X profile to build, e.g. emqx, emqx-edge" echo "--system : Target system e.g. debian10, centos7 etc." echo "--builder : Builder image to pull." echo "--arch : Target arch to build the EMQ X package for" echo "--build_dest : Destination file output tar file" } while [ "$#" -gt 0 ]; do case $1 in -h|--help) help exit 0 ;; --prepare) PREPARE='yes' shift ;; --src_dir) SRC_DIR="$2" shift 2 ;; --profile) PROFILE="$2" shift 2 ;; --system) SYSTEM="$2" shift 2 ;; --builder) BUILDER="$2" shift 2 ;; --arch) ARCH="$2" shift 2 ;; --build_dest) BUILD_DEST="$2" shift 2 ;; *) echo "WARN: Unknown arg (ignored): $1" shift continue ;; esac done if [ "${PREPARE:-}" = 'yes' ]; then mkdir -p $HOME/.docker echo '{ "experimental": "enabled" }' | tee $HOME/.docker/config.json echo '{ "experimental": true, "storage-driver": "overlay2", "max-concurrent-downloads": 50, "max-concurrent-uploads": 50}' | sudo tee /etc/docker/daemon.json sudo systemctl restart docker docker info docker buildx create --use --name mybuild docker run --rm --privileged tonistiigi/binfmt --install all fi cd "${SRC_DIR:-.}" docker buildx build --no-cache \ --platform=linux/$ARCH \ -t "cross_build_emqx_for_${SYSTEM}" \ -f .ci/build_packages/Dockerfile \ --build-arg BUILD_FROM="$BUILDER" \ --build-arg EMQX_NAME="$PROFILE" \ --output type=tar,dest="$BUILD_DEST" .