Skip to content

Commit bdddf36

Browse files
committed
Merge bitcoin/bitcoin#29441: ci: Avoid CI failures from temp env file reuse
fa91bf2 ci: Skip git install if it is already installed (MarcoFalke) c65fde4 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: bitcoin/bitcoin#29274 ACKs for top commit: Sjors: ACK fa91bf2 BrandonOdiwuor: ACK fa91bf2 hebasto: ACK fa91bf2. Tree-SHA512: 9a8479255a2afb6618f9d0796488d9430ba95266b90ce39536a9817c1974ca4049beeaab5355a38b25171f76fc386dbec06b1919aaa079f08a5a0c0a146232c8
2 parents b1a46b2 + fa91bf2 commit bdddf36

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

.cirrus.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env: # Global defaults
2222
# - The ./ci/ depedencies (with cirrus-cli) should be installed:
2323
#
2424
# ```
25-
# 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
25+
# 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
2626
# ```
2727
#
2828
# - There are no strict requirements on the hardware, because having less CPUs
@@ -55,7 +55,7 @@ base_template: &BASE_TEMPLATE
5555
<< : *FILTER_TEMPLATE
5656
merge_base_script:
5757
# Unconditionally install git (used in fingerprint_script).
58-
- bash -c "$PACKAGE_MANAGER_INSTALL git"
58+
- git --version || bash -c "$PACKAGE_MANAGER_INSTALL git"
5959
- if [ "$CIRRUS_PR" = "" ]; then exit 0; fi
6060
- git fetch --depth=1 $CIRRUS_REPO_CLONE_URL "pull/${CIRRUS_PR}/merge"
6161
- git checkout FETCH_HEAD # Use merged changes to detect silent merge conflicts

ci/test/02_run_container.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ set -ex
1212
if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
1313
# Export all env vars to avoid missing some.
1414
# Though, exclude those with newlines to avoid parsing problems.
15-
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
15+
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"
1616
# System-dependent env vars must be kept as is. So read them from the container.
17-
docker run --rm "${CI_IMAGE_NAME_TAG}" bash -c "env | grep --extended-regexp '^(HOME|PATH|USER)='" | tee --append /tmp/env
17+
docker run --rm "${CI_IMAGE_NAME_TAG}" bash -c "env | grep --extended-regexp '^(HOME|PATH|USER)='" | tee --append "/tmp/env-$USER-$CONTAINER_NAME"
1818
echo "Creating $CI_IMAGE_NAME_TAG container to run in"
1919
DOCKER_BUILDKIT=1 docker build \
2020
--file "${BASE_READ_ONLY_DIR}/ci/test_imagefile" \
@@ -44,6 +44,8 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
4444
# When detecting podman-docker, `--external` should be added.
4545
docker image prune --force --filter "label=$CI_IMAGE_LABEL"
4646

47+
# Append $USER to /tmp/env to support multi-user systems and $CONTAINER_NAME
48+
# to allow support starting multiple runs simultaneously by the same user.
4749
# shellcheck disable=SC2086
4850
CI_CONTAINER_ID=$(docker run --cap-add LINUX_IMMUTABLE $CI_CONTAINER_CAP --rm --interactive --detach --tty \
4951
--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
5254
--mount "type=volume,src=${CONTAINER_NAME}_depends_sources,dst=$DEPENDS_DIR/sources" \
5355
--mount "type=volume,src=${CONTAINER_NAME}_depends_SDKs_android,dst=$DEPENDS_DIR/SDKs/android" \
5456
--mount "type=volume,src=${CONTAINER_NAME}_previous_releases,dst=$PREVIOUS_RELEASES_DIR" \
55-
--env-file /tmp/env \
57+
--env-file /tmp/env-$USER-$CONTAINER_NAME \
5658
--name "$CONTAINER_NAME" \
5759
"$CONTAINER_NAME")
5860
export CI_CONTAINER_ID

0 commit comments

Comments
 (0)