ZeroTierOne/ci/scripts/build.sh

127 lines
2.6 KiB
Bash
Raw Normal View History

2022-02-03 13:19:06 +00:00
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
2022-05-14 08:08:22 +00:00
export PLATFORM=$1
export ZT_ISA=$2
2022-02-03 13:19:06 +00:00
export VERSION=$3
2022-05-14 08:08:22 +00:00
export EVENT=$4
2022-02-03 13:19:06 +00:00
2022-05-14 08:08:22 +00:00
case $PLATFORM in
2022-11-30 09:29:33 +00:00
sid)
export PKGFMT=none
;;
2022-05-14 08:08:22 +00:00
el*|fc*|amzn*)
export PKGFMT=rpm
;;
*)
export PKGFMT=deb
esac
2022-11-30 09:29:33 +00:00
#
# Allow user to drop in custom Dockerfile for PLATFORM
#
2022-02-03 13:19:06 +00:00
2022-11-30 09:29:33 +00:00
if [ -f "ci/Dockerfile.${PLATFORM}" ]; then
export DOCKERFILE="ci/Dockerfile.${PLATFORM}"
else
export DOCKERFILE="ci/Dockerfile.${PKGFMT}"
fi
2022-05-14 08:08:22 +00:00
2022-11-30 09:29:33 +00:00
#
# Rust sometimes gets confused about where it's running.
# Normally, the build images will have Rust pre-baked.
# Pass RUST_TRIPLET for convenience when using a custom Dockerfile
#
2022-05-14 08:08:22 +00:00
case $ZT_ISA in
386)
export DOCKER_ARCH=386
export RUST_TRIPLET=i686-unknown-linux-gnu
;;
amd64)
export DOCKER_ARCH=amd64
export RUST_TRIPLET=x86_64-unknown-linux-gnu
2022-02-03 13:19:06 +00:00
;;
2022-11-30 09:29:33 +00:00
armv7)
2022-05-14 08:08:22 +00:00
export DOCKER_ARCH=arm/v7
2022-11-30 09:29:33 +00:00
export RUST_TRIPLET=armv7-unknown-linux-gnueabihf
2022-02-03 13:19:06 +00:00
;;
arm64)
2022-05-14 08:08:22 +00:00
export DOCKER_ARCH=arm64/v8
export RUST_TRIPLET=aarch64-unknown-linux-gnu
2022-02-03 13:19:06 +00:00
;;
2022-05-14 08:08:22 +00:00
riscv64)
export DOCKER_ARCH=riscv64
export RUST_TRIPLET=riscv64gc-unknown-linux-gnu
;;
ppc64le)
export DOCKER_ARCH=ppc64le
export RUST_TRIPLET=powerpc64le-unknown-linux-gnu
2022-11-30 09:29:33 +00:00
;;
2022-05-14 08:08:22 +00:00
mips64le)
export DOCKER_ARCH=mips64le
export RUST_TRIPLET=mips64el-unknown-linux-gnuabi64
;;
s390x)
export DOCKER_ARCH=s390x
export RUST_TRIPLET=s390x-unknown-linux-gnu
;;
2022-11-30 09:29:33 +00:00
*)
2022-05-14 08:08:22 +00:00
echo "ERROR: could not determine architecture settings. PLEASE FIX ME"
exit 1
2022-02-03 13:19:06 +00:00
;;
esac
2022-11-30 09:29:33 +00:00
#
# Print debug info
#
2022-05-14 08:08:22 +00:00
echo "#~~~~~~~~~~~~~~~~~~~~"
echo "$0 variables:"
echo "nproc: $(nproc)"
echo "ZT_ISA: ${ZT_ISA}"
echo "DOCKER_ARCH: ${DOCKER_ARCH}"
echo "RUST_TRIPLET: ${RUST_TRIPLET}"
echo "VERSION: ${VERSION}"
echo "EVENT: ${EVENT}"
echo "PKGFMT: ${PKGFMT}"
echo "PWD: ${PWD}"
echo "DOCKERFILE: ${DOCKERFILE}"
echo "#~~~~~~~~~~~~~~~~~~~~"
2022-11-30 09:29:33 +00:00
#
# Munge RPM and Deb
#
if [ ${PKGFMT} != "none" ] && [ ${EVENT} != "tag" ]; then
make munge_rpm zerotier-one.spec VERSION=${VERSION}
make munge_deb debian/changelog VERSION=${VERSION}
2022-05-14 08:08:22 +00:00
fi
2022-11-30 09:29:33 +00:00
#
# Assemble buildx arguments
#
build_args=(
--no-cache
--build-arg PLATFORM=${PLATFORM}
--build-arg RUST_TRIPLET=${RUST_TRIPLET}
--build-arg DOCKER_ARCH=${DOCKER_ARCH}
--platform linux/${DOCKER_ARCH}
-f ${DOCKERFILE}
-t build
.
)
if [ ${PKGFMT} != "none" ]; then
build_args+=("--output type=local,dest=.")
build_args+=("--target export")
fi
2022-05-14 08:08:22 +00:00
2022-11-30 09:29:33 +00:00
#
# Do build
#
2022-05-14 08:08:22 +00:00
2022-11-30 09:29:33 +00:00
docker buildx build ${build_args[@]}