2021-08-13 18:53:18 +08:00
|
|
|
#!/bin/bash -ex
|
|
|
|
|
|
|
|
PACKAGE_TO_BUILD="$1"
|
|
|
|
if [ -z "$PACKAGE_TO_BUILD" ]; then
|
|
|
|
set +x
|
|
|
|
echo "please provide a package name as first parameter, e.g."
|
|
|
|
echo "build/setup.sh bbb-freeswitch-core"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
mkdir -p artifacts
|
|
|
|
|
|
|
|
DOCKER_IMAGE=$(python3 -c 'import yaml; print(yaml.load(open("./.gitlab-ci.yml"), Loader=yaml.SafeLoader)["default"]["image"])')
|
|
|
|
|
2023-04-04 05:43:13 +08:00
|
|
|
LOCAL_BUILD=1
|
2022-04-26 22:51:29 +08:00
|
|
|
if [ "$LOCAL_BUILD" != 1 ] ; then
|
|
|
|
GIT_REV="${CI_COMMIT_SHA:0:10}"
|
|
|
|
else
|
|
|
|
GIT_REV=$(git rev-parse HEAD)
|
|
|
|
GIT_REV="local-build-${GIT_REV:0:10}"
|
|
|
|
fi
|
|
|
|
COMMIT_DATE="$(git log -n1 --pretty='format:%cd' --date=format:'%Y%m%dT%H%M%S')"
|
|
|
|
|
2023-08-04 00:35:30 +08:00
|
|
|
# FORCE_GIT_REV and FORCE_COMMIT_DATE are useful for Github Actions be able to cache previous packages
|
|
|
|
# It sets FORCE_GIT_REV=0 and FORCE_COMMIT_DATE=0 in order to keep the same package version always
|
2023-08-03 20:15:53 +08:00
|
|
|
if [ ! -z "$FORCE_GIT_REV" ]; then
|
|
|
|
GIT_REV=$FORCE_GIT_REV
|
|
|
|
fi
|
|
|
|
if [ ! -z "$FORCE_COMMIT_DATE" ]; then
|
|
|
|
COMMIT_DATE=$FORCE_COMMIT_DATE
|
|
|
|
fi
|
|
|
|
|
2022-09-26 05:38:44 +08:00
|
|
|
# Arrange to write the docker container ID to a temp file, then run
|
|
|
|
# the container detached and immediately attach it (without stdin) so
|
|
|
|
# we can catch CTRL-C in this script and kill the container if so.
|
|
|
|
|
|
|
|
DOCKER_CONTAINER_ID_FILE=$(mktemp)
|
|
|
|
rm $DOCKER_CONTAINER_ID_FILE
|
|
|
|
|
|
|
|
kill_docker() {
|
|
|
|
if [[ -r $DOCKER_CONTAINER_ID_FILE ]]; then
|
|
|
|
sudo docker kill $(cat $DOCKER_CONTAINER_ID_FILE)
|
|
|
|
sudo rm $DOCKER_CONTAINER_ID_FILE
|
|
|
|
fi
|
|
|
|
tput cnorm
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
trap 'kill_docker' SIGINT SIGTERM
|
|
|
|
|
2021-08-13 18:53:18 +08:00
|
|
|
# -v "$CACHE_DIR/dev":/root/dev
|
2022-09-26 05:38:44 +08:00
|
|
|
sudo docker run --rm --detach --cidfile $DOCKER_CONTAINER_ID_FILE \
|
2023-04-04 05:43:13 +08:00
|
|
|
--env GIT_REV=$GIT_REV --env COMMIT_DATE=$COMMIT_DATE --env LOCAL_BUILD=$LOCAL_BUILD \
|
2021-08-13 18:53:18 +08:00
|
|
|
--mount type=bind,src="$PWD",dst=/mnt \
|
|
|
|
--mount type=bind,src="${PWD}/artifacts,dst=/artifacts" \
|
|
|
|
-t "$DOCKER_IMAGE" /mnt/build/setup-inside-docker.sh "$PACKAGE_TO_BUILD"
|
|
|
|
|
|
|
|
# -v "$CACHE_DIR/$DISTRO/.gradle:/root/.gradle" \
|
|
|
|
# -v "$CACHE_DIR/$DISTRO/.grails:/root/.grails" \
|
|
|
|
# -v "$CACHE_DIR/$DISTRO/.ivy2:/root/.ivy2" \
|
|
|
|
# -v "$CACHE_DIR/$DISTRO/.m2:/root/.m2" \
|
|
|
|
# -v "$TMP/$TARGET:$TMP/$TARGET" \
|
|
|
|
|
2022-09-26 05:38:44 +08:00
|
|
|
docker attach --no-stdin $(cat $DOCKER_CONTAINER_ID_FILE)
|
|
|
|
sudo rm $DOCKER_CONTAINER_ID_FILE
|
|
|
|
|
2022-04-26 22:51:29 +08:00
|
|
|
find artifacts
|