build: add scripts/buildx

This commit is contained in:
Zaiming (Stone) Shi 2021-12-29 15:06:57 +01:00
parent 5a6225d397
commit 6b7a9a8fef
2 changed files with 86 additions and 16 deletions

View File

@ -248,15 +248,6 @@ jobs:
shell: bash shell: bash
steps: steps:
- name: prepare docker
run: |
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
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v2
with: with:
name: source name: source
@ -298,13 +289,13 @@ jobs:
run: | run: |
set -e -u set -e -u
cd source cd source
docker buildx build --no-cache \ ./scripts/buildx.sh \
--platform=linux/$ARCH \ --prepare \
-t cross_build_emqx_for_$SYSTEM \ --profile "$PROFILE" \
-f .ci/build_packages/Dockerfile \ --system "$SYSTEM" \
--build-arg BUILD_FROM=emqx/build-env:$ERL_OTP-$SYSTEM \ --builder "emqx/build-env:$ERL_OTP-$SYSTEM" \
--build-arg EMQX_NAME=$PROFILE \ --arch "$ARCH" \
--output type=tar,dest=/tmp/cross-build-$PROFILE-for-$SYSTEM.tar . --build_dest "/tmp/cross-build-$PROFILE-for-$SYSTEM.tar" .
mkdir -p /tmp/packages/$PROFILE mkdir -p /tmp/packages/$PROFILE
tar -xvf /tmp/cross-build-$PROFILE-for-$SYSTEM.tar --wildcards emqx/_packages/$PROFILE/* tar -xvf /tmp/cross-build-$PROFILE-for-$SYSTEM.tar --wildcards emqx/_packages/$PROFILE/*

79
scripts/buildx.sh Executable file
View File

@ -0,0 +1,79 @@
#!/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 <SRC_DIR>: EMQ X source ode in this dir, default to PWD"
echo "--profile <PROFILE>: EMQ X profile to build, e.g. emqx, emqx-edge"
echo "--system <SYSTEM>: Target system e.g. debian10, centos7 etc."
echo "--builder <BUILDER>: Builder image to pull."
echo "--arch <TARGET_ARCH>: Target arch to build the EMQ X package for"
echo "--build_dest <PATH>: 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" .