2018-08-03 09:21:03 -04:00
#!/usr/bin/env bash
#
2023-08-27 08:34:48 -04:00
# Copyright (c) 2018-present The Bitcoin Core developers
2018-08-03 09:21:03 -04:00
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
2018-08-07 05:50:05 -04:00
export LC_ALL = C.UTF-8
2018-08-03 09:21:03 -04:00
2023-10-04 12:04:40 -03:00
set -ex
2020-04-08 19:59:37 -04:00
if [ -z " $DANGER_RUN_CI_ON_HOST " ] ; then
2023-05-05 02:45:37 -04:00
# Export all env vars to avoid missing some.
# Though, exclude those with newlines to avoid parsing problems.
2023-07-24 08:55:18 -04:00
python3 -c 'import os; [print(f"{key}={value}") for key, value in os.environ.items() if "\n" not in value and "HOME" != key and "PATH" != key and "USER" != key]' | tee /tmp/env
# System-dependent env vars must be kept as is. So read them from the container.
docker run --rm " ${ CI_IMAGE_NAME_TAG } " bash -c "env | grep --extended-regexp '^(HOME|PATH|USER)='" | tee --append /tmp/env
2023-01-09 06:22:18 -03:00
echo " Creating $CI_IMAGE_NAME_TAG container to run in "
2023-07-11 17:10:38 -04:00
DOCKER_BUILDKIT = 1 docker build \
2023-07-30 05:08:52 -04:00
--file " ${ BASE_READ_ONLY_DIR } /ci/test_imagefile " \
2023-01-27 08:42:46 -03:00
--build-arg " CI_IMAGE_NAME_TAG= ${ CI_IMAGE_NAME_TAG } " \
--build-arg " FILE_ENV= ${ FILE_ENV } " \
--tag= " ${ CONTAINER_NAME } " \
2023-07-30 05:08:52 -04:00
" ${ BASE_READ_ONLY_DIR } "
2023-02-03 07:41:17 -03:00
docker volume create " ${ CONTAINER_NAME } _ccache " || true
docker volume create " ${ CONTAINER_NAME } _depends " || true
2023-10-05 08:45:51 -03:00
docker volume create " ${ CONTAINER_NAME } _depends_sources " || true
docker volume create " ${ CONTAINER_NAME } _depends_SDKs_android " || true
2023-02-03 07:41:17 -03:00
docker volume create " ${ CONTAINER_NAME } _previous_releases " || true
2019-08-11 11:57:21 -04:00
2021-03-25 07:14:35 -03:00
if [ -n " ${ RESTART_CI_DOCKER_BEFORE_RUN } " ] ; then
echo "Restart docker before run to stop and clear all containers started with --rm"
2023-09-28 06:18:31 -03:00
podman container rm --force --all # Similar to "systemctl restart docker"
2023-05-30 02:53:45 -04:00
echo "Prune all dangling images"
docker image prune --force
2021-03-25 07:14:35 -03:00
fi
2021-11-07 09:13:39 -03:00
# shellcheck disable=SC2086
2023-09-05 10:07:54 -03:00
CI_CONTAINER_ID = $( docker run --cap-add LINUX_IMMUTABLE $CI_CONTAINER_CAP --rm --interactive --detach --tty \
2023-08-27 08:34:48 -04:00
--mount " type=bind,src= $BASE_READ_ONLY_DIR ,dst= $BASE_READ_ONLY_DIR ,readonly " \
2023-02-03 07:41:17 -03:00
--mount " type=volume,src= ${ CONTAINER_NAME } _ccache,dst= $CCACHE_DIR " \
2023-10-05 08:45:51 -03:00
--mount " type=volume,src= ${ CONTAINER_NAME } _depends,dst= $DEPENDS_DIR /built " \
--mount " type=volume,src= ${ CONTAINER_NAME } _depends_sources,dst= $DEPENDS_DIR /sources " \
--mount " type=volume,src= ${ CONTAINER_NAME } _depends_SDKs_android,dst= $DEPENDS_DIR /SDKs/android " \
2023-02-03 07:41:17 -03:00
--mount " type=volume,src= ${ CONTAINER_NAME } _previous_releases,dst= $PREVIOUS_RELEASES_DIR " \
2019-11-09 11:20:41 -03:00
--env-file /tmp/env \
2023-08-27 08:34:48 -04:00
--name " $CONTAINER_NAME " \
" $CONTAINER_NAME " )
2023-01-09 06:42:19 -03:00
export CI_CONTAINER_ID
2023-03-31 03:28:43 -03:00
export CI_EXEC_CMD_PREFIX = " docker exec ${ CI_CONTAINER_ID } "
2019-08-11 11:57:21 -04:00
else
echo "Running on host system without docker wrapper"
2023-07-11 16:34:42 -04:00
echo "Create missing folders"
mkdir -p " ${ CCACHE_DIR } "
mkdir -p " ${ PREVIOUS_RELEASES_DIR } "
2019-08-11 11:57:21 -04:00
fi
2020-05-30 07:56:56 -04:00
2022-01-31 08:09:37 -03:00
CI_EXEC ( ) {
2023-07-11 17:10:38 -04:00
$CI_EXEC_CMD_PREFIX bash -c " export PATH= ${ BINS_SCRATCH_DIR } : ${ BASE_ROOT_DIR } /ci/retry:\$PATH && cd \" ${ BASE_ROOT_DIR } \" && $* "
2020-05-30 07:56:56 -04:00
}
2022-01-31 08:09:37 -03:00
export -f CI_EXEC
2019-08-11 11:57:21 -04:00
2023-08-15 12:01:20 -04:00
# Normalize all folders to BASE_ROOT_DIR
CI_EXEC rsync --archive --stats --human-readable " ${ BASE_READ_ONLY_DIR } / " " ${ BASE_ROOT_DIR } " || echo " Nothing to copy from ${ BASE_READ_ONLY_DIR } / "
2023-03-31 05:20:15 -03:00
CI_EXEC " ${ BASE_ROOT_DIR } /ci/test/01_base_install.sh "
2023-08-27 08:34:48 -04:00
2023-03-31 05:20:15 -03:00
# Fixes permission issues when there is a container UID/GID mismatch with the owner
# of the git source code directory.
CI_EXEC git config --global --add safe.directory \" *\"
2023-01-09 07:56:57 -03:00
CI_EXEC mkdir -p " ${ BINS_SCRATCH_DIR } "
2023-09-28 08:35:02 -03:00
CI_EXEC " ${ BASE_ROOT_DIR } /ci/test/06_script_b.sh "
if [ -z " $DANGER_RUN_CI_ON_HOST " ] ; then
echo "Stop and remove CI container by ID"
docker container kill " ${ CI_CONTAINER_ID } "
fi