diff options
author | fanquake <fanquake@gmail.com> | 2024-02-20 10:18:22 +0000 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2024-02-20 10:21:44 +0000 |
commit | bdddf364c9a6f80e3bfcf45ab1ae54f9eab5811b (patch) | |
tree | e53c88f693dc73bbc83268f1fecfc80a63e605a5 | |
parent | b1a46b212f109b6fb4b8037cce0f5c0887faff74 (diff) | |
parent | fa91bf2559d2e839592bf1dc1d423d5fb1c3573e (diff) |
Merge bitcoin/bitcoin#29441: ci: Avoid CI failures from temp env file reuse
fa91bf2559d2e839592bf1dc1d423d5fb1c3573e ci: Skip git install if it is already installed (MarcoFalke)
c65fde483133a04964cc8757c96005b78d9e8ca8 ci: vary /tmp/env (Sjors Provoost)
Pull request description:
* Currently, running separate CI tasks at the same time may intermittently fail, because they race to read/write `/tmp/env`. Fix this by adding `$CONTAINER_NAME` to the file name.
* Also, add `$USER`, while touching the line, to allow different users to run the same CI task at the same time.
* Also, skip the git install if there is no need.
Ref: https://github.com/bitcoin/bitcoin/pull/29274
ACKs for top commit:
Sjors:
ACK fa91bf2559d2e839592bf1dc1d423d5fb1c3573e
BrandonOdiwuor:
ACK fa91bf2559d2e839592bf1dc1d423d5fb1c3573e
hebasto:
ACK fa91bf2559d2e839592bf1dc1d423d5fb1c3573e.
Tree-SHA512: 9a8479255a2afb6618f9d0796488d9430ba95266b90ce39536a9817c1974ca4049beeaab5355a38b25171f76fc386dbec06b1919aaa079f08a5a0c0a146232c8
-rw-r--r-- | .cirrus.yml | 4 | ||||
-rwxr-xr-x | ci/test/02_run_container.sh | 8 |
2 files changed, 7 insertions, 5 deletions
diff --git a/.cirrus.yml b/.cirrus.yml index 6628d0bbbb..3c59e41a13 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -22,7 +22,7 @@ env: # Global defaults # - The ./ci/ depedencies (with cirrus-cli) should be installed: # # ``` -# apt update && apt install screen python3 bash podman-docker curl -y && curl -L -o cirrus "https://github.com/cirruslabs/cirrus-cli/releases/latest/download/cirrus-linux-$(dpkg --print-architecture)" && mv cirrus /usr/local/bin/cirrus && chmod +x /usr/local/bin/cirrus +# apt update && apt install git screen python3 bash podman-docker curl -y && curl -L -o cirrus "https://github.com/cirruslabs/cirrus-cli/releases/latest/download/cirrus-linux-$(dpkg --print-architecture)" && mv cirrus /usr/local/bin/cirrus && chmod +x /usr/local/bin/cirrus # ``` # # - There are no strict requirements on the hardware, because having less CPUs @@ -55,7 +55,7 @@ base_template: &BASE_TEMPLATE << : *FILTER_TEMPLATE merge_base_script: # Unconditionally install git (used in fingerprint_script). - - bash -c "$PACKAGE_MANAGER_INSTALL git" + - git --version || bash -c "$PACKAGE_MANAGER_INSTALL git" - if [ "$CIRRUS_PR" = "" ]; then exit 0; fi - git fetch --depth=1 $CIRRUS_REPO_CLONE_URL "pull/${CIRRUS_PR}/merge" - git checkout FETCH_HEAD # Use merged changes to detect silent merge conflicts diff --git a/ci/test/02_run_container.sh b/ci/test/02_run_container.sh index 8a7a978994..e6c4a61341 100755 --- a/ci/test/02_run_container.sh +++ b/ci/test/02_run_container.sh @@ -12,9 +12,9 @@ set -ex if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then # Export all env vars to avoid missing some. # Though, exclude those with newlines to avoid parsing problems. - 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 + 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-$USER-$CONTAINER_NAME" # 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 + docker run --rm "${CI_IMAGE_NAME_TAG}" bash -c "env | grep --extended-regexp '^(HOME|PATH|USER)='" | tee --append "/tmp/env-$USER-$CONTAINER_NAME" echo "Creating $CI_IMAGE_NAME_TAG container to run in" DOCKER_BUILDKIT=1 docker build \ --file "${BASE_READ_ONLY_DIR}/ci/test_imagefile" \ @@ -44,6 +44,8 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then # When detecting podman-docker, `--external` should be added. docker image prune --force --filter "label=$CI_IMAGE_LABEL" + # Append $USER to /tmp/env to support multi-user systems and $CONTAINER_NAME + # to allow support starting multiple runs simultaneously by the same user. # shellcheck disable=SC2086 CI_CONTAINER_ID=$(docker run --cap-add LINUX_IMMUTABLE $CI_CONTAINER_CAP --rm --interactive --detach --tty \ --mount "type=bind,src=$BASE_READ_ONLY_DIR,dst=$BASE_READ_ONLY_DIR,readonly" \ @@ -52,7 +54,7 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then --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" \ --mount "type=volume,src=${CONTAINER_NAME}_previous_releases,dst=$PREVIOUS_RELEASES_DIR" \ - --env-file /tmp/env \ + --env-file /tmp/env-$USER-$CONTAINER_NAME \ --name "$CONTAINER_NAME" \ "$CONTAINER_NAME") export CI_CONTAINER_ID |