|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (c) 2018-2020 The Bitcoin Core developers |
| 4 | +# Distributed under the MIT software license, see the accompanying |
| 5 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 6 | + |
| 7 | +export LC_ALL=C.UTF-8 |
| 8 | + |
| 9 | +if [[ $DOCKER_NAME_TAG == centos* ]]; then |
| 10 | + export LC_ALL=en_US.utf8 |
| 11 | +fi |
| 12 | +if [[ $QEMU_USER_CMD == qemu-s390* ]]; then |
| 13 | + export LC_ALL=C |
| 14 | +fi |
| 15 | + |
| 16 | +# Create folders that are mounted into the docker |
| 17 | +mkdir -p "${CCACHE_DIR}" |
| 18 | +mkdir -p "/tmp/release" |
| 19 | + |
| 20 | +env | grep -E '^(GRIDCOIN_CONFIG|BASE_|QEMU_|CCACHE_|LC_ALL|BOOST_TEST_RANDOM|DEBIAN_FRONTEND|CONFIG_SHELL|(ASAN|LSAN|TSAN|UBSAN)_OPTIONS|PREVIOUS_RELEASES_DIR)' | tee /tmp/env |
| 21 | + |
| 22 | +export P_CI_DIR="$PWD" |
| 23 | + |
| 24 | +mkdir -p /tmp/release |
| 25 | + |
| 26 | +if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then |
| 27 | + echo "Creating $DOCKER_NAME_TAG container to run in" |
| 28 | + ${CI_RETRY_EXE} docker pull "$DOCKER_NAME_TAG" |
| 29 | + |
| 30 | + DOCKER_ID=$(docker run $DOCKER_ADMIN -idt \ |
| 31 | + --mount type=bind,src=$BASE_ROOT_DIR,dst=/ro_base,readonly \ |
| 32 | + --mount type=bind,src=$CCACHE_DIR,dst=$CCACHE_DIR \ |
| 33 | + --mount type=bind,src=$DEPENDS_DIR,dst=$DEPENDS_DIR \ |
| 34 | + --mount type=bind,src=$PREVIOUS_RELEASES_DIR,dst=$PREVIOUS_RELEASES_DIR \ |
| 35 | + --mount type=bind,src=/tmp/release,dst=/release \ |
| 36 | + -w $BASE_ROOT_DIR \ |
| 37 | + --env-file /tmp/env \ |
| 38 | + --name $CONTAINER_NAME \ |
| 39 | + $DOCKER_NAME_TAG) |
| 40 | + export DOCKER_CI_CMD_PREFIX="docker exec $DOCKER_ID" |
| 41 | +else |
| 42 | + echo "Running on host system without docker wrapper" |
| 43 | +fi |
| 44 | + |
| 45 | +DOCKER_EXEC () { |
| 46 | + $DOCKER_CI_CMD_PREFIX bash -c "export PATH=$BASE_SCRATCH_DIR/bins/:\$PATH && cd $P_CI_DIR && $*" |
| 47 | +} |
| 48 | +export -f DOCKER_EXEC |
| 49 | + |
| 50 | +if [ -n "$DPKG_ADD_ARCH" ]; then |
| 51 | + DOCKER_EXEC dpkg --add-architecture "$DPKG_ADD_ARCH" |
| 52 | +fi |
| 53 | + |
| 54 | +if [[ $DOCKER_NAME_TAG == centos* ]]; then |
| 55 | + BEGIN_FOLD yum |
| 56 | + ${CI_RETRY_EXE} DOCKER_EXEC yum -y install epel-release |
| 57 | + ${CI_RETRY_EXE} DOCKER_EXEC yum -y install $DOCKER_PACKAGES $PACKAGES |
| 58 | + END_FOLD |
| 59 | +elif [ "$CI_USE_APT_INSTALL" != "no" ]; then |
| 60 | + BEGIN_FOLD apt |
| 61 | + ${CI_RETRY_EXE} DOCKER_EXEC apt-get update |
| 62 | + ${CI_RETRY_EXE} DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -y $PACKAGES $DOCKER_PACKAGES |
| 63 | + if [ "$NEED_XVFB" == "true" ]; then |
| 64 | + ${CI_RETRY_EXE} DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -y xvfb |
| 65 | + fi |
| 66 | + END_FOLD |
| 67 | +fi |
| 68 | + |
| 69 | +if [ "$OS_NAME" == "macos" ]; then |
| 70 | + top -l 1 -s 0 | awk ' /PhysMem/ {print}' |
| 71 | + echo "Number of CPUs: $(sysctl -n hw.logicalcpu)" |
| 72 | +else |
| 73 | + DOCKER_EXEC free -m -h |
| 74 | + DOCKER_EXEC echo "Number of CPUs \(nproc\):" \$\(nproc\) |
| 75 | + DOCKER_EXEC echo $(lscpu | grep Endian) |
| 76 | + DOCKER_EXEC echo "Free disk space:" |
| 77 | + DOCKER_EXEC df -h |
| 78 | +fi |
| 79 | + |
| 80 | +if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then |
| 81 | + echo "Create $BASE_ROOT_DIR" |
| 82 | + DOCKER_EXEC rsync -a /ro_base/ $BASE_ROOT_DIR |
| 83 | +fi |
| 84 | + |
| 85 | +if [ "$USE_BUSY_BOX" = "true" ]; then |
| 86 | + echo "Setup to use BusyBox utils" |
| 87 | + DOCKER_EXEC mkdir -p $BASE_SCRATCH_DIR/bins/ |
| 88 | + # tar excluded for now because it requires passing in the exact archive type in ./depends (fixed in later BusyBox version) |
| 89 | + # find excluded for now because it does not recognize the -delete option in ./depends (fixed in later BusyBox version) |
| 90 | + # ar excluded for now because it does not recognize the -q option in ./depends (unknown if fixed) |
| 91 | + # shellcheck disable=SC1010 |
| 92 | + DOCKER_EXEC for util in \$\(busybox --list \| grep -v "^ar$" \| grep -v "^tar$" \| grep -v "^find$"\)\; do ln -s \$\(command -v busybox\) $BASE_SCRATCH_DIR/bins/\$util\; done |
| 93 | + # Print BusyBox version |
| 94 | + DOCKER_EXEC patch --help |
| 95 | +fi |
0 commit comments