termux-packages/scripts/run-docker.sh
Leonid Pliushch 86cdb09734
another attempt to fix Github Actions curl timeouts
Will run "sudo ethtool -K eth0 tx off rx off" in container before executing
build commands.

Since our build environment doesn't have ethtool installed, this will
imply rebuilding Docker image. Until that, CI builds will fail due to
missing utility.
2021-05-26 15:15:37 +03:00

68 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
set -e -u
CONTAINER_HOME_DIR=/home/builder
UNAME=$(uname)
if [ "$UNAME" = Darwin ]; then
# Workaround for mac readlink not supporting -f.
REPOROOT=$PWD
else
REPOROOT="$(dirname $(readlink -f $0))/../"
fi
: ${TERMUX_BUILDER_IMAGE_NAME:=termux/package-builder}
: ${CONTAINER_NAME:=termux-package-builder}
USER=builder
if [ -n "${TERMUX_DOCKER_USE_SUDO-}" ]; then
SUDO="sudo"
else
SUDO=""
fi
echo "Running container '$CONTAINER_NAME' from image '$TERMUX_BUILDER_IMAGE_NAME'..."
if [ "${GITHUB_EVENT_PATH-x}" != "x" ]; then
# On CI/CD tty may not be available.
DOCKER_TTY=""
else
DOCKER_TTY=" --tty"
fi
$SUDO docker start $CONTAINER_NAME >/dev/null 2>&1 || {
if [ "$GITHUB_ACTIONS" = "true" ]; then
SECURITY_OPT="--cap-add SYS_ADMIN --cap-add NET_ADMIN --security-opt apparmor:unconfined --security-opt seccomp=unconfined"
else
SECURITY_OPT=""
fi
echo "Creating new container..."
$SUDO docker run \
$SECURITY_OPT \
--detach \
--name $CONTAINER_NAME \
--volume $REPOROOT:$CONTAINER_HOME_DIR/termux-packages \
--tty \
$TERMUX_BUILDER_IMAGE_NAME
if [ "$UNAME" != Darwin ]; then
if [ $(id -u) -ne 1000 -a $(id -u) -ne 0 ]; then
echo "Changed builder uid/gid... (this may take a while)"
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo chown -R $(id -u) $CONTAINER_HOME_DIR
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo chown -R $(id -u) /data
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo usermod -u $(id -u) builder
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo groupmod -g $(id -g) builder
fi
fi
}
if [ "$GITHUB_ACTIONS" = "true" ]; then
$SUDO docker exec $DOCKER_TTY $CONTAINER_NAME sudo ethtool -K eth0 tx off rx off
fi
if [ "$#" -eq "0" ]; then
$SUDO docker exec --interactive $DOCKER_TTY $CONTAINER_NAME bash
else
$SUDO docker exec --interactive $DOCKER_TTY $CONTAINER_NAME "$@"
fi