Skip to content

ci: isolate container test networks - #35417

Closed
willcl-ark wants to merge 2 commits into
bitcoin:masterfrom
willcl-ark:container-networks
Closed

willcl-ark wants to merge 2 commits into
bitcoin:masterfrom
willcl-ark:container-networks

Conversation

@willcl-ark

Copy link
Copy Markdown
Member

Fixes #35416

Local CI jobs currently share Docker networks while requesting fixed
routable addresses. That prevents two jobs from running at the same time
because the second container cannot claim the same static IPs. See
33362.

Name the networks "{container_name}-ipv[4|6]", using a subnet based on
the hash of their name, so each CI job gets a separate network while the
tests continue to see the addresses they expect.

Increment them to 11.x.x.x and 1111:2222:x to avoid hitting (existing) dangling networks on machines.

On successful runs, the networks are cleaned up. On failed runs they will remain (as they are being used by the failing container).

@DrahtBot DrahtBot added the Tests label May 29, 2026
@DrahtBot

DrahtBot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK fanquake

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

No conflicts as of last run.

@willcl-ark

Copy link
Copy Markdown
Member Author

Implements one apprach from #35416 (comment)

I tried other ways of generating deterministic networks here (we have prcedent for using 'os.getpid()`), but I think in the end this is probably the most robust idea.

IMO cleaning up the networks is nicer, but I can drop that commit if it's not wanted for some reason unknown to me currently (or i can squash it).

Also open to other solutions here.

@fanquake

Copy link
Copy Markdown
Member

Concept ACK - thanks for following up here.

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, seems fine. Left some nits

Comment thread ci/test/02_run_container.py Resolved
Comment thread ci/test/02_run_container.py Resolved
Comment thread ci/test/02_run_container.py Resolved
Local CI jobs currently share Docker networks while requesting fixed
routable addresses. That prevents two jobs from running at the same time
because the second container cannot claim the same static IPs. See
33362.

Name the networks "{container_name}-ipv[4|6]", using a subnet based on
the hash of their name, so each CI job gets a separate network while the
tests continue to see the addresses they expect.
Previously the (single, shared) networks were left in docker after runs,
but with a network container this may get messy.

Remove the IPv4 and IPv6 networks when the run is successful. On a
failed run, networks will remain dangling and need manual pruning (same
behaviour as previously).

We can't remove networks automagically form failed runs without first
killing the container (docker doesn't let you remove networks which are
active), which we want to avoid so we can jump in to failures.
@DrahtBot

Copy link
Copy Markdown
Contributor

CI failure:

+ docker network create --ipv6 --subnet 11.51.44.16/28 --subnet 1111:2222::3:32c1:0/112 ci_arm_linux-net
cd1c43f84c4b72cb079c930b48765e36ea8e79d751d336e90365917a9f5a72d9
Prune all dangling bitcoin-ci-test images
+ docker image prune --force --filter label=bitcoin-ci-test
Total reclaimed space: 0B
+ docker run --rm --interactive --detach --tty --cap-add=LINUX_IMMUTABLE --mount=type=bind,src=/home/runner/work/bitcoin/bitcoin,dst=/home/runner/work/bitcoin/bitcoin,readonly --mount=type=bind,src=/home/runner/work/_temp/ccache_dir,dst=/home/runner/work/_temp/ccache_dir --mount=type=bind,src=/home/runner/work/_temp/depends/built,dst=/home/runner/work/_temp/depends/built --mount=type=bind,src=/home/runner/work/_temp/depends/sources,dst=/home/runner/work/_temp/depends/sources --mount=type=bind,src=/home/runner/work/_temp/previous_releases,dst=/home/runner/work/_temp/previous_releases --mount=type=bind,src=/home/runner/work/_temp/build,dst=/home/runner/work/_temp/build --env-file=/tmp/env-runner-ci_arm_linux --name=ci_arm_linux --network=none --platform=linux/arm64 ci_arm_linux
+ docker network connect --ip=11.51.44.21 --ip6=1111:2222::3:32c1:5 ci_arm_linux-net b9b658b4df7a1d872d5e588104b7ff98d97f76a0c19fac54310aeef8bd2f23eb
Error response from daemon: container cannot be connected to multiple networks with one of the networks in private (none) mode
Command '['docker', 'network', 'connect', '--ip=11.51.44.21', '--ip6=1111:2222::3:32c1:5', 'ci_arm_linux-net', 'b9b658b4df7a1d872d5e588104b7ff98d97f76a0c19fac54310aeef8bd2f23eb']' returned non-zero exit status 1.

@DrahtBot
DrahtBot marked this pull request as draft June 19, 2026 08:46
@DrahtBot

Copy link
Copy Markdown
Contributor

Converted to draft, due to failing CI

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left more feedback, and already addressed all in #36435

Also, rewritten the branch by inverting the commit order for easier review.



def get_container_network_config(container_name):
host_id = int.from_bytes(hashlib.sha256(container_name.encode()).digest()[:4], "big") % ((1 << 20) - 1) + 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems a bit confusing to do all the hashing and the -1, and the +1 "hacks", when a stable int id can just be derived from the container (or rather sorted file name index) name directly. Of course this won't be stable across commits, but we can't really guarantee cross-commit ci concurrent runs anyway?

run(["docker", "network", "create", "--ipv6", "--subnet", "1111:1111::/112", "ci-ip6net"], check=False)
run(["docker", "network", "create", "--subnet", "1.1.1.0/24", "ci-ip4net"], check=False)
network_name = f"{os.environ['CONTAINER_NAME']}-net"
run(["docker", "network", "create", "--ipv6", "--subnet", str(ip4_subnet), "--subnet", str(ip6_subnet), network_name], check=False)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check=False now makes me a bit uneasy. Should be safer to remove and check?

# ifconfig INTERFACE_NAME 1.1.1.5 -alias && ifconfig INTERFACE_NAME inet6 1111:1111::5 -alias # to remove it, after the test
ADDR1 = '1.1.1.5' # This and the address below are set in the CI environment, don't change it just here (keep them in sync).
ADDR2 = '1111:1111::5'
ADDR1 = os.getenv('BIND_TEST_ROUTABLE_IPV4', '1.1.1.5') # This and the address below are set in the CI environment, don't change it just here (keep them in sync).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment can be removed and the skip msg below needs an update?

Comment on lines 170 to +181
@@ -156,7 +178,7 @@ def main():
text=True,
).stdout.strip()

run(["docker", "network", "connect", "--ip=1.1.1.5", "ci-ip4net", container_id]) # The IP address is used by some of the tests, don't change it just here (keep them in sync).
run(["docker", "network", "connect", f"--ip={os.environ['BIND_TEST_ROUTABLE_IPV4']}", f"--ip6={os.environ['BIND_TEST_ROUTABLE_IPV6']}", network_name, container_id])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the network=none fails ci, so probably needs the --ip=... and ip6=... passed directly above?

@willcl-ark willcl-ark closed this Oct 6, 2026
@willcl-ark

Copy link
Copy Markdown
Member Author

Closed in favour of #36436

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: side-effects from #33362

4 participants