Upload folder using huggingface_hub (part 182)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- 20260907-014711-computing-math-e1c8fb/environment/public_data/input/tutorial_source.html +686 -0
- 20260907-014711-computing-math-e1c8fb/environment/public_data/input/tutorial_text_windows.csv +174 -0
- 20260907-014711-computing-math-e1c8fb/environment/public_data/main.py +180 -0
- 20260907-014711-computing-math-e1c8fb/environment/public_data/software/command_examples.csv +8 -0
- 20260907-014711-computing-math-e1c8fb/environment/public_data/software/software_manifest.json +17 -0
- 20260907-014711-computing-math-e1c8fb/environment/public_data/software/validate_outputs.py +41 -0
- 20260907-014711-computing-math-e1c8fb/environment/public_data/task_card.json +112 -0
- 20260907-014711-computing-math-e1c8fb/instruction.md +33 -0
- 20260907-014711-computing-math-e1c8fb/solution/internal/workflow_adapters_runtime.py +679 -0
- 20260907-014711-computing-math-e1c8fb/solution/internal/workflow_runtime.py +5 -0
- 20260907-014711-computing-math-e1c8fb/solution/reference_solution.py +20 -0
- 20260907-014711-computing-math-e1c8fb/solution/solve.sh +7 -0
- 20260907-014711-computing-math-e1c8fb/task.toml +45 -0
- 20260907-014711-computing-math-e1c8fb/tests/Dockerfile +6 -0
- 20260907-014711-computing-math-e1c8fb/tests/evaluator_runner.py +92 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/__pycache__/evaluator.cpython-312.pyc +0 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/evaluator.py +114 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/ground_truth/code_block_inventory.csv +34 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/ground_truth/keyword_inventory.csv +12 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/ground_truth/section_outline.csv +20 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/ground_truth/summary.json +11 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/internal/workflow_adapters_runtime.py +679 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/internal/workflow_runtime.py +5 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/reference_manifest.json +34 -0
- 20260907-014711-computing-math-e1c8fb/tests/reference/reference_solution.py +20 -0
- 20260907-014711-computing-math-e1c8fb/tests/test.sh +29 -0
- 20260907-014716-computing-math-8018f2/.DS_Store +3 -0
- 20260907-014716-computing-math-8018f2/environment/Dockerfile +12 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/README.md +11 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/input/README.md +6 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/input/analysis_spec.json +93 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/input/source_context_windows.jsonl +0 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/input/tutorial_metadata.json +31 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/input/tutorial_source.html +686 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/input/tutorial_text_windows.csv +174 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/main.py +180 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/software/command_examples.csv +8 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/software/software_manifest.json +17 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/software/validate_outputs.py +41 -0
- 20260907-014716-computing-math-8018f2/environment/public_data/task_card.json +112 -0
- 20260907-014716-computing-math-8018f2/instruction.md +33 -0
- 20260907-014716-computing-math-8018f2/solution/internal/workflow_adapters_runtime.py +679 -0
- 20260907-014716-computing-math-8018f2/solution/internal/workflow_runtime.py +5 -0
- 20260907-014716-computing-math-8018f2/solution/reference_solution.py +20 -0
- 20260907-014716-computing-math-8018f2/solution/solve.sh +7 -0
- 20260907-014716-computing-math-8018f2/task.toml +45 -0
- 20260907-014716-computing-math-8018f2/tests/Dockerfile +6 -0
- 20260907-014716-computing-math-8018f2/tests/evaluator_runner.py +92 -0
- 20260907-014716-computing-math-8018f2/tests/reference/__pycache__/evaluator.cpython-312.pyc +0 -0
- 20260907-014716-computing-math-8018f2/tests/reference/evaluator.py +114 -0
20260907-014711-computing-math-e1c8fb/environment/public_data/input/tutorial_source.html
ADDED
|
@@ -0,0 +1,686 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Source 1: bridge.md
|
| 2 |
+
|
| 3 |
+
- URL: https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md
|
| 4 |
+
- SHA256: f5d1811100422cd6108a833b6485b7745ce7939b51f5826099242dde00b2f3b5
|
| 5 |
+
- Bytes: 27467
|
| 6 |
+
|
| 7 |
+
```markdown
|
| 8 |
+
---
|
| 9 |
+
title: Bridge network driver
|
| 10 |
+
description: All about using user-defined bridge networks and the default bridge
|
| 11 |
+
keywords: network, bridge, user-defined, standalone
|
| 12 |
+
aliases:
|
| 13 |
+
- /config/containers/bridges/
|
| 14 |
+
- /engine/userguide/networking/default_network/build-bridges/
|
| 15 |
+
- /engine/userguide/networking/default_network/custom-docker0/
|
| 16 |
+
- /engine/userguide/networking/work-with-networks/
|
| 17 |
+
- /network/bridge/
|
| 18 |
+
- /network/drivers/bridge/
|
| 19 |
+
- /engine/network/tutorials/standalone/
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
A Docker bridge network has an IPv4 subnet and, optionally, an IPv6 subnet.
|
| 23 |
+
Each container connected to the bridge network has a network interface with
|
| 24 |
+
addresses in the network's subnets. By default, it:
|
| 25 |
+
|
| 26 |
+
- Allows unrestricted network access to containers in the network from
|
| 27 |
+
the host, and from other containers connected to the same bridge network.
|
| 28 |
+
- Blocks access from containers in other networks and from outside the
|
| 29 |
+
Docker host.
|
| 30 |
+
- Uses masquerading to give containers external network access. Devices on
|
| 31 |
+
the host's external networks only see the IP address of the Docker host.
|
| 32 |
+
- Supports port publishing, where network traffic is forwarded between
|
| 33 |
+
container ports and ports on host IP addresses. The published ports
|
| 34 |
+
can be accessed from outside the Docker host, on its IP addresses.
|
| 35 |
+
|
| 36 |
+
In terms of Docker, a bridge network uses a software bridge which lets
|
| 37 |
+
containers connected to the same bridge network communicate, while providing
|
| 38 |
+
isolation from containers that aren't connected to that bridge network. By
|
| 39 |
+
default, the Docker bridge driver automatically installs rules in the host
|
| 40 |
+
machine so that containers connected to different bridge networks can only
|
| 41 |
+
communicate with each other using published ports.
|
| 42 |
+
|
| 43 |
+
Bridge networks apply to containers running on the same Docker daemon host.
|
| 44 |
+
For communication among containers running on different Docker daemon hosts, you
|
| 45 |
+
can either manage routing at the OS level, or you can use an
|
| 46 |
+
[overlay network](overlay.md).
|
| 47 |
+
|
| 48 |
+
When you start Docker, a [default bridge network](#use-the-default-bridge-network) (also
|
| 49 |
+
called `bridge`) is created automatically, and newly-started containers connect
|
| 50 |
+
to it unless otherwise specified. You can also create user-defined custom bridge
|
| 51 |
+
networks. **User-defined bridge networks are superior to the default `bridge`
|
| 52 |
+
network.**
|
| 53 |
+
|
| 54 |
+
## Differences between user-defined bridges and the default bridge
|
| 55 |
+
|
| 56 |
+
- **User-defined bridges provide automatic DNS resolution between containers**.
|
| 57 |
+
|
| 58 |
+
Containers on the default bridge network can only access each other by IP
|
| 59 |
+
addresses, unless you use the [`--link` option](../links.md), which is
|
| 60 |
+
considered legacy. On a user-defined bridge network, containers can resolve
|
| 61 |
+
each other by name or alias.
|
| 62 |
+
|
| 63 |
+
Imagine an application with a web front-end and a database back-end. If you call
|
| 64 |
+
your containers `web` and `db`, the web container can connect to the db container
|
| 65 |
+
at `db`, no matter which Docker host the application stack is running on.
|
| 66 |
+
|
| 67 |
+
If you run the same application stack on the default bridge network, you need
|
| 68 |
+
to manually create links between the containers (using the legacy `--link`
|
| 69 |
+
flag). These links need to be created in both directions, so you can see this
|
| 70 |
+
gets complex with more than two containers which need to communicate.
|
| 71 |
+
Alternatively, you can manipulate the `/etc/hosts` files within the containers,
|
| 72 |
+
but this creates problems that are difficult to debug.
|
| 73 |
+
|
| 74 |
+
- **User-defined bridges provide better isolation**.
|
| 75 |
+
|
| 76 |
+
All containers without a `--network` specified, are attached to the default bridge network. This can be a risk, as unrelated stacks/services/containers are then able to communicate.
|
| 77 |
+
|
| 78 |
+
Using a user-defined network provides a scoped network in which only containers attached to that network are able to communicate.
|
| 79 |
+
|
| 80 |
+
- **Containers can be attached and detached from user-defined networks on the fly**.
|
| 81 |
+
|
| 82 |
+
During a container's lifetime, you can connect or disconnect it from
|
| 83 |
+
user-defined networks on the fly. To remove a container from the default
|
| 84 |
+
bridge network, you need to stop the container and recreate it with different
|
| 85 |
+
network options.
|
| 86 |
+
|
| 87 |
+
- **Each user-defined network creates a configurable bridge**.
|
| 88 |
+
|
| 89 |
+
If your containers use the default bridge network, you can configure it, but
|
| 90 |
+
all the containers use the same settings, such as MTU and `iptables` rules.
|
| 91 |
+
In addition, configuring the default bridge network happens outside of Docker
|
| 92 |
+
itself, and requires a restart of Docker.
|
| 93 |
+
|
| 94 |
+
User-defined bridge networks are created and configured using
|
| 95 |
+
`docker network create`. If different groups of applications have different
|
| 96 |
+
network requirements, you can configure each user-defined bridge separately,
|
| 97 |
+
as you create it.
|
| 98 |
+
|
| 99 |
+
- **Linked containers on the default bridge network share environment variables**.
|
| 100 |
+
|
| 101 |
+
Originally, the only way to share environment variables between two containers
|
| 102 |
+
was to link them using the [`--link` flag](../links.md). This type of
|
| 103 |
+
variable sharing isn't possible with user-defined networks. However, there
|
| 104 |
+
are superior ways to share environment variables. A few ideas:
|
| 105 |
+
- Multiple containers can mount a file or directory containing the shared
|
| 106 |
+
information, using a Docker volume.
|
| 107 |
+
|
| 108 |
+
- Multiple containers can be started together using `docker-compose` and the
|
| 109 |
+
compose file can define the shared variables.
|
| 110 |
+
|
| 111 |
+
- You can use swarm services instead of standalone containers, and take
|
| 112 |
+
advantage of shared [secrets](/manuals/engine/swarm/secrets.md) and
|
| 113 |
+
[configs](/manuals/engine/swarm/configs.md).
|
| 114 |
+
|
| 115 |
+
Containers connected to the same user-defined bridge network effectively expose all ports
|
| 116 |
+
to each other. For a port to be accessible to containers or non-Docker hosts on
|
| 117 |
+
different networks, that port must be _published_ using the `-p` or `--publish`
|
| 118 |
+
flag.
|
| 119 |
+
|
| 120 |
+
## Options
|
| 121 |
+
|
| 122 |
+
The following table describes the driver-specific options that you can pass to
|
| 123 |
+
`--opt` when creating a custom network using the `bridge` driver.
|
| 124 |
+
|
| 125 |
+
| Option | Default | Description |
|
| 126 |
+
| ----------------------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
| 127 |
+
| `com.docker.network.bridge.name` | | Interface name to use when creating the Linux bridge. |
|
| 128 |
+
| `com.docker.network.bridge.enable_ip_masquerade` | `true` | Enable IP masquerading. |
|
| 129 |
+
| `com.docker.network.host_ipv4`<br/>`com.docker.network.host_ipv6` | | Address to use for source NAT. See [Port publishing](../port-publishing.md#masquerade-or-snat-for-outgoing-packets). |
|
| 130 |
+
| `com.docker.network.bridge.gateway_mode_ipv4`<br/>`com.docker.network.bridge.gateway_mode_ipv6` | `nat` | Control external connectivity. See [Port publishing](../port-publishing.md#gateway-modes). |
|
| 131 |
+
| `com.docker.network.bridge.enable_icc` | `true` | Enable or Disable inter-container connectivity. |
|
| 132 |
+
| `com.docker.network.bridge.host_binding_ipv4` | all IPv4 and IPv6 addresses | Default IP when binding container ports. |
|
| 133 |
+
| `com.docker.network.driver.mtu` | `0` (no limit) | Set the containers network Maximum Transmission Unit (MTU). |
|
| 134 |
+
| `com.docker.network.container_iface_prefix` | `eth` | Set a custom prefix for container interfaces. |
|
| 135 |
+
| `com.docker.network.bridge.inhibit_ipv4` | `false` | Prevent Docker from [assigning an IP address](#skip-bridge-ip-address-configuration) to the bridge. |
|
| 136 |
+
|
| 137 |
+
Some of these options are also available as flags to the `dockerd` CLI, and you
|
| 138 |
+
can use them to configure the default `docker0` bridge when starting the Docker
|
| 139 |
+
daemon. The following table shows which options have equivalent flags in the
|
| 140 |
+
`dockerd` CLI.
|
| 141 |
+
|
| 142 |
+
| Option | Flag |
|
| 143 |
+
| ------------------------------------------------ | ----------- |
|
| 144 |
+
| `com.docker.network.bridge.name` | - |
|
| 145 |
+
| `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq` |
|
| 146 |
+
| `com.docker.network.bridge.enable_icc` | `--icc` |
|
| 147 |
+
| `com.docker.network.bridge.host_binding_ipv4` | `--ip` |
|
| 148 |
+
| `com.docker.network.driver.mtu` | `--mtu` |
|
| 149 |
+
| `com.docker.network.container_iface_prefix` | - |
|
| 150 |
+
|
| 151 |
+
The Docker daemon supports a `--bridge` flag, which you can use to define
|
| 152 |
+
your own `docker0` bridge. Use this option if you want to run multiple daemon
|
| 153 |
+
instances on the same host. For details, see
|
| 154 |
+
[Run multiple daemons](/reference/cli/dockerd.md#run-multiple-daemons).
|
| 155 |
+
|
| 156 |
+
### Default host binding address
|
| 157 |
+
|
| 158 |
+
When no host address is given in port publishing options like `-p 80`
|
| 159 |
+
or `-p 8080:80`, the default is to make the container's port 80 available on all
|
| 160 |
+
host addresses, IPv4 and IPv6.
|
| 161 |
+
|
| 162 |
+
The bridge network driver option `com.docker.network.bridge.host_binding_ipv4`
|
| 163 |
+
can be used to modify the default address for published ports.
|
| 164 |
+
|
| 165 |
+
Despite the option's name, it is possible to specify an IPv6 address.
|
| 166 |
+
|
| 167 |
+
When the default binding address is an address assigned to a specific interface,
|
| 168 |
+
the container's port will only be accessible via that address.
|
| 169 |
+
|
| 170 |
+
Setting the default binding address to `::` means published ports will only be
|
| 171 |
+
available on the host's IPv6 addresses. However, setting it to `0.0.0.0` means it
|
| 172 |
+
will be available on the host's IPv4 and IPv6 addresses.
|
| 173 |
+
|
| 174 |
+
To restrict a published port to IPv4 only, the address must be included in the
|
| 175 |
+
container's publishing options. For example, `-p 0.0.0.0:8080:80`.
|
| 176 |
+
|
| 177 |
+
## Manage a user-defined bridge
|
| 178 |
+
|
| 179 |
+
Use the `docker network create` command to create a user-defined bridge
|
| 180 |
+
network.
|
| 181 |
+
|
| 182 |
+
```console
|
| 183 |
+
$ docker network create my-net
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
You can specify the subnet, the IP address range, the gateway, and other
|
| 187 |
+
options. See the
|
| 188 |
+
[docker network create](/reference/cli/docker/network/create/#specify-advanced-options)
|
| 189 |
+
reference or the output of `docker network create --help` for details.
|
| 190 |
+
|
| 191 |
+
Use the `docker network rm` command to remove a user-defined bridge
|
| 192 |
+
network. If containers are currently connected to the network,
|
| 193 |
+
[disconnect them](#disconnect-a-container-from-a-user-defined-bridge)
|
| 194 |
+
first.
|
| 195 |
+
|
| 196 |
+
```console
|
| 197 |
+
$ docker network rm my-net
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
> **What's really happening?**
|
| 201 |
+
>
|
| 202 |
+
> When you create or remove a user-defined bridge or connect or disconnect a
|
| 203 |
+
> container from a user-defined bridge, Docker uses tools specific to the
|
| 204 |
+
> operating system to manage the underlying network infrastructure (such as adding
|
| 205 |
+
> or removing bridge devices or configuring `iptables` rules on Linux). These
|
| 206 |
+
> details should be considered implementation details. Let Docker manage your
|
| 207 |
+
> user-defined networks for you.
|
| 208 |
+
|
| 209 |
+
## Connect a container to a user-defined bridge
|
| 210 |
+
|
| 211 |
+
When you create a new container, you can specify one or more `--network` flags.
|
| 212 |
+
This example connects an Nginx container to the `my-net` network. It also
|
| 213 |
+
publishes port 80 in the container to port 8080 on the Docker host, so external
|
| 214 |
+
clients can access that port. Any other container connected to the `my-net`
|
| 215 |
+
network has access to all ports on the `my-nginx` container, and vice versa.
|
| 216 |
+
|
| 217 |
+
```console
|
| 218 |
+
$ docker create --name my-nginx \
|
| 219 |
+
--network my-net \
|
| 220 |
+
--publish 8080:80 \
|
| 221 |
+
nginx:latest
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
To connect a **running** container to an existing user-defined bridge, use the
|
| 225 |
+
`docker network connect` command. The following command connects an already-running
|
| 226 |
+
`my-nginx` container to an already-existing `my-net` network:
|
| 227 |
+
|
| 228 |
+
```console
|
| 229 |
+
$ docker network connect my-net my-nginx
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
## Disconnect a container from a user-defined bridge
|
| 233 |
+
|
| 234 |
+
To disconnect a running container from a user-defined bridge, use the
|
| 235 |
+
`docker network disconnect` command. The following command disconnects
|
| 236 |
+
the `my-nginx` container from the `my-net` network.
|
| 237 |
+
|
| 238 |
+
```console
|
| 239 |
+
$ docker network disconnect my-net my-nginx
|
| 240 |
+
```
|
| 241 |
+
|
| 242 |
+
## Use IPv6 in a user-defined bridge network
|
| 243 |
+
|
| 244 |
+
When you create your network, you can specify the `--ipv6` flag to enable IPv6.
|
| 245 |
+
|
| 246 |
+
```console
|
| 247 |
+
$ docker network create --ipv6 --subnet 2001:db8:1234::/64 my-net
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
If you do not provide a `--subnet` option, a Unique Local Address (ULA) prefix
|
| 251 |
+
will be chosen automatically.
|
| 252 |
+
|
| 253 |
+
## IPv6-only bridge networks
|
| 254 |
+
|
| 255 |
+
To skip IPv4 address configuration on the bridge and in its containers, create
|
| 256 |
+
the network with option `--ipv4=false`, and enable IPv6 using `--ipv6`.
|
| 257 |
+
|
| 258 |
+
```console
|
| 259 |
+
$ docker network create --ipv6 --ipv4=false v6net
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
IPv4 address configuration cannot be disabled in the default bridge network.
|
| 263 |
+
|
| 264 |
+
## Use the default bridge network
|
| 265 |
+
|
| 266 |
+
The default `bridge` network is considered a legacy detail of Docker and is not
|
| 267 |
+
recommended for production use. Configuring it is a manual operation, and it has
|
| 268 |
+
[technical shortcomings](#differences-between-user-defined-bridges-and-the-default-bridge).
|
| 269 |
+
|
| 270 |
+
### Connect a container to the default bridge network
|
| 271 |
+
|
| 272 |
+
If you do not specify a network using the `--network` flag, and you do specify a
|
| 273 |
+
network driver, your container is connected to the default `bridge` network by
|
| 274 |
+
default. Containers connected to the default `bridge` network can communicate,
|
| 275 |
+
but only by IP address, unless they're linked using the
|
| 276 |
+
[legacy `--link` flag](../links.md).
|
| 277 |
+
|
| 278 |
+
### Configure the default bridge network
|
| 279 |
+
|
| 280 |
+
To configure the default `bridge` network, you specify options in `daemon.json`.
|
| 281 |
+
Here is an example `daemon.json` with several options specified. Only specify
|
| 282 |
+
the settings you need to customize.
|
| 283 |
+
|
| 284 |
+
```json
|
| 285 |
+
{
|
| 286 |
+
"bip": "192.168.1.1/24",
|
| 287 |
+
"fixed-cidr": "192.168.1.0/25",
|
| 288 |
+
"mtu": 1500,
|
| 289 |
+
"default-gateway": "192.168.1.254",
|
| 290 |
+
"dns": ["10.20.1.2", "10.20.1.3"]
|
| 291 |
+
}
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
In this example:
|
| 295 |
+
|
| 296 |
+
- The bridge's address is "192.168.1.1/24" (from `bip`).
|
| 297 |
+
- The bridge network's subnet is "192.168.1.0/24" (from `bip`).
|
| 298 |
+
- Container addresses will be allocated from "192.168.1.0/25" (from `fixed-cidr`).
|
| 299 |
+
|
| 300 |
+
### Use IPv6 with the default bridge network
|
| 301 |
+
|
| 302 |
+
IPv6 can be enabled for the default bridge using the following options in
|
| 303 |
+
`daemon.json`, or their command line equivalents.
|
| 304 |
+
|
| 305 |
+
These three options only affect the default bridge, they are not used by
|
| 306 |
+
user-defined networks. The addresses in below are examples from the
|
| 307 |
+
IPv6 documentation range.
|
| 308 |
+
|
| 309 |
+
- Option `ipv6` is required.
|
| 310 |
+
- Option `bip6` is optional, it specifies the address of the default bridge, which
|
| 311 |
+
will be used as the default gateway by containers. It also specifies the subnet
|
| 312 |
+
for the bridge network.
|
| 313 |
+
- Option `fixed-cidr-v6` is optional, it specifies the address range Docker may
|
| 314 |
+
automatically allocate to containers.
|
| 315 |
+
- The prefix should normally be `/64` or shorter.
|
| 316 |
+
- For experimentation on a local network, it is better to use a Unique Local
|
| 317 |
+
Address (ULA) prefix (matching `fd00::/8`) than a Link Local prefix (matching
|
| 318 |
+
`fe80::/10`).
|
| 319 |
+
- Option `default-gateway-v6` is optional. If unspecified, the default is the first
|
| 320 |
+
address in the `fixed-cidr-v6` subnet.
|
| 321 |
+
|
| 322 |
+
```json
|
| 323 |
+
{
|
| 324 |
+
"ipv6": true,
|
| 325 |
+
"bip6": "2001:db8::1111/64",
|
| 326 |
+
"fixed-cidr-v6": "2001:db8::/64",
|
| 327 |
+
"default-gateway-v6": "2001:db8:abcd::89"
|
| 328 |
+
}
|
| 329 |
+
```
|
| 330 |
+
|
| 331 |
+
If no `bip6` is specified, `fixed-cidr-v6` defines the subnet for the bridge
|
| 332 |
+
network. If no `bip6` or `fixed-cidr-v6` is specified, a ULA prefix will be
|
| 333 |
+
chosen.
|
| 334 |
+
|
| 335 |
+
Restart Docker for changes to take effect.
|
| 336 |
+
|
| 337 |
+
## Connection limit for bridge networks
|
| 338 |
+
|
| 339 |
+
Due to limitations set by the Linux kernel, bridge networks become unstable and
|
| 340 |
+
inter-container communications may break when 1000 containers or more connect
|
| 341 |
+
to a single network.
|
| 342 |
+
|
| 343 |
+
For more information about this limitation, see
|
| 344 |
+
[moby/moby#44973](https://github.com/moby/moby/issues/44973#issuecomment-1543747718).
|
| 345 |
+
|
| 346 |
+
## Skip Bridge IP address configuration
|
| 347 |
+
|
| 348 |
+
The bridge is normally assigned the network's `--gateway` address, which is
|
| 349 |
+
used as the default route from the bridge network to other networks.
|
| 350 |
+
|
| 351 |
+
The `com.docker.network.bridge.inhibit_ipv4` option lets you create a network
|
| 352 |
+
without the IPv4 gateway address being assigned to the bridge. This is useful
|
| 353 |
+
if you want to configure the gateway IP address for the bridge manually. For
|
| 354 |
+
instance if you add a physical interface to your bridge, and need it to have
|
| 355 |
+
the gateway address.
|
| 356 |
+
|
| 357 |
+
With this configuration, north-south traffic (to and from the bridge network)
|
| 358 |
+
won't work unless you've manually configured the gateway address on the bridge,
|
| 359 |
+
or a device attached to it.
|
| 360 |
+
|
| 361 |
+
This option can only be used with user-defined bridge networks.
|
| 362 |
+
|
| 363 |
+
## Usage examples
|
| 364 |
+
|
| 365 |
+
This section provides hands-on examples for working with bridge networks.
|
| 366 |
+
|
| 367 |
+
### Use the default bridge network
|
| 368 |
+
|
| 369 |
+
This example shows how the default `bridge` network works. You start two
|
| 370 |
+
`alpine` containers on the default bridge and test how they communicate.
|
| 371 |
+
|
| 372 |
+
> [!NOTE]
|
| 373 |
+
> The default `bridge` network is not recommended for production. Use
|
| 374 |
+
> user-defined bridge networks instead.
|
| 375 |
+
|
| 376 |
+
1. List current networks:
|
| 377 |
+
|
| 378 |
+
```console
|
| 379 |
+
$ docker network ls
|
| 380 |
+
|
| 381 |
+
NETWORK ID NAME DRIVER SCOPE
|
| 382 |
+
17e324f45964 bridge bridge local
|
| 383 |
+
6ed54d316334 host host local
|
| 384 |
+
7092879f2cc8 none null local
|
| 385 |
+
```
|
| 386 |
+
|
| 387 |
+
The default `bridge` network is listed, along with `host` and `none`.
|
| 388 |
+
|
| 389 |
+
2. Start two `alpine` containers running `ash`. The `-dit` flags mean detached,
|
| 390 |
+
interactive, and with a TTY. Since you haven't specified a `--network` flag,
|
| 391 |
+
the containers connect to the default `bridge` network.
|
| 392 |
+
|
| 393 |
+
```console
|
| 394 |
+
$ docker run -dit --name alpine1 alpine ash
|
| 395 |
+
$ docker run -dit --name alpine2 alpine ash
|
| 396 |
+
```
|
| 397 |
+
|
| 398 |
+
Verify both containers are running:
|
| 399 |
+
|
| 400 |
+
```console
|
| 401 |
+
$ docker container ls
|
| 402 |
+
|
| 403 |
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
| 404 |
+
602dbf1edc81 alpine "ash" 4 seconds ago Up 3 seconds alpine2
|
| 405 |
+
da33b7aa74b0 alpine "ash" 17 seconds ago Up 16 seconds alpine1
|
| 406 |
+
```
|
| 407 |
+
|
| 408 |
+
3. Inspect the `bridge` network to see connected containers:
|
| 409 |
+
|
| 410 |
+
```console
|
| 411 |
+
$ docker network inspect bridge
|
| 412 |
+
```
|
| 413 |
+
|
| 414 |
+
The output shows both containers connected, with their assigned IP addresses
|
| 415 |
+
(`172.17.0.2` for `alpine1` and `172.17.0.3` for `alpine2`).
|
| 416 |
+
|
| 417 |
+
4. Connect to `alpine1`:
|
| 418 |
+
|
| 419 |
+
```console
|
| 420 |
+
$ docker attach alpine1
|
| 421 |
+
|
| 422 |
+
/ #
|
| 423 |
+
```
|
| 424 |
+
|
| 425 |
+
Show the network interfaces for `alpine1` from within the container:
|
| 426 |
+
|
| 427 |
+
```console
|
| 428 |
+
# ip addr show
|
| 429 |
+
|
| 430 |
+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
|
| 431 |
+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
| 432 |
+
inet 127.0.0.1/8 scope host lo
|
| 433 |
+
valid_lft forever preferred_lft forever
|
| 434 |
+
inet6 ::1/128 scope host
|
| 435 |
+
valid_lft forever preferred_lft forever
|
| 436 |
+
27: eth0@if28: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
|
| 437 |
+
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
|
| 438 |
+
inet 172.17.0.2/16 scope global eth0
|
| 439 |
+
valid_lft forever preferred_lft forever
|
| 440 |
+
```
|
| 441 |
+
|
| 442 |
+
In this example, the `eth0` interface has the IP address `172.17.0.2`.
|
| 443 |
+
|
| 444 |
+
5. From within `alpine1`, verify you can connect to the internet:
|
| 445 |
+
|
| 446 |
+
```console
|
| 447 |
+
# ping -c 2 google.com
|
| 448 |
+
|
| 449 |
+
PING google.com (172.217.3.174): 56 data bytes
|
| 450 |
+
64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.841 ms
|
| 451 |
+
64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.897 ms
|
| 452 |
+
|
| 453 |
+
--- google.com ping statistics ---
|
| 454 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 455 |
+
round-trip min/avg/max = 9.841/9.869/9.897 ms
|
| 456 |
+
```
|
| 457 |
+
|
| 458 |
+
6. Ping the second container by its IP address:
|
| 459 |
+
|
| 460 |
+
```console
|
| 461 |
+
# ping -c 2 172.17.0.3
|
| 462 |
+
|
| 463 |
+
PING 172.17.0.3 (172.17.0.3): 56 data bytes
|
| 464 |
+
64 bytes from 172.17.0.3: seq=0 ttl=64 time=0.086 ms
|
| 465 |
+
64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.094 ms
|
| 466 |
+
|
| 467 |
+
--- 172.17.0.3 ping statistics ---
|
| 468 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 469 |
+
round-trip min/avg/max = 0.086/0.090/0.094 ms
|
| 470 |
+
```
|
| 471 |
+
|
| 472 |
+
This succeeds. Now try pinging by container name:
|
| 473 |
+
|
| 474 |
+
```console
|
| 475 |
+
# ping -c 2 alpine2
|
| 476 |
+
|
| 477 |
+
ping: bad address 'alpine2'
|
| 478 |
+
```
|
| 479 |
+
|
| 480 |
+
On the default bridge network, containers can't resolve each other by name.
|
| 481 |
+
|
| 482 |
+
7. Detach from `alpine1` without stopping it using `CTRL+p CTRL+q`.
|
| 483 |
+
|
| 484 |
+
8. Clean up: stop the containers and remove them.
|
| 485 |
+
|
| 486 |
+
```console
|
| 487 |
+
$ docker container stop alpine1 alpine2
|
| 488 |
+
$ docker container rm alpine1 alpine2
|
| 489 |
+
```
|
| 490 |
+
|
| 491 |
+
Stopped containers lose their IP addresses.
|
| 492 |
+
|
| 493 |
+
### Use user-defined bridge networks
|
| 494 |
+
|
| 495 |
+
This example shows how user-defined bridge networks provide better isolation
|
| 496 |
+
and automatic DNS resolution between containers.
|
| 497 |
+
|
| 498 |
+
1. Create the `alpine-net` network:
|
| 499 |
+
|
| 500 |
+
```console
|
| 501 |
+
$ docker network create --driver bridge alpine-net
|
| 502 |
+
```
|
| 503 |
+
|
| 504 |
+
2. List Docker's networks:
|
| 505 |
+
|
| 506 |
+
```console
|
| 507 |
+
$ docker network ls
|
| 508 |
+
|
| 509 |
+
NETWORK ID NAME DRIVER SCOPE
|
| 510 |
+
e9261a8c9a19 alpine-net bridge local
|
| 511 |
+
17e324f45964 bridge bridge local
|
| 512 |
+
6ed54d316334 host host local
|
| 513 |
+
7092879f2cc8 none null local
|
| 514 |
+
```
|
| 515 |
+
|
| 516 |
+
Inspect the `alpine-net` network:
|
| 517 |
+
|
| 518 |
+
```console
|
| 519 |
+
$ docker network inspect alpine-net
|
| 520 |
+
```
|
| 521 |
+
|
| 522 |
+
This shows the network's gateway (for example, `172.18.0.1`) and that no
|
| 523 |
+
containers are connected yet.
|
| 524 |
+
|
| 525 |
+
3. Create four containers. Three connect to `alpine-net`, and one connects to
|
| 526 |
+
the default `bridge`. Then connect one container to both networks:
|
| 527 |
+
|
| 528 |
+
```console
|
| 529 |
+
$ docker run -dit --name alpine1 --network alpine-net alpine ash
|
| 530 |
+
$ docker run -dit --name alpine2 --network alpine-net alpine ash
|
| 531 |
+
$ docker run -dit --name alpine3 alpine ash
|
| 532 |
+
$ docker run -dit --name alpine4 --network alpine-net alpine ash
|
| 533 |
+
$ docker network connect bridge alpine4
|
| 534 |
+
```
|
| 535 |
+
|
| 536 |
+
Verify all containers are running:
|
| 537 |
+
|
| 538 |
+
```console
|
| 539 |
+
$ docker container ls
|
| 540 |
+
|
| 541 |
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
| 542 |
+
156849ccd902 alpine "ash" 41 seconds ago Up 41 seconds alpine4
|
| 543 |
+
fa1340b8d83e alpine "ash" 51 seconds ago Up 51 seconds alpine3
|
| 544 |
+
a535d969081e alpine "ash" About a minute ago Up About a minute alpine2
|
| 545 |
+
0a02c449a6e9 alpine "ash" About a minute ago Up About a minute alpine1
|
| 546 |
+
```
|
| 547 |
+
|
| 548 |
+
4. Inspect both networks again to see which containers are connected:
|
| 549 |
+
|
| 550 |
+
```console
|
| 551 |
+
$ docker network inspect bridge
|
| 552 |
+
```
|
| 553 |
+
|
| 554 |
+
Containers `alpine3` and `alpine4` are connected to the `bridge` network.
|
| 555 |
+
|
| 556 |
+
```console
|
| 557 |
+
$ docker network inspect alpine-net
|
| 558 |
+
```
|
| 559 |
+
|
| 560 |
+
Containers `alpine1`, `alpine2`, and `alpine4` are connected to
|
| 561 |
+
`alpine-net`.
|
| 562 |
+
|
| 563 |
+
5. On user-defined networks, containers can resolve each other by name. Connect
|
| 564 |
+
to `alpine1` and test:
|
| 565 |
+
|
| 566 |
+
> [!NOTE]
|
| 567 |
+
> Automatic service discovery only resolves custom container names, not
|
| 568 |
+
> default automatically generated names.
|
| 569 |
+
|
| 570 |
+
```console
|
| 571 |
+
$ docker container attach alpine1
|
| 572 |
+
|
| 573 |
+
# ping -c 2 alpine2
|
| 574 |
+
|
| 575 |
+
PING alpine2 (172.18.0.3): 56 data bytes
|
| 576 |
+
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.085 ms
|
| 577 |
+
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.090 ms
|
| 578 |
+
|
| 579 |
+
--- alpine2 ping statistics ---
|
| 580 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 581 |
+
round-trip min/avg/max = 0.085/0.087/0.090 ms
|
| 582 |
+
|
| 583 |
+
# ping -c 2 alpine4
|
| 584 |
+
|
| 585 |
+
PING alpine4 (172.18.0.4): 56 data bytes
|
| 586 |
+
64 bytes from 172.18.0.4: seq=0 ttl=64 time=0.076 ms
|
| 587 |
+
64 bytes from 172.18.0.4: seq=1 ttl=64 time=0.091 ms
|
| 588 |
+
|
| 589 |
+
--- alpine4 ping statistics ---
|
| 590 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 591 |
+
round-trip min/avg/max = 0.076/0.083/0.091 ms
|
| 592 |
+
```
|
| 593 |
+
|
| 594 |
+
6. From `alpine1`, you can't connect to `alpine3` because it's on a different
|
| 595 |
+
network:
|
| 596 |
+
|
| 597 |
+
```console
|
| 598 |
+
# ping -c 2 alpine3
|
| 599 |
+
|
| 600 |
+
ping: bad address 'alpine3'
|
| 601 |
+
```
|
| 602 |
+
|
| 603 |
+
You also can't connect by IP address. If `alpine3`'s IP is `172.17.0.2`:
|
| 604 |
+
|
| 605 |
+
```console
|
| 606 |
+
# ping -c 2 172.17.0.2
|
| 607 |
+
|
| 608 |
+
PING 172.17.0.2 (172.17.0.2): 56 data bytes
|
| 609 |
+
|
| 610 |
+
--- 172.17.0.2 ping statistics ---
|
| 611 |
+
2 packets transmitted, 0 packets received, 100% packet loss
|
| 612 |
+
```
|
| 613 |
+
|
| 614 |
+
Detach from `alpine1` using `CTRL+p CTRL+q`.
|
| 615 |
+
|
| 616 |
+
7. Since `alpine4` is connected to both networks, it can reach all containers.
|
| 617 |
+
However, you need to use `alpine3`'s IP address:
|
| 618 |
+
|
| 619 |
+
```console
|
| 620 |
+
$ docker container attach alpine4
|
| 621 |
+
|
| 622 |
+
# ping -c 2 alpine1
|
| 623 |
+
|
| 624 |
+
PING alpine1 (172.18.0.2): 56 data bytes
|
| 625 |
+
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.074 ms
|
| 626 |
+
64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.082 ms
|
| 627 |
+
|
| 628 |
+
--- alpine1 ping statistics ---
|
| 629 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 630 |
+
round-trip min/avg/max = 0.074/0.078/0.082 ms
|
| 631 |
+
|
| 632 |
+
# ping -c 2 alpine2
|
| 633 |
+
|
| 634 |
+
PING alpine2 (172.18.0.3): 56 data bytes
|
| 635 |
+
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.075 ms
|
| 636 |
+
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.080 ms
|
| 637 |
+
|
| 638 |
+
--- alpine2 ping statistics ---
|
| 639 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 640 |
+
round-trip min/avg/max = 0.075/0.077/0.080 ms
|
| 641 |
+
|
| 642 |
+
# ping -c 2 alpine3
|
| 643 |
+
ping: bad address 'alpine3'
|
| 644 |
+
|
| 645 |
+
# ping -c 2 172.17.0.2
|
| 646 |
+
|
| 647 |
+
PING 172.17.0.2 (172.17.0.2): 56 data bytes
|
| 648 |
+
64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.089 ms
|
| 649 |
+
64 bytes from 172.17.0.2: seq=1 ttl=64 time=0.075 ms
|
| 650 |
+
|
| 651 |
+
--- 172.17.0.2 ping statistics ---
|
| 652 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 653 |
+
round-trip min/avg/max = 0.075/0.082/0.089 ms
|
| 654 |
+
```
|
| 655 |
+
|
| 656 |
+
8. Verify all containers can connect to the internet:
|
| 657 |
+
|
| 658 |
+
```console
|
| 659 |
+
# ping -c 2 google.com
|
| 660 |
+
|
| 661 |
+
PING google.com (172.217.3.174): 56 data bytes
|
| 662 |
+
64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.778 ms
|
| 663 |
+
64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.634 ms
|
| 664 |
+
|
| 665 |
+
--- google.com ping statistics ---
|
| 666 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 667 |
+
round-trip min/avg/max = 9.634/9.706/9.778 ms
|
| 668 |
+
```
|
| 669 |
+
|
| 670 |
+
Detach with `CTRL+p CTRL+q` and repeat for `alpine3` and `alpine1` if
|
| 671 |
+
desired.
|
| 672 |
+
|
| 673 |
+
9. Clean up:
|
| 674 |
+
|
| 675 |
+
```console
|
| 676 |
+
$ docker container stop alpine1 alpine2 alpine3 alpine4
|
| 677 |
+
$ docker container rm alpine1 alpine2 alpine3 alpine4
|
| 678 |
+
$ docker network rm alpine-net
|
| 679 |
+
```
|
| 680 |
+
|
| 681 |
+
## Next steps
|
| 682 |
+
|
| 683 |
+
- Learn about [networking from the container's point of view](../_index.md)
|
| 684 |
+
- Learn about [overlay networks](./overlay.md)
|
| 685 |
+
- Learn about [Macvlan networks](./macvlan.md)
|
| 686 |
+
```
|
20260907-014711-computing-math-e1c8fb/environment/public_data/input/tutorial_text_windows.csv
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
window_id,start_word,end_word,text,contains_code_term,matched_required_terms
|
| 2 |
+
1,0,40,"# Source 1: bridge.md - URL: https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md - SHA256: f5d1811100422cd6108a833b6485b7745ce7939b51f5826099242dde00b2f3b5 - Bytes: 27467 ```markdown --- title: Bridge network driver description: All about using user-defined bridge networks and the default bridge keywords: network, bridge, user-defined, standalone aliases: - /config/containers/bridges/ - /engine/userguide/networking/default_network/build-bridges/",true,Docker|container|network
|
| 3 |
+
2,20,60,"All about using user-defined bridge networks and the default bridge keywords: network, bridge, user-defined, standalone aliases: - /config/containers/bridges/ - /engine/userguide/networking/default_network/build-bridges/ - /engine/userguide/networking/default_network/custom-docker0/ - /engine/userguide/networking/work-with-networks/ - /network/bridge/ - /network/drivers/bridge/ - /engine/network/tutorials/standalone/ --- A Docker bridge network has an IPv4 subnet and,",true,Docker|container|network
|
| 4 |
+
3,40,80,"- /engine/userguide/networking/default_network/custom-docker0/ - /engine/userguide/networking/work-with-networks/ - /network/bridge/ - /network/drivers/bridge/ - /engine/network/tutorials/standalone/ --- A Docker bridge network has an IPv4 subnet and, optionally, an IPv6 subnet. Each container connected to the bridge network has a network interface with addresses in the network's",true,Docker|container|network
|
| 5 |
+
4,60,100,"optionally, an IPv6 subnet. Each container connected to the bridge network has a network interface with addresses in the network's subnets. By default, it: - Allows unrestricted network access to containers in the network from the host, and from other",false,container|network
|
| 6 |
+
5,80,120,"subnets. By default, it: - Allows unrestricted network access to containers in the network from the host, and from other containers connected to the same bridge network. - Blocks access from containers in other networks and from outside the Docker",true,Docker|container|network
|
| 7 |
+
6,100,140,containers connected to the same bridge network. - Blocks access from containers in other networks and from outside the Docker host. - Uses masquerading to give containers external network access. Devices on the host's external networks only see the IP,true,Docker|container|network
|
| 8 |
+
7,120,160,"host. - Uses masquerading to give containers external network access. Devices on the host's external networks only see the IP address of the Docker host. - Supports port publishing, where network traffic is forwarded between container ports and ports on",true,Docker|container|network
|
| 9 |
+
8,140,180,"address of the Docker host. - Supports port publishing, where network traffic is forwarded between container ports and ports on host IP addresses. The published ports can be accessed from outside the Docker host, on its IP addresses. In terms",true,Docker|container|network
|
| 10 |
+
9,160,200,"host IP addresses. The published ports can be accessed from outside the Docker host, on its IP addresses. In terms of Docker, a bridge network uses a software bridge which lets containers connected to the same bridge network communicate, while",true,Docker|container|network
|
| 11 |
+
10,180,220,"of Docker, a bridge network uses a software bridge which lets containers connected to the same bridge network communicate, while providing isolation from containers that aren't connected to that bridge network. By default, the Docker bridge driver automatically installs rules",true,Docker|container|network
|
| 12 |
+
11,200,240,"providing isolation from containers that aren't connected to that bridge network. By default, the Docker bridge driver automatically installs rules in the host machine so that containers connected to different bridge networks can only communicate with each other using published",true,Docker|container|network
|
| 13 |
+
12,220,260,in the host machine so that containers connected to different bridge networks can only communicate with each other using published ports. Bridge networks apply to containers running on the same Docker daemon host. For communication among containers running on different,true,Docker|container|network
|
| 14 |
+
13,240,280,"ports. Bridge networks apply to containers running on the same Docker daemon host. For communication among containers running on different Docker daemon hosts, you can either manage routing at the OS level, or you can use an [overlay network](overlay.md). When",true,Docker|container|network
|
| 15 |
+
14,260,300,"Docker daemon hosts, you can either manage routing at the OS level, or you can use an [overlay network](overlay.md). When you start Docker, a [default bridge network](#use-the-default-bridge-network) (also called `bridge`) is created automatically, and newly-started containers connect to it unless",true,Docker|container|network
|
| 16 |
+
15,280,320,"you start Docker, a [default bridge network](#use-the-default-bridge-network) (also called `bridge`) is created automatically, and newly-started containers connect to it unless otherwise specified. You can also create user-defined custom bridge networks. **User-defined bridge networks are superior to the default `bridge` network.**",true,Docker|container|network
|
| 17 |
+
16,300,340,otherwise specified. You can also create user-defined custom bridge networks. **User-defined bridge networks are superior to the default `bridge` network.** ## Differences between user-defined bridges and the default bridge - **User-defined bridges provide automatic DNS resolution between containers**. Containers on,false,container|network
|
| 18 |
+
17,320,360,"## Differences between user-defined bridges and the default bridge - **User-defined bridges provide automatic DNS resolution between containers**. Containers on the default bridge network can only access each other by IP addresses, unless you use the [`--link` option](../links.md), which is",false,container|network
|
| 19 |
+
18,340,380,"the default bridge network can only access each other by IP addresses, unless you use the [`--link` option](../links.md), which is considered legacy. On a user-defined bridge network, containers can resolve each other by name or alias. Imagine an application with",false,container|network
|
| 20 |
+
19,360,400,"considered legacy. On a user-defined bridge network, containers can resolve each other by name or alias. Imagine an application with a web front-end and a database back-end. If you call your containers `web` and `db`, the web container can connect",false,container|network
|
| 21 |
+
20,380,420,"a web front-end and a database back-end. If you call your containers `web` and `db`, the web container can connect to the db container at `db`, no matter which Docker host the application stack is running on. If you run",true,Docker|container
|
| 22 |
+
21,400,440,"to the db container at `db`, no matter which Docker host the application stack is running on. If you run the same application stack on the default bridge network, you need to manually create links between the containers (using the",true,Docker|container|network
|
| 23 |
+
22,420,460,"the same application stack on the default bridge network, you need to manually create links between the containers (using the legacy `--link` flag). These links need to be created in both directions, so you can see this gets complex with",false,container|network
|
| 24 |
+
23,440,480,"legacy `--link` flag). These links need to be created in both directions, so you can see this gets complex with more than two containers which need to communicate. Alternatively, you can manipulate the `/etc/hosts` files within the containers, but this",false,container
|
| 25 |
+
24,460,500,"more than two containers which need to communicate. Alternatively, you can manipulate the `/etc/hosts` files within the containers, but this creates problems that are difficult to debug. - **User-defined bridges provide better isolation**. All containers without a `--network` specified, are",false,container|network
|
| 26 |
+
25,480,520,"creates problems that are difficult to debug. - **User-defined bridges provide better isolation**. All containers without a `--network` specified, are attached to the default bridge network. This can be a risk, as unrelated stacks/services/containers are then able to communicate. Using",false,container|network
|
| 27 |
+
26,500,540,"attached to the default bridge network. This can be a risk, as unrelated stacks/services/containers are then able to communicate. Using a user-defined network provides a scoped network in which only containers attached to that network are able to communicate. -",false,container|network
|
| 28 |
+
27,520,560,"a user-defined network provides a scoped network in which only containers attached to that network are able to communicate. - **Containers can be attached and detached from user-defined networks on the fly**. During a container's lifetime, you can connect or",false,container|network
|
| 29 |
+
28,540,580,"**Containers can be attached and detached from user-defined networks on the fly**. During a container's lifetime, you can connect or disconnect it from user-defined networks on the fly. To remove a container from the default bridge network, you need to",false,container|network
|
| 30 |
+
29,560,600,"disconnect it from user-defined networks on the fly. To remove a container from the default bridge network, you need to stop the container and recreate it with different network options. - **Each user-defined network creates a configurable bridge**. If your",false,container|network
|
| 31 |
+
30,580,620,"stop the container and recreate it with different network options. - **Each user-defined network creates a configurable bridge**. If your containers use the default bridge network, you can configure it, but all the containers use the same settings, such as",false,container|network
|
| 32 |
+
31,600,640,"containers use the default bridge network, you can configure it, but all the containers use the same settings, such as MTU and `iptables` rules. In addition, configuring the default bridge network happens outside of Docker itself, and requires a restart",true,Docker|container|network
|
| 33 |
+
32,620,660,"MTU and `iptables` rules. In addition, configuring the default bridge network happens outside of Docker itself, and requires a restart of Docker. User-defined bridge networks are created and configured using `docker network create`. If different groups of applications have different",true,Docker|network
|
| 34 |
+
33,640,680,"of Docker. User-defined bridge networks are created and configured using `docker network create`. If different groups of applications have different network requirements, you can configure each user-defined bridge separately, as you create it. - **Linked containers on the default bridge",true,Docker|container|network
|
| 35 |
+
34,660,700,"network requirements, you can configure each user-defined bridge separately, as you create it. - **Linked containers on the default bridge network share environment variables**. Originally, the only way to share environment variables between two containers was to link them using",false,container|network
|
| 36 |
+
35,680,720,"network share environment variables**. Originally, the only way to share environment variables between two containers was to link them using the [`--link` flag](../links.md). This type of variable sharing isn't possible with user-defined networks. However, there are superior ways to share",false,container|network
|
| 37 |
+
36,700,740,"the [`--link` flag](../links.md). This type of variable sharing isn't possible with user-defined networks. However, there are superior ways to share environment variables. A few ideas: - Multiple containers can mount a file or directory containing the shared information, using a",false,container|network
|
| 38 |
+
37,720,760,"environment variables. A few ideas: - Multiple containers can mount a file or directory containing the shared information, using a Docker volume. - Multiple containers can be started together using `docker-compose` and the compose file can define the shared variables.",true,Docker|container
|
| 39 |
+
38,740,780,"Docker volume. - Multiple containers can be started together using `docker-compose` and the compose file can define the shared variables. - You can use swarm services instead of standalone containers, and take advantage of shared [secrets](/manuals/engine/swarm/secrets.md) and [configs](/manuals/engine/swarm/configs.md). Containers connected",true,Docker|container
|
| 40 |
+
39,760,800,"- You can use swarm services instead of standalone containers, and take advantage of shared [secrets](/manuals/engine/swarm/secrets.md) and [configs](/manuals/engine/swarm/configs.md). Containers connected to the same user-defined bridge network effectively expose all ports to each other. For a port to be accessible to",false,container|network
|
| 41 |
+
40,780,820,"to the same user-defined bridge network effectively expose all ports to each other. For a port to be accessible to containers or non-Docker hosts on different networks, that port must be _published_ using the `-p` or `--publish` flag. ## Options",true,Docker|container|network
|
| 42 |
+
41,800,840,"containers or non-Docker hosts on different networks, that port must be _published_ using the `-p` or `--publish` flag. ## Options The following table describes the driver-specific options that you can pass to `--opt` when creating a custom network using the",true,Docker|container|network
|
| 43 |
+
42,820,860,The following table describes the driver-specific options that you can pass to `--opt` when creating a custom network using the `bridge` driver. | Option | Default | Description | | ----------------------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------- | | `com.docker.network.bridge.name` | |,true,Docker|network
|
| 44 |
+
43,840,880,`bridge` driver. | Option | Default | Description | | ----------------------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------- | | `com.docker.network.bridge.name` | | Interface name to use when creating the Linux bridge. | | `com.docker.network.bridge.enable_ip_masquerade` | `true` | Enable IP masquerading. | |,true,Docker|network
|
| 45 |
+
44,860,900,Interface name to use when creating the Linux bridge. | | `com.docker.network.bridge.enable_ip_masquerade` | `true` | Enable IP masquerading. | | `com.docker.network.host_ipv4` `com.docker.network.host_ipv6` | | Address to use for source NAT. See [Port publishing](../port-publishing.md#masquerade-or-snat-for-outgoing-packets). | | `com.docker.network.bridge.gateway_mode_ipv4` `com.docker.network.bridge.gateway_mode_ipv6` | `nat` |,true,Docker|network
|
| 46 |
+
45,880,920,`com.docker.network.host_ipv4` `com.docker.network.host_ipv6` | | Address to use for source NAT. See [Port publishing](../port-publishing.md#masquerade-or-snat-for-outgoing-packets). | | `com.docker.network.bridge.gateway_mode_ipv4` `com.docker.network.bridge.gateway_mode_ipv6` | `nat` | Control external connectivity. See [Port publishing](../port-publishing.md#gateway-modes). | | `com.docker.network.bridge.enable_icc` | `true` | Enable or Disable inter-container connectivity. | | `com.docker.network.bridge.host_binding_ipv4`,true,Docker|container|network
|
| 47 |
+
46,900,940,Control external connectivity. See [Port publishing](../port-publishing.md#gateway-modes). | | `com.docker.network.bridge.enable_icc` | `true` | Enable or Disable inter-container connectivity. | | `com.docker.network.bridge.host_binding_ipv4` | all IPv4 and IPv6 addresses | Default IP when binding container ports. | | `com.docker.network.driver.mtu` | `0` (no limit),true,Docker|container|network
|
| 48 |
+
47,920,960,| all IPv4 and IPv6 addresses | Default IP when binding container ports. | | `com.docker.network.driver.mtu` | `0` (no limit) | Set the containers network Maximum Transmission Unit (MTU). | | `com.docker.network.container_iface_prefix` | `eth` | Set a custom prefix for,true,Docker|container|network
|
| 49 |
+
48,940,980,| Set the containers network Maximum Transmission Unit (MTU). | | `com.docker.network.container_iface_prefix` | `eth` | Set a custom prefix for container interfaces. | | `com.docker.network.bridge.inhibit_ipv4` | `false` | Prevent Docker from [assigning an IP address](#skip-bridge-ip-address-configuration) to the bridge. | Some,true,Docker|container|network
|
| 50 |
+
49,960,1000,"container interfaces. | | `com.docker.network.bridge.inhibit_ipv4` | `false` | Prevent Docker from [assigning an IP address](#skip-bridge-ip-address-configuration) to the bridge. | Some of these options are also available as flags to the `dockerd` CLI, and you can use them to configure the",true,Docker|container|network
|
| 51 |
+
50,980,1020,"of these options are also available as flags to the `dockerd` CLI, and you can use them to configure the default `docker0` bridge when starting the Docker daemon. The following table shows which options have equivalent flags in the `dockerd`",true,Docker
|
| 52 |
+
51,1000,1040,default `docker0` bridge when starting the Docker daemon. The following table shows which options have equivalent flags in the `dockerd` CLI. | Option | Flag | | ------------------------------------------------ | ----------- | | `com.docker.network.bridge.name` | - | | `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq`,true,Docker|network
|
| 53 |
+
52,1020,1060,CLI. | Option | Flag | | ------------------------------------------------ | ----------- | | `com.docker.network.bridge.name` | - | | `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq` | | `com.docker.network.bridge.enable_icc` | `--icc` | | `com.docker.network.bridge.host_binding_ipv4` | `--ip` | | `com.docker.network.driver.mtu` | `--mtu` | | `com.docker.network.container_iface_prefix` | -,true,Docker|container|network
|
| 54 |
+
53,1040,1080,"| | `com.docker.network.bridge.enable_icc` | `--icc` | | `com.docker.network.bridge.host_binding_ipv4` | `--ip` | | `com.docker.network.driver.mtu` | `--mtu` | | `com.docker.network.container_iface_prefix` | - | The Docker daemon supports a `--bridge` flag, which you can use to define your own `docker0` bridge. Use this",true,Docker|container|network
|
| 55 |
+
54,1060,1100,"| The Docker daemon supports a `--bridge` flag, which you can use to define your own `docker0` bridge. Use this option if you want to run multiple daemon instances on the same host. For details, see [Run multiple daemons](/reference/cli/dockerd.md#run-multiple-daemons). ###",true,Docker
|
| 56 |
+
55,1080,1120,"option if you want to run multiple daemon instances on the same host. For details, see [Run multiple daemons](/reference/cli/dockerd.md#run-multiple-daemons). ### Default host binding address When no host address is given in port publishing options like `-p 80` or `-p 8080:80`,",true,Docker
|
| 57 |
+
56,1100,1140,"Default host binding address When no host address is given in port publishing options like `-p 80` or `-p 8080:80`, the default is to make the container's port 80 available on all host addresses, IPv4 and IPv6. The bridge network",false,container|network
|
| 58 |
+
57,1120,1160,"the default is to make the container's port 80 available on all host addresses, IPv4 and IPv6. The bridge network driver option `com.docker.network.bridge.host_binding_ipv4` can be used to modify the default address for published ports. Despite the option's name, it is",true,Docker|container|network
|
| 59 |
+
58,1140,1180,"driver option `com.docker.network.bridge.host_binding_ipv4` can be used to modify the default address for published ports. Despite the option's name, it is possible to specify an IPv6 address. When the default binding address is an address assigned to a specific interface, the",true,Docker|network
|
| 60 |
+
59,1160,1200,"possible to specify an IPv6 address. When the default binding address is an address assigned to a specific interface, the container's port will only be accessible via that address. Setting the default binding address to `::` means published ports will",false,container
|
| 61 |
+
60,1180,1220,"container's port will only be accessible via that address. Setting the default binding address to `::` means published ports will only be available on the host's IPv6 addresses. However, setting it to `0.0.0.0` means it will be available on the",false,container
|
| 62 |
+
61,1200,1240,"only be available on the host's IPv6 addresses. However, setting it to `0.0.0.0` means it will be available on the host's IPv4 and IPv6 addresses. To restrict a published port to IPv4 only, the address must be included in the",false,
|
| 63 |
+
62,1220,1260,"host's IPv4 and IPv6 addresses. To restrict a published port to IPv4 only, the address must be included in the container's publishing options. For example, `-p 0.0.0.0:8080:80`. ## Manage a user-defined bridge Use the `docker network create` command to create",true,Docker|container|network
|
| 64 |
+
63,1240,1280,"container's publishing options. For example, `-p 0.0.0.0:8080:80`. ## Manage a user-defined bridge Use the `docker network create` command to create a user-defined bridge network. ```console $ docker network create my-net ``` You can specify the subnet, the IP address range,",true,Docker|container|network
|
| 65 |
+
64,1260,1300,"a user-defined bridge network. ```console $ docker network create my-net ``` You can specify the subnet, the IP address range, the gateway, and other options. See the [docker network create](/reference/cli/docker/network/create/#specify-advanced-options) reference or the output of `docker network create --help` for",true,Docker|network
|
| 66 |
+
65,1280,1320,"the gateway, and other options. See the [docker network create](/reference/cli/docker/network/create/#specify-advanced-options) reference or the output of `docker network create --help` for details. Use the `docker network rm` command to remove a user-defined bridge network. If containers are currently connected to the",true,Docker|container|network
|
| 67 |
+
66,1300,1340,"details. Use the `docker network rm` command to remove a user-defined bridge network. If containers are currently connected to the network, [disconnect them](#disconnect-a-container-from-a-user-defined-bridge) first. ```console $ docker network rm my-net ``` > **What's really happening?** > > When you create",true,Docker|container|network
|
| 68 |
+
67,1320,1360,"network, [disconnect them](#disconnect-a-container-from-a-user-defined-bridge) first. ```console $ docker network rm my-net ``` > **What's really happening?** > > When you create or remove a user-defined bridge or connect or disconnect a > container from a user-defined bridge, Docker uses tools specific",true,Docker|container|network
|
| 69 |
+
68,1340,1380,"or remove a user-defined bridge or connect or disconnect a > container from a user-defined bridge, Docker uses tools specific to the > operating system to manage the underlying network infrastructure (such as adding > or removing bridge devices or",true,Docker|container|network
|
| 70 |
+
69,1360,1400,to the > operating system to manage the underlying network infrastructure (such as adding > or removing bridge devices or configuring `iptables` rules on Linux). These > details should be considered implementation details. Let Docker manage your > user-defined networks,true,Docker|network
|
| 71 |
+
70,1380,1420,"configuring `iptables` rules on Linux). These > details should be considered implementation details. Let Docker manage your > user-defined networks for you. ## Connect a container to a user-defined bridge When you create a new container, you can specify one",true,Docker|container|network
|
| 72 |
+
71,1400,1440,"for you. ## Connect a container to a user-defined bridge When you create a new container, you can specify one or more `--network` flags. This example connects an Nginx container to the `my-net` network. It also publishes port 80 in",false,container|network
|
| 73 |
+
72,1420,1460,"or more `--network` flags. This example connects an Nginx container to the `my-net` network. It also publishes port 80 in the container to port 8080 on the Docker host, so external clients can access that port. Any other container connected",true,Docker|container|network
|
| 74 |
+
73,1440,1480,"the container to port 8080 on the Docker host, so external clients can access that port. Any other container connected to the `my-net` network has access to all ports on the `my-nginx` container, and vice versa. ```console $ docker create",true,Docker|container|network
|
| 75 |
+
74,1460,1500,"to the `my-net` network has access to all ports on the `my-nginx` container, and vice versa. ```console $ docker create --name my-nginx \ --network my-net \ --publish 8080:80 \ nginx:latest ``` To connect a **running** container to an existing user-defined",true,Docker|container|network
|
| 76 |
+
75,1480,1520,"--name my-nginx \ --network my-net \ --publish 8080:80 \ nginx:latest ``` To connect a **running** container to an existing user-defined bridge, use the `docker network connect` command. The following command connects an already-running `my-nginx` container to an already-existing `my-net` network:",true,Docker|container|network
|
| 77 |
+
76,1500,1540,"bridge, use the `docker network connect` command. The following command connects an already-running `my-nginx` container to an already-existing `my-net` network: ```console $ docker network connect my-net my-nginx ``` ## Disconnect a container from a user-defined bridge To disconnect a running",true,Docker|container|network
|
| 78 |
+
77,1520,1560,"```console $ docker network connect my-net my-nginx ``` ## Disconnect a container from a user-defined bridge To disconnect a running container from a user-defined bridge, use the `docker network disconnect` command. The following command disconnects the `my-nginx` container from the",true,Docker|container|network
|
| 79 |
+
78,1540,1580,"container from a user-defined bridge, use the `docker network disconnect` command. The following command disconnects the `my-nginx` container from the `my-net` network. ```console $ docker network disconnect my-net my-nginx ``` ## Use IPv6 in a user-defined bridge network When you",true,Docker|container|network
|
| 80 |
+
79,1560,1600,"`my-net` network. ```console $ docker network disconnect my-net my-nginx ``` ## Use IPv6 in a user-defined bridge network When you create your network, you can specify the `--ipv6` flag to enable IPv6. ```console $ docker network create --ipv6 --subnet 2001:db8:1234::/64",true,Docker|network
|
| 81 |
+
80,1580,1620,"create your network, you can specify the `--ipv6` flag to enable IPv6. ```console $ docker network create --ipv6 --subnet 2001:db8:1234::/64 my-net ``` If you do not provide a `--subnet` option, a Unique Local Address (ULA) prefix will be chosen automatically.",true,Docker|network
|
| 82 |
+
81,1600,1640,"my-net ``` If you do not provide a `--subnet` option, a Unique Local Address (ULA) prefix will be chosen automatically. ## IPv6-only bridge networks To skip IPv4 address configuration on the bridge and in its containers, create the network with",false,container|network
|
| 83 |
+
82,1620,1660,"## IPv6-only bridge networks To skip IPv4 address configuration on the bridge and in its containers, create the network with option `--ipv4=false`, and enable IPv6 using `--ipv6`. ```console $ docker network create --ipv6 --ipv4=false v6net ``` IPv4 address configuration cannot",true,Docker|container|network
|
| 84 |
+
83,1640,1680,"option `--ipv4=false`, and enable IPv6 using `--ipv6`. ```console $ docker network create --ipv6 --ipv4=false v6net ``` IPv4 address configuration cannot be disabled in the default bridge network. ## Use the default bridge network The default `bridge` network is considered a",true,Docker|network
|
| 85 |
+
84,1660,1700,"be disabled in the default bridge network. ## Use the default bridge network The default `bridge` network is considered a legacy detail of Docker and is not recommended for production use. Configuring it is a manual operation, and it has",true,Docker|network
|
| 86 |
+
85,1680,1720,"legacy detail of Docker and is not recommended for production use. Configuring it is a manual operation, and it has [technical shortcomings](#differences-between-user-defined-bridges-and-the-default-bridge). ### Connect a container to the default bridge network If you do not specify a network using the",true,Docker|container|network
|
| 87 |
+
86,1700,1740,"[technical shortcomings](#differences-between-user-defined-bridges-and-the-default-bridge). ### Connect a container to the default bridge network If you do not specify a network using the `--network` flag, and you do specify a network driver, your container is connected to the default `bridge` network by default.",false,container|network
|
| 88 |
+
87,1720,1760,"`--network` flag, and you do specify a network driver, your container is connected to the default `bridge` network by default. Containers connected to the default `bridge` network can communicate, but only by IP address, unless they're linked using the [legacy",false,container|network
|
| 89 |
+
88,1740,1780,"Containers connected to the default `bridge` network can communicate, but only by IP address, unless they're linked using the [legacy `--link` flag](../links.md). ### Configure the default bridge network To configure the default `bridge` network, you specify options in `daemon.json`. Here",false,container|network
|
| 90 |
+
89,1760,1800,"`--link` flag](../links.md). ### Configure the default bridge network To configure the default `bridge` network, you specify options in `daemon.json`. Here is an example `daemon.json` with several options specified. Only specify the settings you need to customize. ```json { ""bip"": ""192.168.1.1/24"",",false,network
|
| 91 |
+
90,1780,1820,"is an example `daemon.json` with several options specified. Only specify the settings you need to customize. ```json { ""bip"": ""192.168.1.1/24"", ""fixed-cidr"": ""192.168.1.0/25"", ""mtu"": 1500, ""default-gateway"": ""192.168.1.254"", ""dns"": [""10.20.1.2"", ""10.20.1.3""] } ``` In this example: - The bridge's address is ""192.168.1.1/24""",false,
|
| 92 |
+
91,1800,1840,"""fixed-cidr"": ""192.168.1.0/25"", ""mtu"": 1500, ""default-gateway"": ""192.168.1.254"", ""dns"": [""10.20.1.2"", ""10.20.1.3""] } ``` In this example: - The bridge's address is ""192.168.1.1/24"" (from `bip`). - The bridge network's subnet is ""192.168.1.0/24"" (from `bip`). - Container addresses will be allocated from ""192.168.1.0/25"" (from",false,container|network
|
| 93 |
+
92,1820,1860,"(from `bip`). - The bridge network's subnet is ""192.168.1.0/24"" (from `bip`). - Container addresses will be allocated from ""192.168.1.0/25"" (from `fixed-cidr`). ### Use IPv6 with the default bridge network IPv6 can be enabled for the default bridge using the following",false,container|network
|
| 94 |
+
93,1840,1880,"`fixed-cidr`). ### Use IPv6 with the default bridge network IPv6 can be enabled for the default bridge using the following options in `daemon.json`, or their command line equivalents. These three options only affect the default bridge, they are not used",false,network
|
| 95 |
+
94,1860,1900,"options in `daemon.json`, or their command line equivalents. These three options only affect the default bridge, they are not used by user-defined networks. The addresses in below are examples from the IPv6 documentation range. - Option `ipv6` is required. -",false,network
|
| 96 |
+
95,1880,1920,"by user-defined networks. The addresses in below are examples from the IPv6 documentation range. - Option `ipv6` is required. - Option `bip6` is optional, it specifies the address of the default bridge, which will be used as the default gateway",false,network
|
| 97 |
+
96,1900,1940,"Option `bip6` is optional, it specifies the address of the default bridge, which will be used as the default gateway by containers. It also specifies the subnet for the bridge network. - Option `fixed-cidr-v6` is optional, it specifies the address",false,container|network
|
| 98 |
+
97,1920,1960,"by containers. It also specifies the subnet for the bridge network. - Option `fixed-cidr-v6` is optional, it specifies the address range Docker may automatically allocate to containers. - The prefix should normally be `/64` or shorter. - For experimentation on",true,Docker|container|network
|
| 99 |
+
98,1940,1980,"range Docker may automatically allocate to containers. - The prefix should normally be `/64` or shorter. - For experimentation on a local network, it is better to use a Unique Local Address (ULA) prefix (matching `fd00::/8`) than a Link Local",true,Docker|container|network
|
| 100 |
+
99,1960,2000,"a local network, it is better to use a Unique Local Address (ULA) prefix (matching `fd00::/8`) than a Link Local prefix (matching `fe80::/10`). - Option `default-gateway-v6` is optional. If unspecified, the default is the first address in the `fixed-cidr-v6` subnet.",false,network
|
| 101 |
+
100,1980,2020,"prefix (matching `fe80::/10`). - Option `default-gateway-v6` is optional. If unspecified, the default is the first address in the `fixed-cidr-v6` subnet. ```json { ""ipv6"": true, ""bip6"": ""2001:db8::1111/64"", ""fixed-cidr-v6"": ""2001:db8::/64"", ""default-gateway-v6"": ""2001:db8:abcd::89"" } ``` If no `bip6` is specified, `fixed-cidr-v6` defines the",false,
|
| 102 |
+
101,2000,2040,"```json { ""ipv6"": true, ""bip6"": ""2001:db8::1111/64"", ""fixed-cidr-v6"": ""2001:db8::/64"", ""default-gateway-v6"": ""2001:db8:abcd::89"" } ``` If no `bip6` is specified, `fixed-cidr-v6` defines the subnet for the bridge network. If no `bip6` or `fixed-cidr-v6` is specified, a ULA prefix will be chosen. Restart Docker",true,Docker|network
|
| 103 |
+
102,2020,2060,"subnet for the bridge network. If no `bip6` or `fixed-cidr-v6` is specified, a ULA prefix will be chosen. Restart Docker for changes to take effect. ## Connection limit for bridge networks Due to limitations set by the Linux kernel, bridge",true,Docker|network
|
| 104 |
+
103,2040,2080,"for changes to take effect. ## Connection limit for bridge networks Due to limitations set by the Linux kernel, bridge networks become unstable and inter-container communications may break when 1000 containers or more connect to a single network. For more",false,container|network
|
| 105 |
+
104,2060,2100,"networks become unstable and inter-container communications may break when 1000 containers or more connect to a single network. For more information about this limitation, see [moby/moby#44973](https://github.com/moby/moby/issues/44973#issuecomment-1543747718). ## Skip Bridge IP address configuration The bridge is normally assigned the network's `--gateway`",false,container|network
|
| 106 |
+
105,2080,2120,"information about this limitation, see [moby/moby#44973](https://github.com/moby/moby/issues/44973#issuecomment-1543747718). ## Skip Bridge IP address configuration The bridge is normally assigned the network's `--gateway` address, which is used as the default route from the bridge network to other networks. The `com.docker.network.bridge.inhibit_ipv4` option lets you",true,Docker|network
|
| 107 |
+
106,2100,2140,"address, which is used as the default route from the bridge network to other networks. The `com.docker.network.bridge.inhibit_ipv4` option lets you create a network without the IPv4 gateway address being assigned to the bridge. This is useful if you want to",true,Docker|network
|
| 108 |
+
107,2120,2160,"create a network without the IPv4 gateway address being assigned to the bridge. This is useful if you want to configure the gateway IP address for the bridge manually. For instance if you add a physical interface to your bridge,",false,network
|
| 109 |
+
108,2140,2180,"configure the gateway IP address for the bridge manually. For instance if you add a physical interface to your bridge, and need it to have the gateway address. With this configuration, north-south traffic (to and from the bridge network) won't",false,network
|
| 110 |
+
109,2160,2200,"and need it to have the gateway address. With this configuration, north-south traffic (to and from the bridge network) won't work unless you've manually configured the gateway address on the bridge, or a device attached to it. This option can",false,network
|
| 111 |
+
110,2180,2220,"work unless you've manually configured the gateway address on the bridge, or a device attached to it. This option can only be used with user-defined bridge networks. ## Usage examples This section provides hands-on examples for working with bridge networks.",false,network
|
| 112 |
+
111,2200,2240,only be used with user-defined bridge networks. ## Usage examples This section provides hands-on examples for working with bridge networks. ### Use the default bridge network This example shows how the default `bridge` network works. You start two `alpine` containers,false,container|network
|
| 113 |
+
112,2220,2260,### Use the default bridge network This example shows how the default `bridge` network works. You start two `alpine` containers on the default bridge and test how they communicate. > [!NOTE] > The default `bridge` network is not recommended for,false,container|network
|
| 114 |
+
113,2240,2280,on the default bridge and test how they communicate. > [!NOTE] > The default `bridge` network is not recommended for production. Use > user-defined bridge networks instead. 1. List current networks: ```console $ docker network ls NETWORK ID NAME DRIVER,true,Docker|network
|
| 115 |
+
114,2260,2300,"production. Use > user-defined bridge networks instead. 1. List current networks: ```console $ docker network ls NETWORK ID NAME DRIVER SCOPE 17e324f45964 bridge bridge local 6ed54d316334 host host local 7092879f2cc8 none null local ``` The default `bridge` network is listed,",true,Docker|network
|
| 116 |
+
115,2280,2320,"SCOPE 17e324f45964 bridge bridge local 6ed54d316334 host host local 7092879f2cc8 none null local ``` The default `bridge` network is listed, along with `host` and `none`. 2. Start two `alpine` containers running `ash`. The `-dit` flags mean detached, interactive, and with",false,container|network
|
| 117 |
+
116,2300,2340,"along with `host` and `none`. 2. Start two `alpine` containers running `ash`. The `-dit` flags mean detached, interactive, and with a TTY. Since you haven't specified a `--network` flag, the containers connect to the default `bridge` network. ```console $ docker",true,Docker|container|network
|
| 118 |
+
117,2320,2360,"a TTY. Since you haven't specified a `--network` flag, the containers connect to the default `bridge` network. ```console $ docker run -dit --name alpine1 alpine ash $ docker run -dit --name alpine2 alpine ash ``` Verify both containers are running:",true,Docker|container|network
|
| 119 |
+
118,2340,2380,"run -dit --name alpine1 alpine ash $ docker run -dit --name alpine2 alpine ash ``` Verify both containers are running: ```console $ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 602dbf1edc81 alpine ""ash"" 4 seconds ago Up",true,Docker|container|image
|
| 120 |
+
119,2360,2400,"```console $ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 602dbf1edc81 alpine ""ash"" 4 seconds ago Up 3 seconds alpine2 da33b7aa74b0 alpine ""ash"" 17 seconds ago Up 16 seconds alpine1 ``` 3. Inspect the `bridge` network to",true,Docker|container|image|network
|
| 121 |
+
120,2380,2420,"3 seconds alpine2 da33b7aa74b0 alpine ""ash"" 17 seconds ago Up 16 seconds alpine1 ``` 3. Inspect the `bridge` network to see connected containers: ```console $ docker network inspect bridge ``` The output shows both containers connected, with their assigned IP",true,Docker|container|network
|
| 122 |
+
121,2400,2440,"see connected containers: ```console $ docker network inspect bridge ``` The output shows both containers connected, with their assigned IP addresses (`172.17.0.2` for `alpine1` and `172.17.0.3` for `alpine2`). 4. Connect to `alpine1`: ```console $ docker attach alpine1 / # ```",true,Docker|container|network
|
| 123 |
+
122,2420,2460,addresses (`172.17.0.2` for `alpine1` and `172.17.0.3` for `alpine2`). 4. Connect to `alpine1`: ```console $ docker attach alpine1 / # ``` Show the network interfaces for `alpine1` from within the container: ```console # ip addr show 1: lo: mtu 65536 qdisc,true,Docker|container|network
|
| 124 |
+
123,2440,2480,Show the network interfaces for `alpine1` from within the container: ```console # ip addr show 1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128,false,container|network
|
| 125 |
+
124,2460,2500,noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 27: eth0@if28: mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff inet 172.17.0.2/16,false,
|
| 126 |
+
125,2480,2520,"scope host valid_lft forever preferred_lft forever 27: eth0@if28: mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff inet 172.17.0.2/16 scope global eth0 valid_lft forever preferred_lft forever ``` In this example, the `eth0` interface has the IP address `172.17.0.2`. 5.",false,
|
| 127 |
+
126,2500,2540,"scope global eth0 valid_lft forever preferred_lft forever ``` In this example, the `eth0` interface has the IP address `172.17.0.2`. 5. From within `alpine1`, verify you can connect to the internet: ```console # ping -c 2 google.com PING google.com (172.217.3.174): 56",false,
|
| 128 |
+
127,2520,2560,"From within `alpine1`, verify you can connect to the internet: ```console # ping -c 2 google.com PING google.com (172.217.3.174): 56 data bytes 64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.841 ms 64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.897 ms --- google.com",false,
|
| 129 |
+
128,2540,2580,"data bytes 64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.841 ms 64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.897 ms --- google.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 9.841/9.869/9.897 ms ``` 6. Ping",false,
|
| 130 |
+
129,2560,2600,"ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 9.841/9.869/9.897 ms ``` 6. Ping the second container by its IP address: ```console # ping -c 2 172.17.0.3 PING 172.17.0.3 (172.17.0.3): 56 data bytes 64",false,container
|
| 131 |
+
130,2580,2620,the second container by its IP address: ```console # ping -c 2 172.17.0.3 PING 172.17.0.3 (172.17.0.3): 56 data bytes 64 bytes from 172.17.0.3: seq=0 ttl=64 time=0.086 ms 64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.094 ms --- 172.17.0.3 ping statistics ---,false,container
|
| 132 |
+
131,2600,2640,"bytes from 172.17.0.3: seq=0 ttl=64 time=0.086 ms 64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.094 ms --- 172.17.0.3 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.086/0.090/0.094 ms ``` This succeeds. Now try pinging",false,
|
| 133 |
+
132,2620,2660,"2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.086/0.090/0.094 ms ``` This succeeds. Now try pinging by container name: ```console # ping -c 2 alpine2 ping: bad address 'alpine2' ``` On the default bridge network, containers",false,container|network
|
| 134 |
+
133,2640,2680,"by container name: ```console # ping -c 2 alpine2 ping: bad address 'alpine2' ``` On the default bridge network, containers can't resolve each other by name. 7. Detach from `alpine1` without stopping it using `CTRL+p CTRL+q`. 8. Clean up: stop",false,container|network
|
| 135 |
+
134,2660,2700,can't resolve each other by name. 7. Detach from `alpine1` without stopping it using `CTRL+p CTRL+q`. 8. Clean up: stop the containers and remove them. ```console $ docker container stop alpine1 alpine2 $ docker container rm alpine1 alpine2 ``` Stopped,true,Docker|container
|
| 136 |
+
135,2680,2720,the containers and remove them. ```console $ docker container stop alpine1 alpine2 $ docker container rm alpine1 alpine2 ``` Stopped containers lose their IP addresses. ### Use user-defined bridge networks This example shows how user-defined bridge networks provide better isolation,true,Docker|container|network
|
| 137 |
+
136,2700,2740,containers lose their IP addresses. ### Use user-defined bridge networks This example shows how user-defined bridge networks provide better isolation and automatic DNS resolution between containers. 1. Create the `alpine-net` network: ```console $ docker network create --driver bridge alpine-net ```,true,Docker|container|network
|
| 138 |
+
137,2720,2760,and automatic DNS resolution between containers. 1. Create the `alpine-net` network: ```console $ docker network create --driver bridge alpine-net ``` 2. List Docker's networks: ```console $ docker network ls NETWORK ID NAME DRIVER SCOPE e9261a8c9a19 alpine-net bridge local 17e324f45964 bridge,true,Docker|container|network
|
| 139 |
+
138,2740,2780,2. List Docker's networks: ```console $ docker network ls NETWORK ID NAME DRIVER SCOPE e9261a8c9a19 alpine-net bridge local 17e324f45964 bridge bridge local 6ed54d316334 host host local 7092879f2cc8 none null local ``` Inspect the `alpine-net` network: ```console $ docker network inspect,true,Docker|network
|
| 140 |
+
139,2760,2800,"bridge local 6ed54d316334 host host local 7092879f2cc8 none null local ``` Inspect the `alpine-net` network: ```console $ docker network inspect alpine-net ``` This shows the network's gateway (for example, `172.18.0.1`) and that no containers are connected yet. 3. Create four",true,Docker|container|network
|
| 141 |
+
140,2780,2820,"alpine-net ``` This shows the network's gateway (for example, `172.18.0.1`) and that no containers are connected yet. 3. Create four containers. Three connect to `alpine-net`, and one connects to the default `bridge`. Then connect one container to both networks: ```console",false,container|network
|
| 142 |
+
141,2800,2840,"containers. Three connect to `alpine-net`, and one connects to the default `bridge`. Then connect one container to both networks: ```console $ docker run -dit --name alpine1 --network alpine-net alpine ash $ docker run -dit --name alpine2 --network alpine-net alpine ash",true,Docker|container|network
|
| 143 |
+
142,2820,2860,$ docker run -dit --name alpine1 --network alpine-net alpine ash $ docker run -dit --name alpine2 --network alpine-net alpine ash $ docker run -dit --name alpine3 alpine ash $ docker run -dit --name alpine4 --network alpine-net alpine ash $ docker,true,Docker|network
|
| 144 |
+
143,2840,2880,$ docker run -dit --name alpine3 alpine ash $ docker run -dit --name alpine4 --network alpine-net alpine ash $ docker network connect bridge alpine4 ``` Verify all containers are running: ```console $ docker container ls CONTAINER ID IMAGE COMMAND CREATED,true,Docker|container|image|network
|
| 145 |
+
144,2860,2900,"network connect bridge alpine4 ``` Verify all containers are running: ```console $ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 156849ccd902 alpine ""ash"" 41 seconds ago Up 41 seconds alpine4 fa1340b8d83e alpine ""ash"" 51 seconds ago Up",true,Docker|container|image|network
|
| 146 |
+
145,2880,2920,"STATUS PORTS NAMES 156849ccd902 alpine ""ash"" 41 seconds ago Up 41 seconds alpine4 fa1340b8d83e alpine ""ash"" 51 seconds ago Up 51 seconds alpine3 a535d969081e alpine ""ash"" About a minute ago Up About a minute alpine2 0a02c449a6e9 alpine ""ash"" About a",false,
|
| 147 |
+
146,2900,2940,"51 seconds alpine3 a535d969081e alpine ""ash"" About a minute ago Up About a minute alpine2 0a02c449a6e9 alpine ""ash"" About a minute ago Up About a minute alpine1 ``` 4. Inspect both networks again to see which containers are connected: ```console",false,container|network
|
| 148 |
+
147,2920,2960,minute ago Up About a minute alpine1 ``` 4. Inspect both networks again to see which containers are connected: ```console $ docker network inspect bridge ``` Containers `alpine3` and `alpine4` are connected to the `bridge` network. ```console $ docker network,true,Docker|container|network
|
| 149 |
+
148,2940,2980,"$ docker network inspect bridge ``` Containers `alpine3` and `alpine4` are connected to the `bridge` network. ```console $ docker network inspect alpine-net ``` Containers `alpine1`, `alpine2`, and `alpine4` are connected to `alpine-net`. 5. On user-defined networks, containers can resolve each",true,Docker|container|network
|
| 150 |
+
149,2960,3000,"inspect alpine-net ``` Containers `alpine1`, `alpine2`, and `alpine4` are connected to `alpine-net`. 5. On user-defined networks, containers can resolve each other by name. Connect to `alpine1` and test: > [!NOTE] > Automatic service discovery only resolves custom container names, not",false,container|network
|
| 151 |
+
150,2980,3020,"other by name. Connect to `alpine1` and test: > [!NOTE] > Automatic service discovery only resolves custom container names, not > default automatically generated names. ```console $ docker container attach alpine1 # ping -c 2 alpine2 PING alpine2 (172.18.0.3): 56",true,Docker|container
|
| 152 |
+
151,3000,3040,> default automatically generated names. ```console $ docker container attach alpine1 # ping -c 2 alpine2 PING alpine2 (172.18.0.3): 56 data bytes 64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.085 ms 64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.090 ms --- alpine2,true,Docker|container
|
| 153 |
+
152,3020,3060,"data bytes 64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.085 ms 64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.090 ms --- alpine2 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.085/0.087/0.090 ms # ping -c",false,
|
| 154 |
+
153,3040,3080,"ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.085/0.087/0.090 ms # ping -c 2 alpine4 PING alpine4 (172.18.0.4): 56 data bytes 64 bytes from 172.18.0.4: seq=0 ttl=64 time=0.076 ms 64 bytes from 172.18.0.4:",false,
|
| 155 |
+
154,3060,3100,"2 alpine4 PING alpine4 (172.18.0.4): 56 data bytes 64 bytes from 172.18.0.4: seq=0 ttl=64 time=0.076 ms 64 bytes from 172.18.0.4: seq=1 ttl=64 time=0.091 ms --- alpine4 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max",false,
|
| 156 |
+
155,3080,3120,"seq=1 ttl=64 time=0.091 ms --- alpine4 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.076/0.083/0.091 ms ``` 6. From `alpine1`, you can't connect to `alpine3` because it's on a different network: ```console #",false,network
|
| 157 |
+
156,3100,3140,"= 0.076/0.083/0.091 ms ``` 6. From `alpine1`, you can't connect to `alpine3` because it's on a different network: ```console # ping -c 2 alpine3 ping: bad address 'alpine3' ``` You also can't connect by IP address. If `alpine3`'s IP is",false,network
|
| 158 |
+
157,3120,3160,ping -c 2 alpine3 ping: bad address 'alpine3' ``` You also can't connect by IP address. If `alpine3`'s IP is `172.17.0.2`: ```console # ping -c 2 172.17.0.2 PING 172.17.0.2 (172.17.0.2): 56 data bytes --- 172.17.0.2 ping statistics --- 2 packets,false,
|
| 159 |
+
158,3140,3180,"`172.17.0.2`: ```console # ping -c 2 172.17.0.2 PING 172.17.0.2 (172.17.0.2): 56 data bytes --- 172.17.0.2 ping statistics --- 2 packets transmitted, 0 packets received, 100% packet loss ``` Detach from `alpine1` using `CTRL+p CTRL+q`. 7. Since `alpine4` is connected to",false,
|
| 160 |
+
159,3160,3200,"transmitted, 0 packets received, 100% packet loss ``` Detach from `alpine1` using `CTRL+p CTRL+q`. 7. Since `alpine4` is connected to both networks, it can reach all containers. However, you need to use `alpine3`'s IP address: ```console $ docker container attach",true,Docker|container|network
|
| 161 |
+
160,3180,3220,"both networks, it can reach all containers. However, you need to use `alpine3`'s IP address: ```console $ docker container attach alpine4 # ping -c 2 alpine1 PING alpine1 (172.18.0.2): 56 data bytes 64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.074 ms",true,Docker|container|network
|
| 162 |
+
161,3200,3240,"alpine4 # ping -c 2 alpine1 PING alpine1 (172.18.0.2): 56 data bytes 64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.074 ms 64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.082 ms --- alpine1 ping statistics --- 2 packets transmitted, 2 packets received, 0%",false,
|
| 163 |
+
162,3220,3260,"64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.082 ms --- alpine1 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.074/0.078/0.082 ms # ping -c 2 alpine2 PING alpine2 (172.18.0.3): 56 data bytes 64 bytes",false,
|
| 164 |
+
163,3240,3280,packet loss round-trip min/avg/max = 0.074/0.078/0.082 ms # ping -c 2 alpine2 PING alpine2 (172.18.0.3): 56 data bytes 64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.075 ms 64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.080 ms --- alpine2 ping statistics --- 2,false,
|
| 165 |
+
164,3260,3300,"from 172.18.0.3: seq=0 ttl=64 time=0.075 ms 64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.080 ms --- alpine2 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.075/0.077/0.080 ms # ping -c 2 alpine3 ping: bad",false,
|
| 166 |
+
165,3280,3320,"packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.075/0.077/0.080 ms # ping -c 2 alpine3 ping: bad address 'alpine3' # ping -c 2 172.17.0.2 PING 172.17.0.2 (172.17.0.2): 56 data bytes 64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.089",false,
|
| 167 |
+
166,3300,3340,"address 'alpine3' # ping -c 2 172.17.0.2 PING 172.17.0.2 (172.17.0.2): 56 data bytes 64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.089 ms 64 bytes from 172.17.0.2: seq=1 ttl=64 time=0.075 ms --- 172.17.0.2 ping statistics --- 2 packets transmitted, 2 packets received,",false,
|
| 168 |
+
167,3320,3360,"ms 64 bytes from 172.17.0.2: seq=1 ttl=64 time=0.075 ms --- 172.17.0.2 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.075/0.082/0.089 ms ``` 8. Verify all containers can connect to the internet: ```console #",false,container
|
| 169 |
+
168,3340,3380,0% packet loss round-trip min/avg/max = 0.075/0.082/0.089 ms ``` 8. Verify all containers can connect to the internet: ```console # ping -c 2 google.com PING google.com (172.217.3.174): 56 data bytes 64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.778 ms 64 bytes,false,container
|
| 170 |
+
169,3360,3400,"ping -c 2 google.com PING google.com (172.217.3.174): 56 data bytes 64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.778 ms 64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.634 ms --- google.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss",false,
|
| 171 |
+
170,3380,3420,"from 172.217.3.174: seq=1 ttl=41 time=9.634 ms --- google.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 9.634/9.706/9.778 ms ``` Detach with `CTRL+p CTRL+q` and repeat for `alpine3` and `alpine1` if desired. 9. Clean",false,
|
| 172 |
+
171,3400,3440,round-trip min/avg/max = 9.634/9.706/9.778 ms ``` Detach with `CTRL+p CTRL+q` and repeat for `alpine3` and `alpine1` if desired. 9. Clean up: ```console $ docker container stop alpine1 alpine2 alpine3 alpine4 $ docker container rm alpine1 alpine2 alpine3 alpine4 $ docker,true,Docker|container
|
| 173 |
+
172,3420,3460,up: ```console $ docker container stop alpine1 alpine2 alpine3 alpine4 $ docker container rm alpine1 alpine2 alpine3 alpine4 $ docker network rm alpine-net ``` ## Next steps - Learn about [networking from the container's point of view](../_index.md) - Learn about,true,Docker|container|network
|
| 174 |
+
173,3440,3468,network rm alpine-net ``` ## Next steps - Learn about [networking from the container's point of view](../_index.md) - Learn about [overlay networks](./overlay.md) - Learn about [Macvlan networks](./macvlan.md) ```,false,container|network
|
20260907-014711-computing-math-e1c8fb/environment/public_data/main.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import importlib.util
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import shlex
|
| 7 |
+
import shutil
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Task:
|
| 13 |
+
def __init__(self, task_id: str, description: str, metadata: dict[str, Any]):
|
| 14 |
+
self.task_id = task_id
|
| 15 |
+
self.description = description
|
| 16 |
+
self.prompt = description
|
| 17 |
+
self.metadata = metadata
|
| 18 |
+
self.computer = {"setup_config": {"os_type": "linux"}}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _task_dir() -> Path:
|
| 22 |
+
return Path(__file__).resolve().parent
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _load_card() -> dict[str, Any]:
|
| 26 |
+
path = _task_dir() / "task_card.json"
|
| 27 |
+
if not path.is_file():
|
| 28 |
+
return {
|
| 29 |
+
"taskId": os.environ.get("ALE_TASK_ID", "computing_math/docker_bridge_documentation_audit"),
|
| 30 |
+
"taskPrompt": "Task card has not been rendered yet; this fallback exists for stage-03 hook smoke only.",
|
| 31 |
+
"metadata": {
|
| 32 |
+
"domain": "computing_math",
|
| 33 |
+
"task": "docker_bridge_documentation_audit",
|
| 34 |
+
"variant": "base",
|
| 35 |
+
"domain_name": "computing_math",
|
| 36 |
+
"task_name": "docker_bridge_documentation_audit",
|
| 37 |
+
"variant_name": "base",
|
| 38 |
+
"requires_task_data": True,
|
| 39 |
+
"task_dir": "/media/user/data/agenthle/computing_math/docker_bridge_documentation_audit/base",
|
| 40 |
+
"input_dir": "/media/user/data/agenthle/computing_math/docker_bridge_documentation_audit/base/input",
|
| 41 |
+
"software_dir": "/media/user/data/agenthle/computing_math/docker_bridge_documentation_audit/base/software",
|
| 42 |
+
"remote_output_dir": "/media/user/data/agenthle/computing_math/docker_bridge_documentation_audit/base/output",
|
| 43 |
+
"reference_dir": "/media/user/data/agenthle/computing_math/docker_bridge_documentation_audit/base/reference",
|
| 44 |
+
},
|
| 45 |
+
}
|
| 46 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 47 |
+
return json.load(handle)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def load() -> list[Task]:
|
| 51 |
+
card = _load_card()
|
| 52 |
+
metadata = dict(card.get("metadata") or {})
|
| 53 |
+
if not metadata:
|
| 54 |
+
domain, _, task = str(card["taskId"]).partition("/")
|
| 55 |
+
variant = "base"
|
| 56 |
+
task_dir = f"/media/user/data/agenthle/{domain}/{task}/{variant}"
|
| 57 |
+
metadata.update({
|
| 58 |
+
"domain": domain,
|
| 59 |
+
"task": task,
|
| 60 |
+
"variant": variant,
|
| 61 |
+
"domain_name": domain,
|
| 62 |
+
"task_name": task,
|
| 63 |
+
"variant_name": variant,
|
| 64 |
+
"requires_task_data": True,
|
| 65 |
+
"task_dir": task_dir,
|
| 66 |
+
"input_dir": f"{task_dir}/input",
|
| 67 |
+
"software_dir": f"{task_dir}/software",
|
| 68 |
+
"remote_output_dir": f"{task_dir}/output",
|
| 69 |
+
"reference_dir": f"{task_dir}/reference",
|
| 70 |
+
})
|
| 71 |
+
return [Task(task_id=card["taskId"], description=card["taskPrompt"], metadata=metadata)]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _metadata(cfg: Any = None) -> dict[str, Any]:
|
| 75 |
+
if cfg is None:
|
| 76 |
+
return {}
|
| 77 |
+
value = getattr(cfg, "metadata", None)
|
| 78 |
+
return value if isinstance(value, dict) else {}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _remote_path(metadata: dict[str, Any], key: str, fallback: str) -> str:
|
| 82 |
+
value = str(metadata.get(key) or "").strip()
|
| 83 |
+
return value or fallback
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
async def _remote_run(session: Any, command: str, *, check: bool = False) -> Any:
|
| 87 |
+
try:
|
| 88 |
+
return await session.run_command(command, check=check)
|
| 89 |
+
except TypeError:
|
| 90 |
+
return await session.run_command(command)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
async def _remote_start(cfg: Any, session: Any) -> dict[str, Any]:
|
| 94 |
+
metadata = _metadata(cfg)
|
| 95 |
+
output_dir = _remote_path(metadata, "remote_output_dir", "output")
|
| 96 |
+
input_dir = _remote_path(metadata, "input_dir", "input")
|
| 97 |
+
software_dir = _remote_path(metadata, "software_dir", "software")
|
| 98 |
+
command = (
|
| 99 |
+
"set -eu\n"
|
| 100 |
+
f"mkdir -p {shlex.quote(output_dir)}\n"
|
| 101 |
+
f"find {shlex.quote(output_dir)} -mindepth 1 -maxdepth 1 -exec rm -rf -- {{}} +\n"
|
| 102 |
+
)
|
| 103 |
+
await _remote_run(session, command, check=True)
|
| 104 |
+
return {"ok": True, "input_dir": input_dir, "software_dir": software_dir, "output_dir": output_dir}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def start(cfg: Any = None, session: Any = None) -> dict[str, Any]:
|
| 108 |
+
if session is not None:
|
| 109 |
+
return _remote_start(cfg, session)
|
| 110 |
+
del cfg
|
| 111 |
+
output_dir = Path(os.environ.get("ALE_OUTPUT_DIR", "output"))
|
| 112 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 113 |
+
for child in output_dir.iterdir():
|
| 114 |
+
if child.is_dir():
|
| 115 |
+
shutil.rmtree(child)
|
| 116 |
+
else:
|
| 117 |
+
child.unlink()
|
| 118 |
+
input_dir = Path(os.environ.get("ALE_INPUT_DIR", "input"))
|
| 119 |
+
software_dir = Path(os.environ.get("ALE_SOFTWARE_DIR", "software"))
|
| 120 |
+
return {
|
| 121 |
+
"ok": True,
|
| 122 |
+
"input_dir": str(input_dir),
|
| 123 |
+
"software_dir": str(software_dir),
|
| 124 |
+
"output_dir": str(output_dir),
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
async def _remote_evaluate(cfg: Any, session: Any) -> list[float]:
|
| 129 |
+
metadata = _metadata(cfg)
|
| 130 |
+
output_dir = _remote_path(metadata, "remote_output_dir", "output")
|
| 131 |
+
reference_dir = _remote_path(metadata, "reference_dir", "reference")
|
| 132 |
+
script = f"""
|
| 133 |
+
import importlib.util
|
| 134 |
+
import json
|
| 135 |
+
import pathlib
|
| 136 |
+
|
| 137 |
+
output_dir = pathlib.Path({output_dir!r})
|
| 138 |
+
reference_dir = pathlib.Path({reference_dir!r})
|
| 139 |
+
evaluator_path = reference_dir / "evaluator.py"
|
| 140 |
+
if not evaluator_path.is_file():
|
| 141 |
+
raise FileNotFoundError(f"hidden evaluator is missing: {{evaluator_path}}")
|
| 142 |
+
spec = importlib.util.spec_from_file_location("hidden_ale_evaluator", evaluator_path)
|
| 143 |
+
if spec is None or spec.loader is None:
|
| 144 |
+
raise RuntimeError(f"cannot import hidden evaluator: {{evaluator_path}}")
|
| 145 |
+
module = importlib.util.module_from_spec(spec)
|
| 146 |
+
spec.loader.exec_module(module)
|
| 147 |
+
result = module.evaluate(output_dir, reference_dir)
|
| 148 |
+
print(json.dumps(result))
|
| 149 |
+
"""
|
| 150 |
+
command = "python3 - <<'PY'\n" + script + "\nPY"
|
| 151 |
+
result = await _remote_run(session, command, check=True)
|
| 152 |
+
stdout = getattr(result, "stdout", "") or ""
|
| 153 |
+
for line in reversed([item.strip() for item in stdout.splitlines() if item.strip()]):
|
| 154 |
+
try:
|
| 155 |
+
payload = json.loads(line)
|
| 156 |
+
if isinstance(payload, list):
|
| 157 |
+
return [float(max(0.0, min(1.0, value))) for value in payload]
|
| 158 |
+
except Exception:
|
| 159 |
+
continue
|
| 160 |
+
raise RuntimeError("hidden evaluator did not emit a JSON score list")
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def evaluate(cfg: Any = None, session: Any = None) -> list[float]:
|
| 164 |
+
if session is not None:
|
| 165 |
+
return _remote_evaluate(cfg, session)
|
| 166 |
+
del cfg
|
| 167 |
+
output_dir = Path(os.environ.get("ALE_OUTPUT_DIR", "output"))
|
| 168 |
+
reference_dir = Path(os.environ.get("ALE_REFERENCE_DIR", "reference"))
|
| 169 |
+
evaluator_path = reference_dir / "evaluator.py"
|
| 170 |
+
if not evaluator_path.is_file():
|
| 171 |
+
raise FileNotFoundError(f"hidden evaluator is missing: {evaluator_path}")
|
| 172 |
+
spec = importlib.util.spec_from_file_location("hidden_ale_evaluator", evaluator_path)
|
| 173 |
+
if spec is None or spec.loader is None:
|
| 174 |
+
raise RuntimeError(f"cannot import hidden evaluator: {evaluator_path}")
|
| 175 |
+
module = importlib.util.module_from_spec(spec)
|
| 176 |
+
spec.loader.exec_module(module)
|
| 177 |
+
result = module.evaluate(output_dir, reference_dir)
|
| 178 |
+
if not isinstance(result, list):
|
| 179 |
+
raise TypeError("hidden evaluator must return list[float]")
|
| 180 |
+
return [float(max(0.0, min(1.0, value))) for value in result]
|
20260907-014711-computing-math-e1c8fb/environment/public_data/software/command_examples.csv
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
term,kind,software_name
|
| 2 |
+
docker compose,code_term,Docker
|
| 3 |
+
docker pull,code_term,Docker
|
| 4 |
+
docker,code_term,Docker
|
| 5 |
+
docker run,code_term,Docker
|
| 6 |
+
docker build,code_term,Docker
|
| 7 |
+
docker,executable,Docker
|
| 8 |
+
docker compose,executable,Docker
|
20260907-014711-computing-math-e1c8fb/environment/public_data/software/software_manifest.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"software_name": "Docker",
|
| 3 |
+
"executables": [
|
| 4 |
+
"docker",
|
| 5 |
+
"docker compose"
|
| 6 |
+
],
|
| 7 |
+
"required_system_packages": [
|
| 8 |
+
"docker.io",
|
| 9 |
+
"docker-compose-plugin"
|
| 10 |
+
],
|
| 11 |
+
"official_sources": [
|
| 12 |
+
"https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md"
|
| 13 |
+
],
|
| 14 |
+
"solve_time_network": "disabled",
|
| 15 |
+
"python_wrapper_only": false,
|
| 16 |
+
"note": "This task audits real official software documentation/source staged offline; Python helpers only validate outputs."
|
| 17 |
+
}
|
20260907-014711-computing-math-e1c8fb/environment/public_data/software/validate_outputs.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def required_outputs(input_dir: Path) -> list[str]:
|
| 11 |
+
spec_path = input_dir / "analysis_spec.json"
|
| 12 |
+
if spec_path.is_file():
|
| 13 |
+
payload = json.loads(spec_path.read_text(encoding="utf-8"))
|
| 14 |
+
required = payload.get("required_outputs") if isinstance(payload, dict) else None
|
| 15 |
+
if isinstance(required, list):
|
| 16 |
+
rows = [str(item.get("path") or "") for item in required if isinstance(item, dict)]
|
| 17 |
+
rows = [item for item in rows if item]
|
| 18 |
+
if rows:
|
| 19 |
+
return rows
|
| 20 |
+
return [
|
| 21 |
+
"summary.json",
|
| 22 |
+
"magnitude_depth_bins.csv",
|
| 23 |
+
"region_daily_counts.csv",
|
| 24 |
+
"filtered_events.geojson",
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def main() -> int:
|
| 29 |
+
output_dir = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("output")
|
| 30 |
+
input_dir = Path(sys.argv[2]) if len(sys.argv) > 2 else Path(os.environ.get("ALE_INPUT_DIR", "input"))
|
| 31 |
+
required = required_outputs(input_dir)
|
| 32 |
+
missing = [name for name in required if not (output_dir / name).is_file()]
|
| 33 |
+
if missing:
|
| 34 |
+
print(json.dumps({"ok": False, "missing": missing}, indent=2))
|
| 35 |
+
return 1
|
| 36 |
+
print(json.dumps({"ok": True, "required": required}, indent=2))
|
| 37 |
+
return 0
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
raise SystemExit(main())
|
20260907-014711-computing-math-e1c8fb/environment/public_data/task_card.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"taskId": "computing_math/docker_bridge_documentation_audit__20260907-014711_computing_math_e1c8fb",
|
| 3 |
+
"title": "Repair4 20260907 029 Repair3 20260907 048 Repair2 20260906 053 Repair 20260906 Software 0084",
|
| 4 |
+
"summary": "Audit a staged offline Docker official tutorial corpus and produce reproducible section, keyword, and command inventories from local files (keyword-subset experiment 3: 6 terms) (ALE-100 software diversity variant 5) (independent source snapshot 5). (repair batch 20260906; independent official source) (targeted repair round 2). (targeted repair round 3). (targeted repair round 4).",
|
| 5 |
+
"category": "computing_math",
|
| 6 |
+
"taxonomy": {
|
| 7 |
+
"domain_id": "9",
|
| 8 |
+
"domain_code": "computing_math",
|
| 9 |
+
"subdomain_id": "9.6",
|
| 10 |
+
"subdomain_code": "infra_cloud",
|
| 11 |
+
"subdomain_name": "Infrastructure Engineering & Cloud Operations",
|
| 12 |
+
"classifier": {
|
| 13 |
+
"source": "public software metadata mapping",
|
| 14 |
+
"rationale": "Subdomain selected from public task metadata."
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"taskPrompt": "Use a Linux command-line workflow to audit the staged offline official tutorial corpus for Docker. The source document is input/tutorial_source.html, and input/tutorial_text_windows.csv contains deterministic text windows derived from it. Your job is to reconstruct the section outline, keyword inventory, code-block inventory, and summary statistics from the local files. Read only the staged files in input/ and software/, write final deliverables under output/, and do not use network access, credentials, GUI tools, browser automation, Windows-only tooling, or mobile apps. The authoritative public contract is input/analysis_spec.json; if any wording elsewhere is less specific, follow analysis_spec.json for file names, columns, filters, grouping rules, rounding rules, and output schemas. The workflow kind is software_tutorial_doc_audit. The primary staged data file is input/tutorial_text_windows.csv. Produce exactly these required deliverables: output/summary.json, output/section_outline.csv, output/keyword_inventory.csv, output/code_block_inventory.csv. The output schemas are:\n- output/summary.json: JSON keys and nested shape {\"code_block_count\": \"integer\", \"heading_count\": \"integer\", \"keyword_total\": \"integer\", \"software_name\": \"string\", \"source_character_count\": \"integer\", \"source_file\": \"string\", \"top_keyword\": \"string|null\", \"unique_required_terms_found\": \"integer\", \"window_count\": \"integer\"}\n- output/section_outline.csv: CSV header exactly rank, heading_level, heading_text, slug\n- output/keyword_inventory.csv: CSV header exactly term, category, count, first_window, appears_in_code\n- output/code_block_inventory.csv: CSV header exactly block_index, line_count, char_count, contains_code_term, first_line\nCompute all requested values from the staged data rather than hard-coding constants. Use deterministic ordering, UTF-8 text, explicit CSV headers, valid JSON/GeoJSON where applicable, and stable numeric formatting. You may run software/validate_outputs.py as a public sanity check after writing outputs, but the deliverables in output/ are what will be evaluated.",
|
| 18 |
+
"agentMustDo": [
|
| 19 |
+
"Read input/analysis_spec.json first and treat it as the authoritative public specification.",
|
| 20 |
+
"Read input/tutorial_text_windows.csv and compute results from the staged local data.",
|
| 21 |
+
"Create output/summary.json as json exactly as specified by analysis_spec.json.",
|
| 22 |
+
"Create output/section_outline.csv as csv exactly as specified by analysis_spec.json.",
|
| 23 |
+
"Create output/keyword_inventory.csv as csv exactly as specified by analysis_spec.json.",
|
| 24 |
+
"Create output/code_block_inventory.csv as csv exactly as specified by analysis_spec.json.",
|
| 25 |
+
"Place every final deliverable directly under output/ with the exact required filename.",
|
| 26 |
+
"Use only local staged files and installed Linux CLI tooling; do not download fresh data."
|
| 27 |
+
],
|
| 28 |
+
"inputFiles": [
|
| 29 |
+
{
|
| 30 |
+
"name": "README.md",
|
| 31 |
+
"format": "Markdown",
|
| 32 |
+
"path": "input/README.md",
|
| 33 |
+
"description": "Agent-visible staged input file for this task."
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"name": "analysis_spec.json",
|
| 37 |
+
"format": "JSON",
|
| 38 |
+
"path": "input/analysis_spec.json",
|
| 39 |
+
"description": "Agent-visible staged input file for this task."
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"name": "source_context_windows.jsonl",
|
| 43 |
+
"format": "JSONL",
|
| 44 |
+
"path": "input/source_context_windows.jsonl",
|
| 45 |
+
"description": "Agent-visible staged input file for this task."
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "tutorial_metadata.json",
|
| 49 |
+
"format": "JSON",
|
| 50 |
+
"path": "input/tutorial_metadata.json",
|
| 51 |
+
"description": "Agent-visible staged input file for this task."
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"name": "tutorial_source.html",
|
| 55 |
+
"format": "HTML",
|
| 56 |
+
"path": "input/tutorial_source.html",
|
| 57 |
+
"description": "Agent-visible staged input file for this task."
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"name": "tutorial_text_windows.csv",
|
| 61 |
+
"format": "CSV",
|
| 62 |
+
"path": "input/tutorial_text_windows.csv",
|
| 63 |
+
"description": "Agent-visible staged input file for this task."
|
| 64 |
+
}
|
| 65 |
+
],
|
| 66 |
+
"referenceFiles": [
|
| 67 |
+
{
|
| 68 |
+
"name": "summary.json",
|
| 69 |
+
"format": "JSON",
|
| 70 |
+
"path": "output/summary.json",
|
| 71 |
+
"description": "Required agent output file evaluated against hidden reference data."
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "section_outline.csv",
|
| 75 |
+
"format": "CSV",
|
| 76 |
+
"path": "output/section_outline.csv",
|
| 77 |
+
"description": "Required agent output file evaluated against hidden reference data."
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"name": "keyword_inventory.csv",
|
| 81 |
+
"format": "CSV",
|
| 82 |
+
"path": "output/keyword_inventory.csv",
|
| 83 |
+
"description": "Required agent output file evaluated against hidden reference data."
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"name": "code_block_inventory.csv",
|
| 87 |
+
"format": "CSV",
|
| 88 |
+
"path": "output/code_block_inventory.csv",
|
| 89 |
+
"description": "Required agent output file evaluated against hidden reference data."
|
| 90 |
+
}
|
| 91 |
+
],
|
| 92 |
+
"software": [
|
| 93 |
+
"Docker",
|
| 94 |
+
"docker",
|
| 95 |
+
"docker compose",
|
| 96 |
+
"Python 3.11",
|
| 97 |
+
"standard Unix shell",
|
| 98 |
+
"software/command_examples.csv",
|
| 99 |
+
"software/software_manifest.json",
|
| 100 |
+
"software/validate_outputs.py"
|
| 101 |
+
],
|
| 102 |
+
"requiredSystemPackages": [
|
| 103 |
+
"docker.io",
|
| 104 |
+
"docker-compose-plugin"
|
| 105 |
+
],
|
| 106 |
+
"evaluation": "Final required files under output/ are compared against standard-reference outputs generated by the deterministic workflow for this task.",
|
| 107 |
+
"vm": {
|
| 108 |
+
"machineType": "c4-standard-4",
|
| 109 |
+
"snapshot": "cpu-free-ubuntu",
|
| 110 |
+
"timeout": 7200
|
| 111 |
+
}
|
| 112 |
+
}
|
20260907-014711-computing-math-e1c8fb/instruction.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Repair4 20260907 029 Repair3 20260907 048 Repair2 20260906 053 Repair 20260906 Software 0084
|
| 2 |
+
|
| 3 |
+
Audit a staged offline Docker official tutorial corpus and produce reproducible section, keyword, and command inventories from local files (keyword-subset experiment 3: 6 terms) (ALE-100 software diversity variant 5) (independent source snapshot 5). (repair batch 20260906; independent official source) (targeted repair round 2). (targeted repair round 3). (targeted repair round 4).
|
| 4 |
+
|
| 5 |
+
## Task
|
| 6 |
+
|
| 7 |
+
Use a Linux command-line workflow to audit the staged offline official tutorial corpus for Docker. The source document is input/tutorial_source.html, and input/tutorial_text_windows.csv contains deterministic text windows derived from it. Your job is to reconstruct the section outline, keyword inventory, code-block inventory, and summary statistics from the local files. Read only the staged files in input/ and software/, write final deliverables under output/, and do not use network access, credentials, GUI tools, browser automation, Windows-only tooling, or mobile apps. The authoritative public contract is input/analysis_spec.json; if any wording elsewhere is less specific, follow analysis_spec.json for file names, columns, filters, grouping rules, rounding rules, and output schemas. The workflow kind is software_tutorial_doc_audit. The primary staged data file is input/tutorial_text_windows.csv. Produce exactly these required deliverables: output/summary.json, output/section_outline.csv, output/keyword_inventory.csv, output/code_block_inventory.csv. The output schemas are:
|
| 8 |
+
- output/summary.json: JSON keys and nested shape {"code_block_count": "integer", "heading_count": "integer", "keyword_total": "integer", "software_name": "string", "source_character_count": "integer", "source_file": "string", "top_keyword": "string|null", "unique_required_terms_found": "integer", "window_count": "integer"}
|
| 9 |
+
- output/section_outline.csv: CSV header exactly rank, heading_level, heading_text, slug
|
| 10 |
+
- output/keyword_inventory.csv: CSV header exactly term, category, count, first_window, appears_in_code
|
| 11 |
+
- output/code_block_inventory.csv: CSV header exactly block_index, line_count, char_count, contains_code_term, first_line
|
| 12 |
+
Compute all requested values from the staged data rather than hard-coding constants. Use deterministic ordering, UTF-8 text, explicit CSV headers, valid JSON/GeoJSON where applicable, and stable numeric formatting. You may run software/validate_outputs.py as a public sanity check after writing outputs, but the deliverables in output/ are what will be evaluated.
|
| 13 |
+
|
| 14 |
+
## Workspace
|
| 15 |
+
|
| 16 |
+
You are working in `/workspace`.
|
| 17 |
+
|
| 18 |
+
- Public input files are under `/workspace/input/`.
|
| 19 |
+
- Public helper software and validation scripts are under `/workspace/software/`.
|
| 20 |
+
- The public task card is available at `/workspace/task_card.json`.
|
| 21 |
+
- The public task driver is available at `/workspace/main.py` for reference only.
|
| 22 |
+
- Do not use hidden reference data, network downloads, credentials, GUI tools, or browser automation.
|
| 23 |
+
|
| 24 |
+
## Required Outputs
|
| 25 |
+
|
| 26 |
+
Create every final deliverable exactly at these paths:
|
| 27 |
+
|
| 28 |
+
- `/workspace/output/summary.json` (json)
|
| 29 |
+
- `/workspace/output/section_outline.csv` (csv)
|
| 30 |
+
- `/workspace/output/keyword_inventory.csv` (csv)
|
| 31 |
+
- `/workspace/output/code_block_inventory.csv` (csv)
|
| 32 |
+
|
| 33 |
+
Follow `/workspace/input/analysis_spec.json` whenever it is more specific than prose. You may run public validation helpers, but the files under `/workspace/output/` are what will be evaluated.
|
20260907-014711-computing-math-e1c8fb/solution/internal/workflow_adapters_runtime.py
ADDED
|
@@ -0,0 +1,679 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
import datetime as dt
|
| 5 |
+
import html
|
| 6 |
+
import json
|
| 7 |
+
import math
|
| 8 |
+
import re
|
| 9 |
+
import shutil
|
| 10 |
+
import statistics
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _read_json(path: Path) -> Any:
|
| 16 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 17 |
+
return json.load(handle)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _write_json(path: Path, payload: Any) -> None:
|
| 21 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 22 |
+
with path.open("w", encoding="utf-8") as handle:
|
| 23 |
+
json.dump(payload, handle, ensure_ascii=False, indent=2)
|
| 24 |
+
handle.write("\n")
|
| 25 |
+
|
| 26 |
+
def _stable_region(place: str) -> str:
|
| 27 |
+
if not place:
|
| 28 |
+
return "unknown"
|
| 29 |
+
if "," in place:
|
| 30 |
+
return place.split(",")[-1].strip() or place.strip()
|
| 31 |
+
parts = place.split()
|
| 32 |
+
return " ".join(parts[-2:]) if len(parts) >= 2 else place.strip()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _mag_bin(value: float | None) -> str:
|
| 36 |
+
if value is None or math.isnan(value):
|
| 37 |
+
return "unknown"
|
| 38 |
+
lower = math.floor(value)
|
| 39 |
+
upper = lower + 1
|
| 40 |
+
return f"{lower:.0f}-{upper:.0f}"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _depth_bin(value: float | None) -> str:
|
| 44 |
+
if value is None or math.isnan(value):
|
| 45 |
+
return "unknown"
|
| 46 |
+
if value < 0:
|
| 47 |
+
return "<0"
|
| 48 |
+
if value < 10:
|
| 49 |
+
return "0-10"
|
| 50 |
+
if value < 30:
|
| 51 |
+
return "10-30"
|
| 52 |
+
if value < 70:
|
| 53 |
+
return "30-70"
|
| 54 |
+
if value < 300:
|
| 55 |
+
return "70-300"
|
| 56 |
+
return "300+"
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _clean_markup_text(raw: str) -> str:
|
| 60 |
+
text = re.sub(r"(?is)<(script|style|noscript)[^>]*>.*?</\1>", " ", raw)
|
| 61 |
+
text = re.sub(r"(?is)<br\s*/?>", "\n", text)
|
| 62 |
+
text = re.sub(r"(?is)</(p|div|li|tr|h[1-6]|pre)>", "\n", text)
|
| 63 |
+
text = re.sub(r"(?is)<[^>]+>", " ", text)
|
| 64 |
+
text = html.unescape(text)
|
| 65 |
+
text = re.sub(r"[ \t]+", " ", text)
|
| 66 |
+
text = re.sub(r"\n\s+", "\n", text)
|
| 67 |
+
return text.strip()
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _heading_slug(value: str) -> str:
|
| 71 |
+
slug = re.sub(r"[^a-z0-9]+", "_", value.lower()).strip("_")
|
| 72 |
+
return slug[:80] or "section"
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _extract_headings(raw: str) -> list[dict[str, str]]:
|
| 76 |
+
headings: list[dict[str, str]] = []
|
| 77 |
+
for match in re.finditer(r"(?is)<h([1-6])[^>]*>(.*?)</h\1>", raw):
|
| 78 |
+
text = _clean_markup_text(match.group(2))
|
| 79 |
+
if text:
|
| 80 |
+
headings.append({"level": f"h{match.group(1)}", "text": text})
|
| 81 |
+
if headings:
|
| 82 |
+
return headings
|
| 83 |
+
for line in raw.splitlines():
|
| 84 |
+
match = re.match(r"^(#{1,6})\s+(.+?)\s*$", line)
|
| 85 |
+
if match:
|
| 86 |
+
headings.append({"level": f"h{len(match.group(1))}", "text": match.group(2).strip()})
|
| 87 |
+
return headings
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _extract_code_blocks(raw: str) -> list[str]:
|
| 91 |
+
blocks: list[str] = []
|
| 92 |
+
for match in re.finditer(r"(?is)<pre[^>]*>(.*?)</pre>", raw):
|
| 93 |
+
text = _clean_markup_text(match.group(1))
|
| 94 |
+
if text:
|
| 95 |
+
blocks.append(text)
|
| 96 |
+
for match in re.finditer(r"(?is)<code[^>]*>(.*?)</code>", raw):
|
| 97 |
+
text = _clean_markup_text(match.group(1))
|
| 98 |
+
if text and text not in blocks:
|
| 99 |
+
blocks.append(text)
|
| 100 |
+
for match in re.finditer(r"(?s)```(?:[A-Za-z0-9_-]+)?\n(.*?)```", raw):
|
| 101 |
+
text = html.unescape(match.group(1).strip())
|
| 102 |
+
if text and text not in blocks:
|
| 103 |
+
blocks.append(text)
|
| 104 |
+
return blocks
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def _window_rows(clean_text: str, *, width: int = 40, stride: int = 20) -> list[dict[str, Any]]:
|
| 108 |
+
words = re.findall(r"\S+", clean_text)
|
| 109 |
+
rows: list[dict[str, Any]] = []
|
| 110 |
+
if not words:
|
| 111 |
+
return rows
|
| 112 |
+
start = 0
|
| 113 |
+
while start < len(words):
|
| 114 |
+
end = min(start + width, len(words))
|
| 115 |
+
rows.append({
|
| 116 |
+
"window_id": len(rows) + 1,
|
| 117 |
+
"start_word": start,
|
| 118 |
+
"end_word": end,
|
| 119 |
+
"text": " ".join(words[start:end]),
|
| 120 |
+
})
|
| 121 |
+
if end == len(words):
|
| 122 |
+
break
|
| 123 |
+
start += stride
|
| 124 |
+
return rows
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _term_count(text: str, term: str) -> int:
|
| 128 |
+
term = term.strip()
|
| 129 |
+
if not term:
|
| 130 |
+
return 0
|
| 131 |
+
return len(re.findall(re.escape(term), text, flags=re.IGNORECASE))
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _first_window(windows: list[dict[str, Any]], term: str) -> str:
|
| 135 |
+
term_lower = term.lower()
|
| 136 |
+
for row in windows:
|
| 137 |
+
if term_lower in str(row.get("text") or "").lower():
|
| 138 |
+
return str(row.get("window_id") or "")
|
| 139 |
+
return ""
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _write_tutorial_public_inputs(input_dir: Path, source_path: Path, spec_payload: dict[str, Any]) -> None:
|
| 143 |
+
raw = source_path.read_text(encoding="utf-8", errors="replace")
|
| 144 |
+
# Tutorial examples may contain a maintainer's local Windows path. Keep
|
| 145 |
+
# the command semantics while preventing host-specific paths from entering
|
| 146 |
+
# the public task artifact.
|
| 147 |
+
sanitized_raw = re.sub(r"(?i)\b[A-Z]:\\(?:[^\\\r\n<>\"']+\\?)*[^\\\r\n<>\"']*", "./local.db", raw)
|
| 148 |
+
clean_text = _clean_markup_text(sanitized_raw)
|
| 149 |
+
windows = _window_rows(clean_text)
|
| 150 |
+
if len(windows) < 100:
|
| 151 |
+
raise ValueError(f"official tutorial source produced only {len(windows)} text windows; need at least 100")
|
| 152 |
+
required_terms = [str(item) for item in spec_payload.get("required_terms") or []]
|
| 153 |
+
code_terms = [str(item) for item in spec_payload.get("code_terms") or []]
|
| 154 |
+
input_dir.mkdir(parents=True, exist_ok=True)
|
| 155 |
+
destination = input_dir / str(spec_payload["source_file"])
|
| 156 |
+
# Always materialize the sanitized copy, including when the downloader
|
| 157 |
+
# already placed the source at the destination path.
|
| 158 |
+
destination.write_text(sanitized_raw, encoding="utf-8")
|
| 159 |
+
with (input_dir / str(spec_payload["input_file"])).open("w", encoding="utf-8", newline="") as handle:
|
| 160 |
+
fieldnames = ["window_id", "start_word", "end_word", "text", "contains_code_term", "matched_required_terms"]
|
| 161 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 162 |
+
writer.writeheader()
|
| 163 |
+
for row in windows:
|
| 164 |
+
text = str(row["text"])
|
| 165 |
+
matched = [term for term in required_terms if term.lower() in text.lower()]
|
| 166 |
+
contains_code = any(term.lower() in text.lower() for term in code_terms)
|
| 167 |
+
writer.writerow({
|
| 168 |
+
"window_id": row["window_id"],
|
| 169 |
+
"start_word": row["start_word"],
|
| 170 |
+
"end_word": row["end_word"],
|
| 171 |
+
"text": text,
|
| 172 |
+
"contains_code_term": "true" if contains_code else "false",
|
| 173 |
+
"matched_required_terms": "|".join(matched),
|
| 174 |
+
})
|
| 175 |
+
metadata = {
|
| 176 |
+
"software_name": spec_payload.get("software_name"),
|
| 177 |
+
"tutorial_url": spec_payload.get("tutorial_url"),
|
| 178 |
+
"source_urls": spec_payload.get("source_urls"),
|
| 179 |
+
"source_file": spec_payload.get("source_file"),
|
| 180 |
+
"window_file": spec_payload.get("input_file"),
|
| 181 |
+
"window_rule": spec_payload.get("window_rule"),
|
| 182 |
+
"required_terms": spec_payload.get("required_terms"),
|
| 183 |
+
"code_terms": spec_payload.get("code_terms"),
|
| 184 |
+
"note": "Provenance and public extraction rules only; scored aggregate values are intentionally not stored here.",
|
| 185 |
+
}
|
| 186 |
+
_write_json(input_dir / "tutorial_metadata.json", metadata)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def _source_context_text(path: Path) -> str:
|
| 190 |
+
try:
|
| 191 |
+
raw = path.read_text(encoding="utf-8", errors="replace")
|
| 192 |
+
except Exception:
|
| 193 |
+
return f"{path.name}\nsha256={_sha256_file(path)}\nsize_bytes={path.stat().st_size}\n"
|
| 194 |
+
if path.suffix.lower() in {".html", ".htm", ".md", ".txt"}:
|
| 195 |
+
return _clean_markup_text(raw)
|
| 196 |
+
return re.sub(r"\s+", " ", raw).strip()
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def _ensure_public_input_footprint(input_dir: Path, source_paths: list[Path]) -> str:
|
| 200 |
+
current = _tree_file_bytes(input_dir)
|
| 201 |
+
if current >= MIN_PUBLIC_TASK_DATA_BYTES:
|
| 202 |
+
return f"public input footprint is {current} bytes; no context expansion needed"
|
| 203 |
+
context_path = input_dir / "source_context_windows.jsonl"
|
| 204 |
+
base = current - (context_path.stat().st_size if context_path.is_file() else 0)
|
| 205 |
+
context_path.unlink(missing_ok=True)
|
| 206 |
+
rows: list[dict[str, Any]] = []
|
| 207 |
+
for source in source_paths:
|
| 208 |
+
if not source.is_file() or source.resolve() == context_path.resolve():
|
| 209 |
+
continue
|
| 210 |
+
text = _source_context_text(source)
|
| 211 |
+
if not text:
|
| 212 |
+
continue
|
| 213 |
+
start = 0
|
| 214 |
+
width = 1800
|
| 215 |
+
stride = 900
|
| 216 |
+
while start < len(text):
|
| 217 |
+
end = min(len(text), start + width)
|
| 218 |
+
rows.append({
|
| 219 |
+
"source_file": source.relative_to(input_dir).as_posix() if source.is_relative_to(input_dir) else source.name,
|
| 220 |
+
"source_sha256": _sha256_file(source),
|
| 221 |
+
"start_char": start,
|
| 222 |
+
"end_char": end,
|
| 223 |
+
"text": text[start:end],
|
| 224 |
+
})
|
| 225 |
+
if end == len(text):
|
| 226 |
+
break
|
| 227 |
+
start += stride
|
| 228 |
+
if not rows:
|
| 229 |
+
raise ValueError("public input footprint expansion has no public source text")
|
| 230 |
+
input_dir.mkdir(parents=True, exist_ok=True)
|
| 231 |
+
rows_written = 0
|
| 232 |
+
target_extra = MIN_PUBLIC_TASK_DATA_BYTES - max(0, base)
|
| 233 |
+
with context_path.open("w", encoding="utf-8") as handle:
|
| 234 |
+
cycle = 0
|
| 235 |
+
while handle.tell() < target_extra or rows_written < 100:
|
| 236 |
+
row = dict(rows[rows_written % len(rows)])
|
| 237 |
+
row["window_id"] = rows_written + 1
|
| 238 |
+
row["cycle"] = cycle
|
| 239 |
+
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 240 |
+
rows_written += 1
|
| 241 |
+
if rows_written % len(rows) == 0:
|
| 242 |
+
cycle += 1
|
| 243 |
+
handle.flush()
|
| 244 |
+
return f"wrote input/source_context_windows.jsonl with {rows_written} public-source windows and {context_path.stat().st_size} bytes"
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _write_software_manifest(software_dir: Path, spec_payload: dict[str, Any]) -> None:
|
| 248 |
+
if str(spec_payload.get("workflow_kind") or "") != "software_tutorial_doc_audit":
|
| 249 |
+
return
|
| 250 |
+
software_dir.mkdir(parents=True, exist_ok=True)
|
| 251 |
+
software_name = str(spec_payload.get("software_name") or "").strip()
|
| 252 |
+
executables = [str(item).strip() for item in spec_payload.get("executables") or [] if str(item).strip()]
|
| 253 |
+
system_packages = [str(item).strip() for item in spec_payload.get("required_system_packages") or [] if str(item).strip()]
|
| 254 |
+
source_urls = [str(item).strip() for item in spec_payload.get("source_urls") or [] if str(item).strip()]
|
| 255 |
+
_write_json(software_dir / "software_manifest.json", {
|
| 256 |
+
"software_name": software_name,
|
| 257 |
+
"executables": executables,
|
| 258 |
+
"required_system_packages": system_packages,
|
| 259 |
+
"official_sources": source_urls,
|
| 260 |
+
"solve_time_network": "disabled",
|
| 261 |
+
"python_wrapper_only": False,
|
| 262 |
+
"note": "This task audits real official software documentation/source staged offline; Python helpers only validate outputs.",
|
| 263 |
+
})
|
| 264 |
+
with (software_dir / "command_examples.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 265 |
+
writer = csv.DictWriter(handle, fieldnames=["term", "kind", "software_name"])
|
| 266 |
+
writer.writeheader()
|
| 267 |
+
for term in spec_payload.get("code_terms") or []:
|
| 268 |
+
writer.writerow({"term": str(term), "kind": "code_term", "software_name": software_name})
|
| 269 |
+
for exe in executables:
|
| 270 |
+
writer.writerow({"term": exe, "kind": "executable", "software_name": software_name})
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def software_tutorial_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 274 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 275 |
+
source_file = str(spec["source_file"])
|
| 276 |
+
source_text = (input_dir / source_file).read_text(encoding="utf-8", errors="replace")
|
| 277 |
+
clean_text = _clean_markup_text(source_text)
|
| 278 |
+
headings = _extract_headings(source_text)
|
| 279 |
+
code_blocks = _extract_code_blocks(source_text)
|
| 280 |
+
window_rows: list[dict[str, str]] = []
|
| 281 |
+
with (input_dir / str(spec["input_file"])).open("r", encoding="utf-8", newline="") as handle:
|
| 282 |
+
window_rows = list(csv.DictReader(handle))
|
| 283 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 284 |
+
|
| 285 |
+
with (output_dir / "section_outline.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 286 |
+
fieldnames = ["rank", "heading_level", "heading_text", "slug"]
|
| 287 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 288 |
+
writer.writeheader()
|
| 289 |
+
for rank, heading in enumerate(headings, start=1):
|
| 290 |
+
writer.writerow({
|
| 291 |
+
"rank": rank,
|
| 292 |
+
"heading_level": heading["level"],
|
| 293 |
+
"heading_text": heading["text"],
|
| 294 |
+
"slug": _heading_slug(heading["text"]),
|
| 295 |
+
})
|
| 296 |
+
|
| 297 |
+
all_terms: list[tuple[str, str]] = []
|
| 298 |
+
for term in spec.get("required_terms") or []:
|
| 299 |
+
all_terms.append((str(term), "required"))
|
| 300 |
+
for term in spec.get("code_terms") or []:
|
| 301 |
+
if str(term) not in {item[0] for item in all_terms}:
|
| 302 |
+
all_terms.append((str(term), "code"))
|
| 303 |
+
code_text = "\n".join(code_blocks)
|
| 304 |
+
term_rows: list[dict[str, Any]] = []
|
| 305 |
+
for term, category in all_terms:
|
| 306 |
+
term_rows.append({
|
| 307 |
+
"term": term,
|
| 308 |
+
"category": category,
|
| 309 |
+
"count": _term_count(clean_text, term),
|
| 310 |
+
"first_window": _first_window(window_rows, term),
|
| 311 |
+
"appears_in_code": "true" if term.lower() in code_text.lower() else "false",
|
| 312 |
+
})
|
| 313 |
+
term_rows.sort(key=lambda row: (str(row["category"]), str(row["term"]).lower()))
|
| 314 |
+
with (output_dir / "keyword_inventory.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 315 |
+
fieldnames = ["term", "category", "count", "first_window", "appears_in_code"]
|
| 316 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 317 |
+
writer.writeheader()
|
| 318 |
+
for row in term_rows:
|
| 319 |
+
writer.writerow(row)
|
| 320 |
+
|
| 321 |
+
code_terms = [str(item).lower() for item in spec.get("code_terms") or []]
|
| 322 |
+
with (output_dir / "code_block_inventory.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 323 |
+
fieldnames = ["block_index", "line_count", "char_count", "contains_code_term", "first_line"]
|
| 324 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 325 |
+
writer.writeheader()
|
| 326 |
+
for index, block in enumerate(code_blocks, start=1):
|
| 327 |
+
lines = [line for line in block.splitlines() if line.strip()]
|
| 328 |
+
contains = any(term and term in block.lower() for term in code_terms)
|
| 329 |
+
writer.writerow({
|
| 330 |
+
"block_index": index,
|
| 331 |
+
"line_count": len(lines),
|
| 332 |
+
"char_count": len(block),
|
| 333 |
+
"contains_code_term": "true" if contains else "false",
|
| 334 |
+
"first_line": lines[0][:200] if lines else "",
|
| 335 |
+
})
|
| 336 |
+
|
| 337 |
+
keyword_total = sum(int(row["count"]) for row in term_rows)
|
| 338 |
+
required_found = sum(1 for row in term_rows if row["category"] == "required" and int(row["count"]) > 0)
|
| 339 |
+
top_keyword = None
|
| 340 |
+
if term_rows:
|
| 341 |
+
top = max(term_rows, key=lambda row: (int(row["count"]), str(row["term"]).lower()))
|
| 342 |
+
top_keyword = str(top["term"]) if int(top["count"]) > 0 else None
|
| 343 |
+
summary = {
|
| 344 |
+
"software_name": str(spec.get("software_name") or ""),
|
| 345 |
+
"source_file": source_file,
|
| 346 |
+
"window_count": len(window_rows),
|
| 347 |
+
"heading_count": len(headings),
|
| 348 |
+
"code_block_count": len(code_blocks),
|
| 349 |
+
"keyword_total": keyword_total,
|
| 350 |
+
"unique_required_terms_found": required_found,
|
| 351 |
+
"top_keyword": top_keyword,
|
| 352 |
+
"source_character_count": len(clean_text),
|
| 353 |
+
}
|
| 354 |
+
_write_json(output_dir / "summary.json", summary)
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
def geojson_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 358 |
+
payload = _read_json(input_dir / "events.geojson")
|
| 359 |
+
features = payload.get("features") if isinstance(payload, dict) else []
|
| 360 |
+
rows: list[dict[str, Any]] = []
|
| 361 |
+
for feature in features:
|
| 362 |
+
if not isinstance(feature, dict):
|
| 363 |
+
continue
|
| 364 |
+
props = feature.get("properties") if isinstance(feature.get("properties"), dict) else {}
|
| 365 |
+
geom = feature.get("geometry") if isinstance(feature.get("geometry"), dict) else {}
|
| 366 |
+
coords = geom.get("coordinates") if isinstance(geom.get("coordinates"), list) else []
|
| 367 |
+
mag = props.get("mag")
|
| 368 |
+
try:
|
| 369 |
+
mag = float(mag) if mag is not None else None
|
| 370 |
+
except (TypeError, ValueError):
|
| 371 |
+
mag = None
|
| 372 |
+
depth = None
|
| 373 |
+
if len(coords) >= 3:
|
| 374 |
+
try:
|
| 375 |
+
depth = float(coords[2])
|
| 376 |
+
except (TypeError, ValueError):
|
| 377 |
+
depth = None
|
| 378 |
+
time_ms = props.get("time")
|
| 379 |
+
date_utc = "unknown"
|
| 380 |
+
if isinstance(time_ms, (int, float)):
|
| 381 |
+
date_utc = dt.datetime.utcfromtimestamp(time_ms / 1000).date().isoformat()
|
| 382 |
+
rows.append({
|
| 383 |
+
"id": feature.get("id") or props.get("code") or "",
|
| 384 |
+
"mag": mag,
|
| 385 |
+
"depth": depth,
|
| 386 |
+
"place": str(props.get("place") or ""),
|
| 387 |
+
"region": _stable_region(str(props.get("place") or "")),
|
| 388 |
+
"date_utc": date_utc,
|
| 389 |
+
"feature": feature,
|
| 390 |
+
})
|
| 391 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 392 |
+
mags = [row["mag"] for row in rows if row["mag"] is not None]
|
| 393 |
+
depths = [row["depth"] for row in rows if row["depth"] is not None]
|
| 394 |
+
summary = {
|
| 395 |
+
"event_count": len(rows),
|
| 396 |
+
"magnitude": {
|
| 397 |
+
"count": len(mags),
|
| 398 |
+
"min": round(min(mags), 6) if mags else None,
|
| 399 |
+
"max": round(max(mags), 6) if mags else None,
|
| 400 |
+
"mean": round(statistics.fmean(mags), 6) if mags else None,
|
| 401 |
+
"median": round(statistics.median(mags), 6) if mags else None,
|
| 402 |
+
},
|
| 403 |
+
"depth_km": {
|
| 404 |
+
"count": len(depths),
|
| 405 |
+
"min": round(min(depths), 6) if depths else None,
|
| 406 |
+
"max": round(max(depths), 6) if depths else None,
|
| 407 |
+
"mean": round(statistics.fmean(depths), 6) if depths else None,
|
| 408 |
+
},
|
| 409 |
+
"time_range_utc": {
|
| 410 |
+
"start_date": min((row["date_utc"] for row in rows if row["date_utc"] != "unknown"), default=None),
|
| 411 |
+
"end_date": max((row["date_utc"] for row in rows if row["date_utc"] != "unknown"), default=None),
|
| 412 |
+
},
|
| 413 |
+
"quality_flags": {
|
| 414 |
+
"missing_magnitude": sum(1 for row in rows if row["mag"] is None),
|
| 415 |
+
"missing_depth": sum(1 for row in rows if row["depth"] is None),
|
| 416 |
+
"unique_regions": len({row["region"] for row in rows}),
|
| 417 |
+
},
|
| 418 |
+
}
|
| 419 |
+
_write_json(output_dir / "summary.json", summary)
|
| 420 |
+
|
| 421 |
+
grouped: dict[tuple[str, str], list[dict[str, Any]]] = {}
|
| 422 |
+
for row in rows:
|
| 423 |
+
grouped.setdefault((_mag_bin(row["mag"]), _depth_bin(row["depth"])), []).append(row)
|
| 424 |
+
with (output_dir / "magnitude_depth_bins.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 425 |
+
fieldnames = ["mag_bin", "depth_bin", "event_count", "mean_magnitude", "max_magnitude"]
|
| 426 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 427 |
+
writer.writeheader()
|
| 428 |
+
for (mag_bin, depth_bin), group in sorted(grouped.items()):
|
| 429 |
+
group_mags = [row["mag"] for row in group if row["mag"] is not None]
|
| 430 |
+
writer.writerow({
|
| 431 |
+
"mag_bin": mag_bin,
|
| 432 |
+
"depth_bin": depth_bin,
|
| 433 |
+
"event_count": len(group),
|
| 434 |
+
"mean_magnitude": f"{statistics.fmean(group_mags):.6f}" if group_mags else "",
|
| 435 |
+
"max_magnitude": f"{max(group_mags):.6f}" if group_mags else "",
|
| 436 |
+
})
|
| 437 |
+
|
| 438 |
+
daily: dict[tuple[str, str], list[dict[str, Any]]] = {}
|
| 439 |
+
for row in rows:
|
| 440 |
+
daily.setdefault((row["region"], row["date_utc"]), []).append(row)
|
| 441 |
+
with (output_dir / "region_daily_counts.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 442 |
+
fieldnames = ["region", "date_utc", "event_count", "max_magnitude"]
|
| 443 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 444 |
+
writer.writeheader()
|
| 445 |
+
for (region, date_utc), group in sorted(daily.items()):
|
| 446 |
+
group_mags = [row["mag"] for row in group if row["mag"] is not None]
|
| 447 |
+
writer.writerow({
|
| 448 |
+
"region": region,
|
| 449 |
+
"date_utc": date_utc,
|
| 450 |
+
"event_count": len(group),
|
| 451 |
+
"max_magnitude": f"{max(group_mags):.6f}" if group_mags else "",
|
| 452 |
+
})
|
| 453 |
+
|
| 454 |
+
filtered = [row["feature"] for row in rows if row["mag"] is not None and row["mag"] >= 4.5]
|
| 455 |
+
_write_json(output_dir / "filtered_events.geojson", {"type": "FeatureCollection", "features": filtered})
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def csv_time_series_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 459 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 460 |
+
csv_name = spec["input_file"]
|
| 461 |
+
date_column = spec["date_column"]
|
| 462 |
+
value_column = spec["value_column"]
|
| 463 |
+
rows: list[dict[str, Any]] = []
|
| 464 |
+
with (input_dir / csv_name).open("r", encoding="utf-8", newline="") as raw_handle:
|
| 465 |
+
lines = [line for line in raw_handle if not line.lstrip().startswith("#")]
|
| 466 |
+
reader = csv.DictReader(lines)
|
| 467 |
+
for item in reader:
|
| 468 |
+
raw_date = item.get(date_column, "")
|
| 469 |
+
try:
|
| 470 |
+
day = dt.date.fromisoformat(raw_date)
|
| 471 |
+
except ValueError:
|
| 472 |
+
if raw_date.isdigit() and len(raw_date) == 4:
|
| 473 |
+
day = dt.date(int(raw_date), 1, 1)
|
| 474 |
+
else:
|
| 475 |
+
continue
|
| 476 |
+
raw_value = item.get(value_column, "")
|
| 477 |
+
try:
|
| 478 |
+
value = float(raw_value)
|
| 479 |
+
except (TypeError, ValueError):
|
| 480 |
+
value = None
|
| 481 |
+
rows.append({"date": day, "value": value, "raw": item})
|
| 482 |
+
rows.sort(key=lambda item: item["date"])
|
| 483 |
+
valid = [row for row in rows if row["value"] is not None]
|
| 484 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 485 |
+
monthly: dict[str, list[float]] = {}
|
| 486 |
+
for row in valid:
|
| 487 |
+
key = row["date"].strftime("%Y-%m")
|
| 488 |
+
monthly.setdefault(key, []).append(row["value"])
|
| 489 |
+
with (output_dir / "monthly_statistics.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 490 |
+
fieldnames = ["month", "count", "mean", "median", "min", "max"]
|
| 491 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 492 |
+
writer.writeheader()
|
| 493 |
+
for month, values in sorted(monthly.items()):
|
| 494 |
+
writer.writerow({
|
| 495 |
+
"month": month,
|
| 496 |
+
"count": len(values),
|
| 497 |
+
"mean": f"{statistics.fmean(values):.6f}",
|
| 498 |
+
"median": f"{statistics.median(values):.6f}",
|
| 499 |
+
"min": f"{min(values):.6f}",
|
| 500 |
+
"max": f"{max(values):.6f}",
|
| 501 |
+
})
|
| 502 |
+
existing_dates = {row["date"] for row in rows}
|
| 503 |
+
missing_days: list[dt.date] = []
|
| 504 |
+
if rows:
|
| 505 |
+
day = rows[0]["date"]
|
| 506 |
+
while day <= rows[-1]["date"]:
|
| 507 |
+
if day.weekday() < 5 and day not in existing_dates:
|
| 508 |
+
missing_days.append(day)
|
| 509 |
+
day += dt.timedelta(days=1)
|
| 510 |
+
with (output_dir / "missing_business_days.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 511 |
+
writer = csv.DictWriter(handle, fieldnames=["date"])
|
| 512 |
+
writer.writeheader()
|
| 513 |
+
for day in missing_days:
|
| 514 |
+
writer.writerow({"date": day.isoformat()})
|
| 515 |
+
with (output_dir / "clean_series.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 516 |
+
writer = csv.DictWriter(handle, fieldnames=["date", "value"])
|
| 517 |
+
writer.writeheader()
|
| 518 |
+
for row in valid:
|
| 519 |
+
writer.writerow({"date": row["date"].isoformat(), "value": f"{row['value']:.6f}"})
|
| 520 |
+
values = [row["value"] for row in valid]
|
| 521 |
+
summary = {
|
| 522 |
+
"series_name": spec.get("series_name", value_column),
|
| 523 |
+
"row_count": len(rows),
|
| 524 |
+
"valid_value_count": len(valid),
|
| 525 |
+
"missing_value_count": len(rows) - len(valid),
|
| 526 |
+
"missing_business_day_count": len(missing_days),
|
| 527 |
+
"date_range": {
|
| 528 |
+
"start": rows[0]["date"].isoformat() if rows else None,
|
| 529 |
+
"end": rows[-1]["date"].isoformat() if rows else None,
|
| 530 |
+
},
|
| 531 |
+
"value": {
|
| 532 |
+
"min": round(min(values), 6) if values else None,
|
| 533 |
+
"max": round(max(values), 6) if values else None,
|
| 534 |
+
"mean": round(statistics.fmean(values), 6) if values else None,
|
| 535 |
+
"median": round(statistics.median(values), 6) if values else None,
|
| 536 |
+
},
|
| 537 |
+
}
|
| 538 |
+
_write_json(output_dir / "summary.json", summary)
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
def _aggregate_annual_rows(rows: list[dict[str, Any]], aggregation: str) -> list[dict[str, Any]]:
|
| 542 |
+
if not aggregation:
|
| 543 |
+
return rows
|
| 544 |
+
grouped: dict[int, list[float]] = {}
|
| 545 |
+
for row in rows:
|
| 546 |
+
grouped.setdefault(int(row["year"]), []).append(float(row["value"]))
|
| 547 |
+
aggregated: list[dict[str, Any]] = []
|
| 548 |
+
for year, values in sorted(grouped.items()):
|
| 549 |
+
if aggregation == "mean":
|
| 550 |
+
value = statistics.fmean(values)
|
| 551 |
+
elif aggregation == "median":
|
| 552 |
+
value = statistics.median(values)
|
| 553 |
+
elif aggregation == "max":
|
| 554 |
+
value = max(values)
|
| 555 |
+
elif aggregation == "min":
|
| 556 |
+
value = min(values)
|
| 557 |
+
elif aggregation == "count":
|
| 558 |
+
value = float(len(values))
|
| 559 |
+
else:
|
| 560 |
+
raise ValueError(f"unsupported year_aggregation for csv_annual_series_audit: {aggregation}")
|
| 561 |
+
aggregated.append({"year": year, "value": value})
|
| 562 |
+
return aggregated
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
def csv_annual_series_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 566 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 567 |
+
csv_name = spec["input_file"]
|
| 568 |
+
year_column = spec["year_column"]
|
| 569 |
+
value_column = spec["value_column"]
|
| 570 |
+
# Optional: derive the year from an ISO-8601 timestamp column (e.g. USGS FDSN
|
| 571 |
+
# `time` = "2022-06-29T19:17:58.929Z") instead of parsing an integer year.
|
| 572 |
+
# When unset, behaviour is unchanged (integer year column).
|
| 573 |
+
year_from_timestamp = bool(spec.get("year_from_timestamp", False))
|
| 574 |
+
year_aggregation = str(spec.get("year_aggregation") or "").strip().lower()
|
| 575 |
+
raw_rows: list[dict[str, Any]] = []
|
| 576 |
+
with (input_dir / csv_name).open("r", encoding="utf-8", newline="") as raw_handle:
|
| 577 |
+
lines = [line for line in raw_handle if not line.lstrip().startswith("#")]
|
| 578 |
+
reader = csv.DictReader(lines)
|
| 579 |
+
for item in reader:
|
| 580 |
+
raw_year = str(item.get(year_column, "")).strip()
|
| 581 |
+
try:
|
| 582 |
+
if year_from_timestamp:
|
| 583 |
+
# Take the leading 4-digit year of an ISO timestamp/date.
|
| 584 |
+
match = re.match(r"\s*(\d{4})", raw_year)
|
| 585 |
+
if not match:
|
| 586 |
+
continue
|
| 587 |
+
year = int(match.group(1))
|
| 588 |
+
else:
|
| 589 |
+
year = int(raw_year)
|
| 590 |
+
value = float(str(item.get(value_column, "")).strip())
|
| 591 |
+
except (TypeError, ValueError):
|
| 592 |
+
continue
|
| 593 |
+
raw_rows.append({"year": year, "value": value})
|
| 594 |
+
rows = _aggregate_annual_rows(raw_rows, year_aggregation)
|
| 595 |
+
rows.sort(key=lambda item: item["year"])
|
| 596 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 597 |
+
decades: dict[str, list[float]] = {}
|
| 598 |
+
for row in rows:
|
| 599 |
+
decade_start = (row["year"] // 10) * 10
|
| 600 |
+
decades.setdefault(f"{decade_start}s", []).append(row["value"])
|
| 601 |
+
with (output_dir / "decadal_statistics.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 602 |
+
fieldnames = [
|
| 603 |
+
"decade_start",
|
| 604 |
+
"start_year",
|
| 605 |
+
"end_year",
|
| 606 |
+
"count",
|
| 607 |
+
"mean_departure",
|
| 608 |
+
"median_departure",
|
| 609 |
+
"min_departure",
|
| 610 |
+
"max_departure",
|
| 611 |
+
"sample_std_departure",
|
| 612 |
+
]
|
| 613 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 614 |
+
writer.writeheader()
|
| 615 |
+
for decade, values in sorted(decades.items()):
|
| 616 |
+
decade_start = int(decade.rstrip("s"))
|
| 617 |
+
years = [row["year"] for row in rows if decade_start <= row["year"] <= decade_start + 9]
|
| 618 |
+
writer.writerow({
|
| 619 |
+
"decade_start": decade_start,
|
| 620 |
+
"start_year": min(years),
|
| 621 |
+
"end_year": max(years),
|
| 622 |
+
"count": len(values),
|
| 623 |
+
"mean_departure": f"{statistics.fmean(values):.6f}",
|
| 624 |
+
"median_departure": f"{statistics.median(values):.6f}",
|
| 625 |
+
"min_departure": f"{min(values):.6f}",
|
| 626 |
+
"max_departure": f"{max(values):.6f}",
|
| 627 |
+
"sample_std_departure": f"{statistics.stdev(values):.6f}" if len(values) >= 2 else "",
|
| 628 |
+
})
|
| 629 |
+
threshold = float(spec.get("threshold", 1.0))
|
| 630 |
+
with (output_dir / "threshold_years.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 631 |
+
fieldnames = ["rank", "year", "departure", "threshold"]
|
| 632 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 633 |
+
writer.writeheader()
|
| 634 |
+
rank = 1
|
| 635 |
+
for row in rows:
|
| 636 |
+
if row["value"] >= threshold:
|
| 637 |
+
writer.writerow({
|
| 638 |
+
"rank": rank,
|
| 639 |
+
"year": row["year"],
|
| 640 |
+
"departure": f"{row['value']:.6f}",
|
| 641 |
+
"threshold": f"{threshold:.6f}",
|
| 642 |
+
})
|
| 643 |
+
rank += 1
|
| 644 |
+
with (output_dir / "clean_series.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 645 |
+
writer = csv.DictWriter(handle, fieldnames=["Year", "Departure from Average"])
|
| 646 |
+
writer.writeheader()
|
| 647 |
+
for row in rows:
|
| 648 |
+
writer.writerow({"Year": row["year"], "Departure from Average": f"{row['value']:.6f}"})
|
| 649 |
+
values = [row["value"] for row in rows]
|
| 650 |
+
threshold_rows = [row for row in rows if row["value"] >= threshold]
|
| 651 |
+
min_row = min(rows, key=lambda row: row["value"]) if rows else None
|
| 652 |
+
max_row = max(rows, key=lambda row: row["value"]) if rows else None
|
| 653 |
+
summary = {
|
| 654 |
+
"series_name": spec.get("series_name", value_column),
|
| 655 |
+
"row_count": len(rows),
|
| 656 |
+
"year_range": {
|
| 657 |
+
"start": rows[0]["year"] if rows else None,
|
| 658 |
+
"end": rows[-1]["year"] if rows else None,
|
| 659 |
+
},
|
| 660 |
+
"value": {
|
| 661 |
+
"min": round(min(values), 6) if values else None,
|
| 662 |
+
"min_year": min_row["year"] if min_row else None,
|
| 663 |
+
"max": round(max(values), 6) if values else None,
|
| 664 |
+
"max_year": max_row["year"] if max_row else None,
|
| 665 |
+
"mean": round(statistics.fmean(values), 6) if values else None,
|
| 666 |
+
"median": round(statistics.median(values), 6) if values else None,
|
| 667 |
+
"sample_std": round(statistics.stdev(values), 6) if len(values) >= 2 else None,
|
| 668 |
+
},
|
| 669 |
+
"threshold": threshold,
|
| 670 |
+
"years_at_or_above_threshold": len(threshold_rows),
|
| 671 |
+
"first_threshold_year": threshold_rows[0]["year"] if threshold_rows else None,
|
| 672 |
+
"last_threshold_year": threshold_rows[-1]["year"] if threshold_rows else None,
|
| 673 |
+
}
|
| 674 |
+
if year_aggregation:
|
| 675 |
+
summary["year_aggregation"] = year_aggregation
|
| 676 |
+
summary["source_row_count"] = len(raw_rows)
|
| 677 |
+
_write_json(output_dir / "summary.json", summary)
|
| 678 |
+
|
| 679 |
+
|
20260907-014711-computing-math-e1c8fb/solution/internal/workflow_runtime.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from workflow_adapters_runtime import software_tutorial_outputs
|
| 3 |
+
|
| 4 |
+
def run_reference(input_dir: Path, output_dir: Path) -> None:
|
| 5 |
+
software_tutorial_outputs(input_dir, output_dir)
|
20260907-014711-computing-math-e1c8fb/solution/reference_solution.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def main() -> int:
|
| 9 |
+
parser = argparse.ArgumentParser()
|
| 10 |
+
parser.add_argument("--input", required=True)
|
| 11 |
+
parser.add_argument("--output", required=True)
|
| 12 |
+
args = parser.parse_args()
|
| 13 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent / "internal"))
|
| 14 |
+
from workflow_runtime import run_reference
|
| 15 |
+
run_reference(Path(args.input), Path(args.output))
|
| 16 |
+
return 0
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
raise SystemExit(main())
|
20260907-014711-computing-math-e1c8fb/solution/solve.sh
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
INPUT_DIR="${1:-/workspace/input}"
|
| 4 |
+
OUTPUT_DIR="${2:-/workspace/output}"
|
| 5 |
+
SOLUTION_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
| 6 |
+
mkdir -p "${OUTPUT_DIR}"
|
| 7 |
+
python "${SOLUTION_DIR}/reference_solution.py" --input "${INPUT_DIR}" --output "${OUTPUT_DIR}"
|
20260907-014711-computing-math-e1c8fb/task.toml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version = "1.3"
|
| 2 |
+
artifacts = ["/workspace/output/summary.json", "/workspace/output/section_outline.csv", "/workspace/output/keyword_inventory.csv", "/workspace/output/code_block_inventory.csv"]
|
| 3 |
+
|
| 4 |
+
[task]
|
| 5 |
+
name = "ale-cli/20260907-014711-computing-math-e1c8fb"
|
| 6 |
+
description = "Audit a staged offline Docker official tutorial corpus and produce reproducible section, keyword, and command inventories from local files (keyword-subset experiment 3: 6 terms) (ALE-100 software diversity variant 5) (independent source snapshot 5). (repair batch 20260906; independent official sourc"
|
| 7 |
+
keywords = ["agents-last-exam", "ale-cli", "computing-math", "deterministic-evaluator", "linux-cli", "software-tutorial-doc-audit"]
|
| 8 |
+
|
| 9 |
+
[metadata]
|
| 10 |
+
benchmark = "ale_cli"
|
| 11 |
+
source_format = "ale_cli_official_style"
|
| 12 |
+
converter = "ale_cli_to_harbor"
|
| 13 |
+
source_task_key = "20260907-014711_computing_math_e1c8fb"
|
| 14 |
+
task_id = "computing_math/docker_bridge_documentation_audit__20260907-014711_computing_math_e1c8fb"
|
| 15 |
+
domain = "computing_math"
|
| 16 |
+
task = "docker_bridge_documentation_audit"
|
| 17 |
+
variant = "base"
|
| 18 |
+
oracle_available = true
|
| 19 |
+
scoring_method = "deterministic_hidden_evaluator"
|
| 20 |
+
required_outputs = ["summary.json", "section_outline.csv", "keyword_inventory.csv", "code_block_inventory.csv"]
|
| 21 |
+
|
| 22 |
+
[agent]
|
| 23 |
+
timeout_sec = 1800
|
| 24 |
+
|
| 25 |
+
[verifier]
|
| 26 |
+
timeout_sec = 600
|
| 27 |
+
environment_mode = "separate"
|
| 28 |
+
|
| 29 |
+
[verifier.environment]
|
| 30 |
+
build_timeout_sec = 900.0
|
| 31 |
+
network_mode = "public"
|
| 32 |
+
os = "linux"
|
| 33 |
+
cpus = 1
|
| 34 |
+
memory_mb = 2048
|
| 35 |
+
storage_mb = 4096
|
| 36 |
+
gpus = 0
|
| 37 |
+
|
| 38 |
+
[environment]
|
| 39 |
+
build_timeout_sec = 1200.0
|
| 40 |
+
network_mode = "public"
|
| 41 |
+
os = "linux"
|
| 42 |
+
cpus = 2
|
| 43 |
+
memory_mb = 4096
|
| 44 |
+
storage_mb = 10240
|
| 45 |
+
gpus = 0
|
20260907-014711-computing-math-e1c8fb/tests/Dockerfile
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /workspace
|
| 4 |
+
|
| 5 |
+
COPY . /tests
|
| 6 |
+
RUN chmod +x /tests/test.sh
|
20260907-014711-computing-math-e1c8fb/tests/evaluator_runner.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import importlib.util
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def read_json(path: Path) -> Any:
|
| 12 |
+
return json.loads(path.read_text(encoding="utf-8"))
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def write_json(path: Path, payload: Any) -> None:
|
| 16 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 17 |
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def reward(
|
| 21 |
+
*,
|
| 22 |
+
score: float,
|
| 23 |
+
output_present: float,
|
| 24 |
+
evaluator_available: float,
|
| 25 |
+
item_count: int,
|
| 26 |
+
format_score: float = 1.0,
|
| 27 |
+
) -> dict[str, float]:
|
| 28 |
+
clipped = max(0.0, min(1.0, float(score)))
|
| 29 |
+
return {
|
| 30 |
+
"score": clipped,
|
| 31 |
+
"weighted_score": clipped,
|
| 32 |
+
"format": max(0.0, min(1.0, float(format_score))),
|
| 33 |
+
"output_present": max(0.0, min(1.0, float(output_present))),
|
| 34 |
+
"evaluator_available": max(0.0, min(1.0, float(evaluator_available))),
|
| 35 |
+
"item_count": float(item_count),
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def load_evaluator(reference_dir: Path):
|
| 40 |
+
evaluator_path = reference_dir / "evaluator.py"
|
| 41 |
+
spec = importlib.util.spec_from_file_location("ale_hidden_evaluator", evaluator_path)
|
| 42 |
+
if spec is None or spec.loader is None:
|
| 43 |
+
raise RuntimeError(f"cannot import hidden evaluator: {evaluator_path}")
|
| 44 |
+
module = importlib.util.module_from_spec(spec)
|
| 45 |
+
spec.loader.exec_module(module)
|
| 46 |
+
return module
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def required_outputs(reference_dir: Path) -> list[dict[str, str]]:
|
| 50 |
+
manifest_path = reference_dir / "reference_manifest.json"
|
| 51 |
+
if not manifest_path.is_file():
|
| 52 |
+
return []
|
| 53 |
+
manifest = read_json(manifest_path)
|
| 54 |
+
rows = manifest.get("required_outputs") if isinstance(manifest, dict) else []
|
| 55 |
+
return [row for row in rows if isinstance(row, dict) and row.get("path")]
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def main() -> int:
|
| 59 |
+
parser = argparse.ArgumentParser(description="Run a hidden ALE CLI evaluator in Harbor.")
|
| 60 |
+
parser.add_argument("--output-dir", type=Path, required=True)
|
| 61 |
+
parser.add_argument("--reference-dir", type=Path, required=True)
|
| 62 |
+
parser.add_argument("--reward-json", type=Path, required=True)
|
| 63 |
+
parser.add_argument("--details-json", type=Path, required=True)
|
| 64 |
+
args = parser.parse_args()
|
| 65 |
+
|
| 66 |
+
required = required_outputs(args.reference_dir)
|
| 67 |
+
present = [row for row in required if (args.output_dir / str(row["path"])).is_file()]
|
| 68 |
+
item_count = len(required)
|
| 69 |
+
if not required:
|
| 70 |
+
write_json(args.reward_json, reward(score=0.0, output_present=0.0, evaluator_available=0.0, item_count=0, format_score=0.0))
|
| 71 |
+
write_json(args.details_json, {"ok": False, "error": "reference_manifest.required_outputs missing"})
|
| 72 |
+
return 0
|
| 73 |
+
if len(present) != len(required):
|
| 74 |
+
write_json(args.reward_json, reward(score=0.0, output_present=0.0, evaluator_available=1.0, item_count=item_count))
|
| 75 |
+
write_json(args.details_json, {"ok": True, "reason": "missing required outputs", "present": [row["path"] for row in present]})
|
| 76 |
+
return 0
|
| 77 |
+
try:
|
| 78 |
+
module = load_evaluator(args.reference_dir)
|
| 79 |
+
result = module.evaluate(args.output_dir, args.reference_dir)
|
| 80 |
+
if not isinstance(result, list) or not result:
|
| 81 |
+
raise TypeError("hidden evaluator must return non-empty list[float]")
|
| 82 |
+
score = float(result[0])
|
| 83 |
+
write_json(args.reward_json, reward(score=score, output_present=1.0, evaluator_available=1.0, item_count=item_count))
|
| 84 |
+
write_json(args.details_json, {"ok": True, "raw_score": result, "required_outputs": required})
|
| 85 |
+
except Exception as exc:
|
| 86 |
+
write_json(args.reward_json, reward(score=0.0, output_present=1.0, evaluator_available=0.0, item_count=item_count))
|
| 87 |
+
write_json(args.details_json, {"ok": False, "error": f"{type(exc).__name__}: {exc}", "required_outputs": required})
|
| 88 |
+
return 0
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
raise SystemExit(main())
|
20260907-014711-computing-math-e1c8fb/tests/reference/__pycache__/evaluator.cpython-312.pyc
ADDED
|
Binary file (6.23 kB). View file
|
|
|
20260907-014711-computing-math-e1c8fb/tests/reference/evaluator.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
import json
|
| 5 |
+
import math
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Any
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _load_json(path: Path) -> Any:
|
| 11 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 12 |
+
return json.load(handle)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _num_close(a: Any, b: Any, tol: float) -> bool:
|
| 16 |
+
try:
|
| 17 |
+
af = float(a)
|
| 18 |
+
bf = float(b)
|
| 19 |
+
except (TypeError, ValueError):
|
| 20 |
+
return False
|
| 21 |
+
if math.isnan(af) and math.isnan(bf):
|
| 22 |
+
return True
|
| 23 |
+
return abs(af - bf) <= tol
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _compare_json(actual: Any, expected: Any, tol: float) -> float:
|
| 27 |
+
if isinstance(expected, dict):
|
| 28 |
+
if not isinstance(actual, dict):
|
| 29 |
+
return 0.0
|
| 30 |
+
if not expected:
|
| 31 |
+
return 1.0
|
| 32 |
+
scores = []
|
| 33 |
+
for key, exp_value in expected.items():
|
| 34 |
+
if key not in actual:
|
| 35 |
+
scores.append(0.0)
|
| 36 |
+
else:
|
| 37 |
+
scores.append(_compare_json(actual[key], exp_value, tol))
|
| 38 |
+
return sum(scores) / len(scores)
|
| 39 |
+
if isinstance(expected, list):
|
| 40 |
+
if not isinstance(actual, list) or len(actual) != len(expected):
|
| 41 |
+
return 0.0
|
| 42 |
+
if not expected:
|
| 43 |
+
return 1.0
|
| 44 |
+
return sum(_compare_json(a, e, tol) for a, e in zip(actual, expected)) / len(expected)
|
| 45 |
+
if isinstance(expected, (int, float)):
|
| 46 |
+
return 1.0 if _num_close(actual, expected, tol) else 0.0
|
| 47 |
+
return 1.0 if actual == expected else 0.0
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _read_csv(path: Path) -> list[dict[str, str]]:
|
| 51 |
+
with path.open("r", encoding="utf-8", newline="") as handle:
|
| 52 |
+
return list(csv.DictReader(handle))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _compare_csv(actual_path: Path, expected_path: Path, tol: float) -> float:
|
| 56 |
+
try:
|
| 57 |
+
actual = _read_csv(actual_path)
|
| 58 |
+
expected = _read_csv(expected_path)
|
| 59 |
+
except Exception:
|
| 60 |
+
return 0.0
|
| 61 |
+
if len(actual) != len(expected):
|
| 62 |
+
return 0.0
|
| 63 |
+
if not expected:
|
| 64 |
+
return 1.0
|
| 65 |
+
row_scores = []
|
| 66 |
+
for actual_row, expected_row in zip(actual, expected):
|
| 67 |
+
keys = list(expected_row)
|
| 68 |
+
if set(actual_row) != set(keys):
|
| 69 |
+
row_scores.append(0.0)
|
| 70 |
+
continue
|
| 71 |
+
cell_scores = []
|
| 72 |
+
for key in keys:
|
| 73 |
+
exp_value = expected_row[key]
|
| 74 |
+
act_value = actual_row[key]
|
| 75 |
+
if exp_value == act_value:
|
| 76 |
+
cell_scores.append(1.0)
|
| 77 |
+
elif _num_close(act_value, exp_value, tol):
|
| 78 |
+
cell_scores.append(1.0)
|
| 79 |
+
else:
|
| 80 |
+
cell_scores.append(0.0)
|
| 81 |
+
row_scores.append(sum(cell_scores) / len(cell_scores) if cell_scores else 1.0)
|
| 82 |
+
return sum(row_scores) / len(row_scores)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def evaluate(output_dir: str | Path, reference_dir: str | Path | None = None) -> list[float]:
|
| 86 |
+
output_dir = Path(output_dir)
|
| 87 |
+
reference_dir = Path(reference_dir) if reference_dir is not None else Path(__file__).resolve().parent
|
| 88 |
+
manifest = _load_json(reference_dir / "reference_manifest.json")
|
| 89 |
+
tolerance = float(manifest.get("numeric_tolerance", 1e-9))
|
| 90 |
+
required = manifest.get("required_outputs") or []
|
| 91 |
+
if not required:
|
| 92 |
+
return [0.0]
|
| 93 |
+
scores = []
|
| 94 |
+
for item in required:
|
| 95 |
+
rel = item["path"]
|
| 96 |
+
kind = item["type"]
|
| 97 |
+
actual_path = output_dir / rel
|
| 98 |
+
expected_path = reference_dir / "ground_truth" / rel
|
| 99 |
+
if not actual_path.is_file() or not expected_path.is_file():
|
| 100 |
+
scores.append(0.0)
|
| 101 |
+
continue
|
| 102 |
+
try:
|
| 103 |
+
if kind == "json":
|
| 104 |
+
scores.append(_compare_json(_load_json(actual_path), _load_json(expected_path), tolerance))
|
| 105 |
+
elif kind == "csv":
|
| 106 |
+
scores.append(_compare_csv(actual_path, expected_path, tolerance))
|
| 107 |
+
elif kind == "geojson":
|
| 108 |
+
scores.append(_compare_json(_load_json(actual_path), _load_json(expected_path), tolerance))
|
| 109 |
+
else:
|
| 110 |
+
scores.append(1.0 if actual_path.read_bytes() == expected_path.read_bytes() else 0.0)
|
| 111 |
+
except Exception:
|
| 112 |
+
scores.append(0.0)
|
| 113 |
+
score = max(0.0, min(1.0, sum(scores) / len(scores)))
|
| 114 |
+
return [score]
|
20260907-014711-computing-math-e1c8fb/tests/reference/ground_truth/code_block_inventory.csv
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
block_index,line_count,char_count,contains_code_term,first_line
|
| 2 |
+
1,135,10785,true,---
|
| 3 |
+
2,8,457,true,"You can specify the subnet, the IP address range, the gateway, and other"
|
| 4 |
+
3,14,892,true,> **What's really happening?**
|
| 5 |
+
4,3,224,true,"To connect a **running** container to an existing user-defined bridge, use the"
|
| 6 |
+
5,4,246,true,## Disconnect a container from a user-defined bridge
|
| 7 |
+
6,2,125,false,## Use IPv6 in a user-defined bridge network
|
| 8 |
+
7,5,290,false,"If you do not provide a `--subnet` option, a Unique Local Address (ULA) prefix"
|
| 9 |
+
8,15,991,true,IPv4 address configuration cannot be disabled in the default bridge network.
|
| 10 |
+
9,22,1257,true,In this example:
|
| 11 |
+
10,31,1756,true,"If no `bip6` is specified, `fixed-cidr-v6` defines the subnet for the bridge"
|
| 12 |
+
11,4,289,false,"The default `bridge` network is listed, along with `host` and `none`."
|
| 13 |
+
12,1,35,false,Verify both containers are running:
|
| 14 |
+
13,1,60,false,3. Inspect the `bridge` network to see connected containers:
|
| 15 |
+
14,3,166,false,"The output shows both containers connected, with their assigned IP addresses"
|
| 16 |
+
15,1,68,false,Show the network interfaces for `alpine1` from within the container:
|
| 17 |
+
16,2,137,false,"In this example, the `eth0` interface has the IP address `172.17.0.2`."
|
| 18 |
+
17,1,47,false,6. Ping the second container by its IP address:
|
| 19 |
+
18,1,49,false,This succeeds. Now try pinging by container name:
|
| 20 |
+
19,3,195,false,"On the default bridge network, containers can't resolve each other by name."
|
| 21 |
+
20,5,245,false,Stopped containers lose their IP addresses.
|
| 22 |
+
21,1,26,true,2. List Docker's networks:
|
| 23 |
+
22,1,33,false,Inspect the `alpine-net` network:
|
| 24 |
+
23,4,254,false,"This shows the network's gateway (for example, `172.18.0.1`) and that no"
|
| 25 |
+
24,1,34,false,Verify all containers are running:
|
| 26 |
+
25,1,69,false,4. Inspect both networks again to see which containers are connected:
|
| 27 |
+
26,1,73,false,Containers `alpine3` and `alpine4` are connected to the `bridge` network.
|
| 28 |
+
27,7,320,false,"Containers `alpine1`, `alpine2`, and `alpine4` are connected to"
|
| 29 |
+
28,2,89,false,"6. From `alpine1`, you can't connect to `alpine3` because it's on a different"
|
| 30 |
+
29,1,72,false,You also can't connect by IP address. If `alpine3`'s IP is `172.17.0.2`:
|
| 31 |
+
30,3,176,false,Detach from `alpine1` using `CTRL+p CTRL+q`.
|
| 32 |
+
31,1,53,false,8. Verify all containers can connect to the internet:
|
| 33 |
+
32,3,95,false,Detach with `CTRL+p CTRL+q` and repeat for `alpine3` and `alpine1` if
|
| 34 |
+
33,4,184,false,## Next steps
|
20260907-014711-computing-math-e1c8fb/tests/reference/ground_truth/keyword_inventory.csv
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
term,category,count,first_window,appears_in_code
|
| 2 |
+
docker,code,90,1,true
|
| 3 |
+
docker build,code,0,,false
|
| 4 |
+
docker compose,code,0,,false
|
| 5 |
+
docker pull,code,0,,false
|
| 6 |
+
docker run,code,6,117,false
|
| 7 |
+
container,required,105,1,true
|
| 8 |
+
Docker,required,90,1,true
|
| 9 |
+
Dockerfile,required,0,,false
|
| 10 |
+
image,required,2,118,false
|
| 11 |
+
network,required,174,1,true
|
| 12 |
+
registry,required,0,,false
|
20260907-014711-computing-math-e1c8fb/tests/reference/ground_truth/section_outline.csv
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
rank,heading_level,heading_text,slug
|
| 2 |
+
1,h1,Source 1: bridge.md,source_1_bridge_md
|
| 3 |
+
2,h2,Differences between user-defined bridges and the default bridge,differences_between_user_defined_bridges_and_the_default_bridge
|
| 4 |
+
3,h2,Options,options
|
| 5 |
+
4,h3,Default host binding address,default_host_binding_address
|
| 6 |
+
5,h2,Manage a user-defined bridge,manage_a_user_defined_bridge
|
| 7 |
+
6,h2,Connect a container to a user-defined bridge,connect_a_container_to_a_user_defined_bridge
|
| 8 |
+
7,h2,Disconnect a container from a user-defined bridge,disconnect_a_container_from_a_user_defined_bridge
|
| 9 |
+
8,h2,Use IPv6 in a user-defined bridge network,use_ipv6_in_a_user_defined_bridge_network
|
| 10 |
+
9,h2,IPv6-only bridge networks,ipv6_only_bridge_networks
|
| 11 |
+
10,h2,Use the default bridge network,use_the_default_bridge_network
|
| 12 |
+
11,h3,Connect a container to the default bridge network,connect_a_container_to_the_default_bridge_network
|
| 13 |
+
12,h3,Configure the default bridge network,configure_the_default_bridge_network
|
| 14 |
+
13,h3,Use IPv6 with the default bridge network,use_ipv6_with_the_default_bridge_network
|
| 15 |
+
14,h2,Connection limit for bridge networks,connection_limit_for_bridge_networks
|
| 16 |
+
15,h2,Skip Bridge IP address configuration,skip_bridge_ip_address_configuration
|
| 17 |
+
16,h2,Usage examples,usage_examples
|
| 18 |
+
17,h3,Use the default bridge network,use_the_default_bridge_network
|
| 19 |
+
18,h3,Use user-defined bridge networks,use_user_defined_bridge_networks
|
| 20 |
+
19,h2,Next steps,next_steps
|
20260907-014711-computing-math-e1c8fb/tests/reference/ground_truth/summary.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"software_name": "Docker",
|
| 3 |
+
"source_file": "tutorial_source.html",
|
| 4 |
+
"window_count": 173,
|
| 5 |
+
"heading_count": 19,
|
| 6 |
+
"code_block_count": 33,
|
| 7 |
+
"keyword_total": 467,
|
| 8 |
+
"unique_required_terms_found": 4,
|
| 9 |
+
"top_keyword": "network",
|
| 10 |
+
"source_character_count": 24419
|
| 11 |
+
}
|
20260907-014711-computing-math-e1c8fb/tests/reference/internal/workflow_adapters_runtime.py
ADDED
|
@@ -0,0 +1,679 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
import datetime as dt
|
| 5 |
+
import html
|
| 6 |
+
import json
|
| 7 |
+
import math
|
| 8 |
+
import re
|
| 9 |
+
import shutil
|
| 10 |
+
import statistics
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _read_json(path: Path) -> Any:
|
| 16 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 17 |
+
return json.load(handle)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _write_json(path: Path, payload: Any) -> None:
|
| 21 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 22 |
+
with path.open("w", encoding="utf-8") as handle:
|
| 23 |
+
json.dump(payload, handle, ensure_ascii=False, indent=2)
|
| 24 |
+
handle.write("\n")
|
| 25 |
+
|
| 26 |
+
def _stable_region(place: str) -> str:
|
| 27 |
+
if not place:
|
| 28 |
+
return "unknown"
|
| 29 |
+
if "," in place:
|
| 30 |
+
return place.split(",")[-1].strip() or place.strip()
|
| 31 |
+
parts = place.split()
|
| 32 |
+
return " ".join(parts[-2:]) if len(parts) >= 2 else place.strip()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _mag_bin(value: float | None) -> str:
|
| 36 |
+
if value is None or math.isnan(value):
|
| 37 |
+
return "unknown"
|
| 38 |
+
lower = math.floor(value)
|
| 39 |
+
upper = lower + 1
|
| 40 |
+
return f"{lower:.0f}-{upper:.0f}"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _depth_bin(value: float | None) -> str:
|
| 44 |
+
if value is None or math.isnan(value):
|
| 45 |
+
return "unknown"
|
| 46 |
+
if value < 0:
|
| 47 |
+
return "<0"
|
| 48 |
+
if value < 10:
|
| 49 |
+
return "0-10"
|
| 50 |
+
if value < 30:
|
| 51 |
+
return "10-30"
|
| 52 |
+
if value < 70:
|
| 53 |
+
return "30-70"
|
| 54 |
+
if value < 300:
|
| 55 |
+
return "70-300"
|
| 56 |
+
return "300+"
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _clean_markup_text(raw: str) -> str:
|
| 60 |
+
text = re.sub(r"(?is)<(script|style|noscript)[^>]*>.*?</\1>", " ", raw)
|
| 61 |
+
text = re.sub(r"(?is)<br\s*/?>", "\n", text)
|
| 62 |
+
text = re.sub(r"(?is)</(p|div|li|tr|h[1-6]|pre)>", "\n", text)
|
| 63 |
+
text = re.sub(r"(?is)<[^>]+>", " ", text)
|
| 64 |
+
text = html.unescape(text)
|
| 65 |
+
text = re.sub(r"[ \t]+", " ", text)
|
| 66 |
+
text = re.sub(r"\n\s+", "\n", text)
|
| 67 |
+
return text.strip()
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _heading_slug(value: str) -> str:
|
| 71 |
+
slug = re.sub(r"[^a-z0-9]+", "_", value.lower()).strip("_")
|
| 72 |
+
return slug[:80] or "section"
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _extract_headings(raw: str) -> list[dict[str, str]]:
|
| 76 |
+
headings: list[dict[str, str]] = []
|
| 77 |
+
for match in re.finditer(r"(?is)<h([1-6])[^>]*>(.*?)</h\1>", raw):
|
| 78 |
+
text = _clean_markup_text(match.group(2))
|
| 79 |
+
if text:
|
| 80 |
+
headings.append({"level": f"h{match.group(1)}", "text": text})
|
| 81 |
+
if headings:
|
| 82 |
+
return headings
|
| 83 |
+
for line in raw.splitlines():
|
| 84 |
+
match = re.match(r"^(#{1,6})\s+(.+?)\s*$", line)
|
| 85 |
+
if match:
|
| 86 |
+
headings.append({"level": f"h{len(match.group(1))}", "text": match.group(2).strip()})
|
| 87 |
+
return headings
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _extract_code_blocks(raw: str) -> list[str]:
|
| 91 |
+
blocks: list[str] = []
|
| 92 |
+
for match in re.finditer(r"(?is)<pre[^>]*>(.*?)</pre>", raw):
|
| 93 |
+
text = _clean_markup_text(match.group(1))
|
| 94 |
+
if text:
|
| 95 |
+
blocks.append(text)
|
| 96 |
+
for match in re.finditer(r"(?is)<code[^>]*>(.*?)</code>", raw):
|
| 97 |
+
text = _clean_markup_text(match.group(1))
|
| 98 |
+
if text and text not in blocks:
|
| 99 |
+
blocks.append(text)
|
| 100 |
+
for match in re.finditer(r"(?s)```(?:[A-Za-z0-9_-]+)?\n(.*?)```", raw):
|
| 101 |
+
text = html.unescape(match.group(1).strip())
|
| 102 |
+
if text and text not in blocks:
|
| 103 |
+
blocks.append(text)
|
| 104 |
+
return blocks
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def _window_rows(clean_text: str, *, width: int = 40, stride: int = 20) -> list[dict[str, Any]]:
|
| 108 |
+
words = re.findall(r"\S+", clean_text)
|
| 109 |
+
rows: list[dict[str, Any]] = []
|
| 110 |
+
if not words:
|
| 111 |
+
return rows
|
| 112 |
+
start = 0
|
| 113 |
+
while start < len(words):
|
| 114 |
+
end = min(start + width, len(words))
|
| 115 |
+
rows.append({
|
| 116 |
+
"window_id": len(rows) + 1,
|
| 117 |
+
"start_word": start,
|
| 118 |
+
"end_word": end,
|
| 119 |
+
"text": " ".join(words[start:end]),
|
| 120 |
+
})
|
| 121 |
+
if end == len(words):
|
| 122 |
+
break
|
| 123 |
+
start += stride
|
| 124 |
+
return rows
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _term_count(text: str, term: str) -> int:
|
| 128 |
+
term = term.strip()
|
| 129 |
+
if not term:
|
| 130 |
+
return 0
|
| 131 |
+
return len(re.findall(re.escape(term), text, flags=re.IGNORECASE))
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _first_window(windows: list[dict[str, Any]], term: str) -> str:
|
| 135 |
+
term_lower = term.lower()
|
| 136 |
+
for row in windows:
|
| 137 |
+
if term_lower in str(row.get("text") or "").lower():
|
| 138 |
+
return str(row.get("window_id") or "")
|
| 139 |
+
return ""
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _write_tutorial_public_inputs(input_dir: Path, source_path: Path, spec_payload: dict[str, Any]) -> None:
|
| 143 |
+
raw = source_path.read_text(encoding="utf-8", errors="replace")
|
| 144 |
+
# Tutorial examples may contain a maintainer's local Windows path. Keep
|
| 145 |
+
# the command semantics while preventing host-specific paths from entering
|
| 146 |
+
# the public task artifact.
|
| 147 |
+
sanitized_raw = re.sub(r"(?i)\b[A-Z]:\\(?:[^\\\r\n<>\"']+\\?)*[^\\\r\n<>\"']*", "./local.db", raw)
|
| 148 |
+
clean_text = _clean_markup_text(sanitized_raw)
|
| 149 |
+
windows = _window_rows(clean_text)
|
| 150 |
+
if len(windows) < 100:
|
| 151 |
+
raise ValueError(f"official tutorial source produced only {len(windows)} text windows; need at least 100")
|
| 152 |
+
required_terms = [str(item) for item in spec_payload.get("required_terms") or []]
|
| 153 |
+
code_terms = [str(item) for item in spec_payload.get("code_terms") or []]
|
| 154 |
+
input_dir.mkdir(parents=True, exist_ok=True)
|
| 155 |
+
destination = input_dir / str(spec_payload["source_file"])
|
| 156 |
+
# Always materialize the sanitized copy, including when the downloader
|
| 157 |
+
# already placed the source at the destination path.
|
| 158 |
+
destination.write_text(sanitized_raw, encoding="utf-8")
|
| 159 |
+
with (input_dir / str(spec_payload["input_file"])).open("w", encoding="utf-8", newline="") as handle:
|
| 160 |
+
fieldnames = ["window_id", "start_word", "end_word", "text", "contains_code_term", "matched_required_terms"]
|
| 161 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 162 |
+
writer.writeheader()
|
| 163 |
+
for row in windows:
|
| 164 |
+
text = str(row["text"])
|
| 165 |
+
matched = [term for term in required_terms if term.lower() in text.lower()]
|
| 166 |
+
contains_code = any(term.lower() in text.lower() for term in code_terms)
|
| 167 |
+
writer.writerow({
|
| 168 |
+
"window_id": row["window_id"],
|
| 169 |
+
"start_word": row["start_word"],
|
| 170 |
+
"end_word": row["end_word"],
|
| 171 |
+
"text": text,
|
| 172 |
+
"contains_code_term": "true" if contains_code else "false",
|
| 173 |
+
"matched_required_terms": "|".join(matched),
|
| 174 |
+
})
|
| 175 |
+
metadata = {
|
| 176 |
+
"software_name": spec_payload.get("software_name"),
|
| 177 |
+
"tutorial_url": spec_payload.get("tutorial_url"),
|
| 178 |
+
"source_urls": spec_payload.get("source_urls"),
|
| 179 |
+
"source_file": spec_payload.get("source_file"),
|
| 180 |
+
"window_file": spec_payload.get("input_file"),
|
| 181 |
+
"window_rule": spec_payload.get("window_rule"),
|
| 182 |
+
"required_terms": spec_payload.get("required_terms"),
|
| 183 |
+
"code_terms": spec_payload.get("code_terms"),
|
| 184 |
+
"note": "Provenance and public extraction rules only; scored aggregate values are intentionally not stored here.",
|
| 185 |
+
}
|
| 186 |
+
_write_json(input_dir / "tutorial_metadata.json", metadata)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def _source_context_text(path: Path) -> str:
|
| 190 |
+
try:
|
| 191 |
+
raw = path.read_text(encoding="utf-8", errors="replace")
|
| 192 |
+
except Exception:
|
| 193 |
+
return f"{path.name}\nsha256={_sha256_file(path)}\nsize_bytes={path.stat().st_size}\n"
|
| 194 |
+
if path.suffix.lower() in {".html", ".htm", ".md", ".txt"}:
|
| 195 |
+
return _clean_markup_text(raw)
|
| 196 |
+
return re.sub(r"\s+", " ", raw).strip()
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def _ensure_public_input_footprint(input_dir: Path, source_paths: list[Path]) -> str:
|
| 200 |
+
current = _tree_file_bytes(input_dir)
|
| 201 |
+
if current >= MIN_PUBLIC_TASK_DATA_BYTES:
|
| 202 |
+
return f"public input footprint is {current} bytes; no context expansion needed"
|
| 203 |
+
context_path = input_dir / "source_context_windows.jsonl"
|
| 204 |
+
base = current - (context_path.stat().st_size if context_path.is_file() else 0)
|
| 205 |
+
context_path.unlink(missing_ok=True)
|
| 206 |
+
rows: list[dict[str, Any]] = []
|
| 207 |
+
for source in source_paths:
|
| 208 |
+
if not source.is_file() or source.resolve() == context_path.resolve():
|
| 209 |
+
continue
|
| 210 |
+
text = _source_context_text(source)
|
| 211 |
+
if not text:
|
| 212 |
+
continue
|
| 213 |
+
start = 0
|
| 214 |
+
width = 1800
|
| 215 |
+
stride = 900
|
| 216 |
+
while start < len(text):
|
| 217 |
+
end = min(len(text), start + width)
|
| 218 |
+
rows.append({
|
| 219 |
+
"source_file": source.relative_to(input_dir).as_posix() if source.is_relative_to(input_dir) else source.name,
|
| 220 |
+
"source_sha256": _sha256_file(source),
|
| 221 |
+
"start_char": start,
|
| 222 |
+
"end_char": end,
|
| 223 |
+
"text": text[start:end],
|
| 224 |
+
})
|
| 225 |
+
if end == len(text):
|
| 226 |
+
break
|
| 227 |
+
start += stride
|
| 228 |
+
if not rows:
|
| 229 |
+
raise ValueError("public input footprint expansion has no public source text")
|
| 230 |
+
input_dir.mkdir(parents=True, exist_ok=True)
|
| 231 |
+
rows_written = 0
|
| 232 |
+
target_extra = MIN_PUBLIC_TASK_DATA_BYTES - max(0, base)
|
| 233 |
+
with context_path.open("w", encoding="utf-8") as handle:
|
| 234 |
+
cycle = 0
|
| 235 |
+
while handle.tell() < target_extra or rows_written < 100:
|
| 236 |
+
row = dict(rows[rows_written % len(rows)])
|
| 237 |
+
row["window_id"] = rows_written + 1
|
| 238 |
+
row["cycle"] = cycle
|
| 239 |
+
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 240 |
+
rows_written += 1
|
| 241 |
+
if rows_written % len(rows) == 0:
|
| 242 |
+
cycle += 1
|
| 243 |
+
handle.flush()
|
| 244 |
+
return f"wrote input/source_context_windows.jsonl with {rows_written} public-source windows and {context_path.stat().st_size} bytes"
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _write_software_manifest(software_dir: Path, spec_payload: dict[str, Any]) -> None:
|
| 248 |
+
if str(spec_payload.get("workflow_kind") or "") != "software_tutorial_doc_audit":
|
| 249 |
+
return
|
| 250 |
+
software_dir.mkdir(parents=True, exist_ok=True)
|
| 251 |
+
software_name = str(spec_payload.get("software_name") or "").strip()
|
| 252 |
+
executables = [str(item).strip() for item in spec_payload.get("executables") or [] if str(item).strip()]
|
| 253 |
+
system_packages = [str(item).strip() for item in spec_payload.get("required_system_packages") or [] if str(item).strip()]
|
| 254 |
+
source_urls = [str(item).strip() for item in spec_payload.get("source_urls") or [] if str(item).strip()]
|
| 255 |
+
_write_json(software_dir / "software_manifest.json", {
|
| 256 |
+
"software_name": software_name,
|
| 257 |
+
"executables": executables,
|
| 258 |
+
"required_system_packages": system_packages,
|
| 259 |
+
"official_sources": source_urls,
|
| 260 |
+
"solve_time_network": "disabled",
|
| 261 |
+
"python_wrapper_only": False,
|
| 262 |
+
"note": "This task audits real official software documentation/source staged offline; Python helpers only validate outputs.",
|
| 263 |
+
})
|
| 264 |
+
with (software_dir / "command_examples.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 265 |
+
writer = csv.DictWriter(handle, fieldnames=["term", "kind", "software_name"])
|
| 266 |
+
writer.writeheader()
|
| 267 |
+
for term in spec_payload.get("code_terms") or []:
|
| 268 |
+
writer.writerow({"term": str(term), "kind": "code_term", "software_name": software_name})
|
| 269 |
+
for exe in executables:
|
| 270 |
+
writer.writerow({"term": exe, "kind": "executable", "software_name": software_name})
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def software_tutorial_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 274 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 275 |
+
source_file = str(spec["source_file"])
|
| 276 |
+
source_text = (input_dir / source_file).read_text(encoding="utf-8", errors="replace")
|
| 277 |
+
clean_text = _clean_markup_text(source_text)
|
| 278 |
+
headings = _extract_headings(source_text)
|
| 279 |
+
code_blocks = _extract_code_blocks(source_text)
|
| 280 |
+
window_rows: list[dict[str, str]] = []
|
| 281 |
+
with (input_dir / str(spec["input_file"])).open("r", encoding="utf-8", newline="") as handle:
|
| 282 |
+
window_rows = list(csv.DictReader(handle))
|
| 283 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 284 |
+
|
| 285 |
+
with (output_dir / "section_outline.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 286 |
+
fieldnames = ["rank", "heading_level", "heading_text", "slug"]
|
| 287 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 288 |
+
writer.writeheader()
|
| 289 |
+
for rank, heading in enumerate(headings, start=1):
|
| 290 |
+
writer.writerow({
|
| 291 |
+
"rank": rank,
|
| 292 |
+
"heading_level": heading["level"],
|
| 293 |
+
"heading_text": heading["text"],
|
| 294 |
+
"slug": _heading_slug(heading["text"]),
|
| 295 |
+
})
|
| 296 |
+
|
| 297 |
+
all_terms: list[tuple[str, str]] = []
|
| 298 |
+
for term in spec.get("required_terms") or []:
|
| 299 |
+
all_terms.append((str(term), "required"))
|
| 300 |
+
for term in spec.get("code_terms") or []:
|
| 301 |
+
if str(term) not in {item[0] for item in all_terms}:
|
| 302 |
+
all_terms.append((str(term), "code"))
|
| 303 |
+
code_text = "\n".join(code_blocks)
|
| 304 |
+
term_rows: list[dict[str, Any]] = []
|
| 305 |
+
for term, category in all_terms:
|
| 306 |
+
term_rows.append({
|
| 307 |
+
"term": term,
|
| 308 |
+
"category": category,
|
| 309 |
+
"count": _term_count(clean_text, term),
|
| 310 |
+
"first_window": _first_window(window_rows, term),
|
| 311 |
+
"appears_in_code": "true" if term.lower() in code_text.lower() else "false",
|
| 312 |
+
})
|
| 313 |
+
term_rows.sort(key=lambda row: (str(row["category"]), str(row["term"]).lower()))
|
| 314 |
+
with (output_dir / "keyword_inventory.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 315 |
+
fieldnames = ["term", "category", "count", "first_window", "appears_in_code"]
|
| 316 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 317 |
+
writer.writeheader()
|
| 318 |
+
for row in term_rows:
|
| 319 |
+
writer.writerow(row)
|
| 320 |
+
|
| 321 |
+
code_terms = [str(item).lower() for item in spec.get("code_terms") or []]
|
| 322 |
+
with (output_dir / "code_block_inventory.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 323 |
+
fieldnames = ["block_index", "line_count", "char_count", "contains_code_term", "first_line"]
|
| 324 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 325 |
+
writer.writeheader()
|
| 326 |
+
for index, block in enumerate(code_blocks, start=1):
|
| 327 |
+
lines = [line for line in block.splitlines() if line.strip()]
|
| 328 |
+
contains = any(term and term in block.lower() for term in code_terms)
|
| 329 |
+
writer.writerow({
|
| 330 |
+
"block_index": index,
|
| 331 |
+
"line_count": len(lines),
|
| 332 |
+
"char_count": len(block),
|
| 333 |
+
"contains_code_term": "true" if contains else "false",
|
| 334 |
+
"first_line": lines[0][:200] if lines else "",
|
| 335 |
+
})
|
| 336 |
+
|
| 337 |
+
keyword_total = sum(int(row["count"]) for row in term_rows)
|
| 338 |
+
required_found = sum(1 for row in term_rows if row["category"] == "required" and int(row["count"]) > 0)
|
| 339 |
+
top_keyword = None
|
| 340 |
+
if term_rows:
|
| 341 |
+
top = max(term_rows, key=lambda row: (int(row["count"]), str(row["term"]).lower()))
|
| 342 |
+
top_keyword = str(top["term"]) if int(top["count"]) > 0 else None
|
| 343 |
+
summary = {
|
| 344 |
+
"software_name": str(spec.get("software_name") or ""),
|
| 345 |
+
"source_file": source_file,
|
| 346 |
+
"window_count": len(window_rows),
|
| 347 |
+
"heading_count": len(headings),
|
| 348 |
+
"code_block_count": len(code_blocks),
|
| 349 |
+
"keyword_total": keyword_total,
|
| 350 |
+
"unique_required_terms_found": required_found,
|
| 351 |
+
"top_keyword": top_keyword,
|
| 352 |
+
"source_character_count": len(clean_text),
|
| 353 |
+
}
|
| 354 |
+
_write_json(output_dir / "summary.json", summary)
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
def geojson_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 358 |
+
payload = _read_json(input_dir / "events.geojson")
|
| 359 |
+
features = payload.get("features") if isinstance(payload, dict) else []
|
| 360 |
+
rows: list[dict[str, Any]] = []
|
| 361 |
+
for feature in features:
|
| 362 |
+
if not isinstance(feature, dict):
|
| 363 |
+
continue
|
| 364 |
+
props = feature.get("properties") if isinstance(feature.get("properties"), dict) else {}
|
| 365 |
+
geom = feature.get("geometry") if isinstance(feature.get("geometry"), dict) else {}
|
| 366 |
+
coords = geom.get("coordinates") if isinstance(geom.get("coordinates"), list) else []
|
| 367 |
+
mag = props.get("mag")
|
| 368 |
+
try:
|
| 369 |
+
mag = float(mag) if mag is not None else None
|
| 370 |
+
except (TypeError, ValueError):
|
| 371 |
+
mag = None
|
| 372 |
+
depth = None
|
| 373 |
+
if len(coords) >= 3:
|
| 374 |
+
try:
|
| 375 |
+
depth = float(coords[2])
|
| 376 |
+
except (TypeError, ValueError):
|
| 377 |
+
depth = None
|
| 378 |
+
time_ms = props.get("time")
|
| 379 |
+
date_utc = "unknown"
|
| 380 |
+
if isinstance(time_ms, (int, float)):
|
| 381 |
+
date_utc = dt.datetime.utcfromtimestamp(time_ms / 1000).date().isoformat()
|
| 382 |
+
rows.append({
|
| 383 |
+
"id": feature.get("id") or props.get("code") or "",
|
| 384 |
+
"mag": mag,
|
| 385 |
+
"depth": depth,
|
| 386 |
+
"place": str(props.get("place") or ""),
|
| 387 |
+
"region": _stable_region(str(props.get("place") or "")),
|
| 388 |
+
"date_utc": date_utc,
|
| 389 |
+
"feature": feature,
|
| 390 |
+
})
|
| 391 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 392 |
+
mags = [row["mag"] for row in rows if row["mag"] is not None]
|
| 393 |
+
depths = [row["depth"] for row in rows if row["depth"] is not None]
|
| 394 |
+
summary = {
|
| 395 |
+
"event_count": len(rows),
|
| 396 |
+
"magnitude": {
|
| 397 |
+
"count": len(mags),
|
| 398 |
+
"min": round(min(mags), 6) if mags else None,
|
| 399 |
+
"max": round(max(mags), 6) if mags else None,
|
| 400 |
+
"mean": round(statistics.fmean(mags), 6) if mags else None,
|
| 401 |
+
"median": round(statistics.median(mags), 6) if mags else None,
|
| 402 |
+
},
|
| 403 |
+
"depth_km": {
|
| 404 |
+
"count": len(depths),
|
| 405 |
+
"min": round(min(depths), 6) if depths else None,
|
| 406 |
+
"max": round(max(depths), 6) if depths else None,
|
| 407 |
+
"mean": round(statistics.fmean(depths), 6) if depths else None,
|
| 408 |
+
},
|
| 409 |
+
"time_range_utc": {
|
| 410 |
+
"start_date": min((row["date_utc"] for row in rows if row["date_utc"] != "unknown"), default=None),
|
| 411 |
+
"end_date": max((row["date_utc"] for row in rows if row["date_utc"] != "unknown"), default=None),
|
| 412 |
+
},
|
| 413 |
+
"quality_flags": {
|
| 414 |
+
"missing_magnitude": sum(1 for row in rows if row["mag"] is None),
|
| 415 |
+
"missing_depth": sum(1 for row in rows if row["depth"] is None),
|
| 416 |
+
"unique_regions": len({row["region"] for row in rows}),
|
| 417 |
+
},
|
| 418 |
+
}
|
| 419 |
+
_write_json(output_dir / "summary.json", summary)
|
| 420 |
+
|
| 421 |
+
grouped: dict[tuple[str, str], list[dict[str, Any]]] = {}
|
| 422 |
+
for row in rows:
|
| 423 |
+
grouped.setdefault((_mag_bin(row["mag"]), _depth_bin(row["depth"])), []).append(row)
|
| 424 |
+
with (output_dir / "magnitude_depth_bins.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 425 |
+
fieldnames = ["mag_bin", "depth_bin", "event_count", "mean_magnitude", "max_magnitude"]
|
| 426 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 427 |
+
writer.writeheader()
|
| 428 |
+
for (mag_bin, depth_bin), group in sorted(grouped.items()):
|
| 429 |
+
group_mags = [row["mag"] for row in group if row["mag"] is not None]
|
| 430 |
+
writer.writerow({
|
| 431 |
+
"mag_bin": mag_bin,
|
| 432 |
+
"depth_bin": depth_bin,
|
| 433 |
+
"event_count": len(group),
|
| 434 |
+
"mean_magnitude": f"{statistics.fmean(group_mags):.6f}" if group_mags else "",
|
| 435 |
+
"max_magnitude": f"{max(group_mags):.6f}" if group_mags else "",
|
| 436 |
+
})
|
| 437 |
+
|
| 438 |
+
daily: dict[tuple[str, str], list[dict[str, Any]]] = {}
|
| 439 |
+
for row in rows:
|
| 440 |
+
daily.setdefault((row["region"], row["date_utc"]), []).append(row)
|
| 441 |
+
with (output_dir / "region_daily_counts.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 442 |
+
fieldnames = ["region", "date_utc", "event_count", "max_magnitude"]
|
| 443 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 444 |
+
writer.writeheader()
|
| 445 |
+
for (region, date_utc), group in sorted(daily.items()):
|
| 446 |
+
group_mags = [row["mag"] for row in group if row["mag"] is not None]
|
| 447 |
+
writer.writerow({
|
| 448 |
+
"region": region,
|
| 449 |
+
"date_utc": date_utc,
|
| 450 |
+
"event_count": len(group),
|
| 451 |
+
"max_magnitude": f"{max(group_mags):.6f}" if group_mags else "",
|
| 452 |
+
})
|
| 453 |
+
|
| 454 |
+
filtered = [row["feature"] for row in rows if row["mag"] is not None and row["mag"] >= 4.5]
|
| 455 |
+
_write_json(output_dir / "filtered_events.geojson", {"type": "FeatureCollection", "features": filtered})
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def csv_time_series_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 459 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 460 |
+
csv_name = spec["input_file"]
|
| 461 |
+
date_column = spec["date_column"]
|
| 462 |
+
value_column = spec["value_column"]
|
| 463 |
+
rows: list[dict[str, Any]] = []
|
| 464 |
+
with (input_dir / csv_name).open("r", encoding="utf-8", newline="") as raw_handle:
|
| 465 |
+
lines = [line for line in raw_handle if not line.lstrip().startswith("#")]
|
| 466 |
+
reader = csv.DictReader(lines)
|
| 467 |
+
for item in reader:
|
| 468 |
+
raw_date = item.get(date_column, "")
|
| 469 |
+
try:
|
| 470 |
+
day = dt.date.fromisoformat(raw_date)
|
| 471 |
+
except ValueError:
|
| 472 |
+
if raw_date.isdigit() and len(raw_date) == 4:
|
| 473 |
+
day = dt.date(int(raw_date), 1, 1)
|
| 474 |
+
else:
|
| 475 |
+
continue
|
| 476 |
+
raw_value = item.get(value_column, "")
|
| 477 |
+
try:
|
| 478 |
+
value = float(raw_value)
|
| 479 |
+
except (TypeError, ValueError):
|
| 480 |
+
value = None
|
| 481 |
+
rows.append({"date": day, "value": value, "raw": item})
|
| 482 |
+
rows.sort(key=lambda item: item["date"])
|
| 483 |
+
valid = [row for row in rows if row["value"] is not None]
|
| 484 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 485 |
+
monthly: dict[str, list[float]] = {}
|
| 486 |
+
for row in valid:
|
| 487 |
+
key = row["date"].strftime("%Y-%m")
|
| 488 |
+
monthly.setdefault(key, []).append(row["value"])
|
| 489 |
+
with (output_dir / "monthly_statistics.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 490 |
+
fieldnames = ["month", "count", "mean", "median", "min", "max"]
|
| 491 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 492 |
+
writer.writeheader()
|
| 493 |
+
for month, values in sorted(monthly.items()):
|
| 494 |
+
writer.writerow({
|
| 495 |
+
"month": month,
|
| 496 |
+
"count": len(values),
|
| 497 |
+
"mean": f"{statistics.fmean(values):.6f}",
|
| 498 |
+
"median": f"{statistics.median(values):.6f}",
|
| 499 |
+
"min": f"{min(values):.6f}",
|
| 500 |
+
"max": f"{max(values):.6f}",
|
| 501 |
+
})
|
| 502 |
+
existing_dates = {row["date"] for row in rows}
|
| 503 |
+
missing_days: list[dt.date] = []
|
| 504 |
+
if rows:
|
| 505 |
+
day = rows[0]["date"]
|
| 506 |
+
while day <= rows[-1]["date"]:
|
| 507 |
+
if day.weekday() < 5 and day not in existing_dates:
|
| 508 |
+
missing_days.append(day)
|
| 509 |
+
day += dt.timedelta(days=1)
|
| 510 |
+
with (output_dir / "missing_business_days.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 511 |
+
writer = csv.DictWriter(handle, fieldnames=["date"])
|
| 512 |
+
writer.writeheader()
|
| 513 |
+
for day in missing_days:
|
| 514 |
+
writer.writerow({"date": day.isoformat()})
|
| 515 |
+
with (output_dir / "clean_series.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 516 |
+
writer = csv.DictWriter(handle, fieldnames=["date", "value"])
|
| 517 |
+
writer.writeheader()
|
| 518 |
+
for row in valid:
|
| 519 |
+
writer.writerow({"date": row["date"].isoformat(), "value": f"{row['value']:.6f}"})
|
| 520 |
+
values = [row["value"] for row in valid]
|
| 521 |
+
summary = {
|
| 522 |
+
"series_name": spec.get("series_name", value_column),
|
| 523 |
+
"row_count": len(rows),
|
| 524 |
+
"valid_value_count": len(valid),
|
| 525 |
+
"missing_value_count": len(rows) - len(valid),
|
| 526 |
+
"missing_business_day_count": len(missing_days),
|
| 527 |
+
"date_range": {
|
| 528 |
+
"start": rows[0]["date"].isoformat() if rows else None,
|
| 529 |
+
"end": rows[-1]["date"].isoformat() if rows else None,
|
| 530 |
+
},
|
| 531 |
+
"value": {
|
| 532 |
+
"min": round(min(values), 6) if values else None,
|
| 533 |
+
"max": round(max(values), 6) if values else None,
|
| 534 |
+
"mean": round(statistics.fmean(values), 6) if values else None,
|
| 535 |
+
"median": round(statistics.median(values), 6) if values else None,
|
| 536 |
+
},
|
| 537 |
+
}
|
| 538 |
+
_write_json(output_dir / "summary.json", summary)
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
def _aggregate_annual_rows(rows: list[dict[str, Any]], aggregation: str) -> list[dict[str, Any]]:
|
| 542 |
+
if not aggregation:
|
| 543 |
+
return rows
|
| 544 |
+
grouped: dict[int, list[float]] = {}
|
| 545 |
+
for row in rows:
|
| 546 |
+
grouped.setdefault(int(row["year"]), []).append(float(row["value"]))
|
| 547 |
+
aggregated: list[dict[str, Any]] = []
|
| 548 |
+
for year, values in sorted(grouped.items()):
|
| 549 |
+
if aggregation == "mean":
|
| 550 |
+
value = statistics.fmean(values)
|
| 551 |
+
elif aggregation == "median":
|
| 552 |
+
value = statistics.median(values)
|
| 553 |
+
elif aggregation == "max":
|
| 554 |
+
value = max(values)
|
| 555 |
+
elif aggregation == "min":
|
| 556 |
+
value = min(values)
|
| 557 |
+
elif aggregation == "count":
|
| 558 |
+
value = float(len(values))
|
| 559 |
+
else:
|
| 560 |
+
raise ValueError(f"unsupported year_aggregation for csv_annual_series_audit: {aggregation}")
|
| 561 |
+
aggregated.append({"year": year, "value": value})
|
| 562 |
+
return aggregated
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
def csv_annual_series_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 566 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 567 |
+
csv_name = spec["input_file"]
|
| 568 |
+
year_column = spec["year_column"]
|
| 569 |
+
value_column = spec["value_column"]
|
| 570 |
+
# Optional: derive the year from an ISO-8601 timestamp column (e.g. USGS FDSN
|
| 571 |
+
# `time` = "2022-06-29T19:17:58.929Z") instead of parsing an integer year.
|
| 572 |
+
# When unset, behaviour is unchanged (integer year column).
|
| 573 |
+
year_from_timestamp = bool(spec.get("year_from_timestamp", False))
|
| 574 |
+
year_aggregation = str(spec.get("year_aggregation") or "").strip().lower()
|
| 575 |
+
raw_rows: list[dict[str, Any]] = []
|
| 576 |
+
with (input_dir / csv_name).open("r", encoding="utf-8", newline="") as raw_handle:
|
| 577 |
+
lines = [line for line in raw_handle if not line.lstrip().startswith("#")]
|
| 578 |
+
reader = csv.DictReader(lines)
|
| 579 |
+
for item in reader:
|
| 580 |
+
raw_year = str(item.get(year_column, "")).strip()
|
| 581 |
+
try:
|
| 582 |
+
if year_from_timestamp:
|
| 583 |
+
# Take the leading 4-digit year of an ISO timestamp/date.
|
| 584 |
+
match = re.match(r"\s*(\d{4})", raw_year)
|
| 585 |
+
if not match:
|
| 586 |
+
continue
|
| 587 |
+
year = int(match.group(1))
|
| 588 |
+
else:
|
| 589 |
+
year = int(raw_year)
|
| 590 |
+
value = float(str(item.get(value_column, "")).strip())
|
| 591 |
+
except (TypeError, ValueError):
|
| 592 |
+
continue
|
| 593 |
+
raw_rows.append({"year": year, "value": value})
|
| 594 |
+
rows = _aggregate_annual_rows(raw_rows, year_aggregation)
|
| 595 |
+
rows.sort(key=lambda item: item["year"])
|
| 596 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 597 |
+
decades: dict[str, list[float]] = {}
|
| 598 |
+
for row in rows:
|
| 599 |
+
decade_start = (row["year"] // 10) * 10
|
| 600 |
+
decades.setdefault(f"{decade_start}s", []).append(row["value"])
|
| 601 |
+
with (output_dir / "decadal_statistics.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 602 |
+
fieldnames = [
|
| 603 |
+
"decade_start",
|
| 604 |
+
"start_year",
|
| 605 |
+
"end_year",
|
| 606 |
+
"count",
|
| 607 |
+
"mean_departure",
|
| 608 |
+
"median_departure",
|
| 609 |
+
"min_departure",
|
| 610 |
+
"max_departure",
|
| 611 |
+
"sample_std_departure",
|
| 612 |
+
]
|
| 613 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 614 |
+
writer.writeheader()
|
| 615 |
+
for decade, values in sorted(decades.items()):
|
| 616 |
+
decade_start = int(decade.rstrip("s"))
|
| 617 |
+
years = [row["year"] for row in rows if decade_start <= row["year"] <= decade_start + 9]
|
| 618 |
+
writer.writerow({
|
| 619 |
+
"decade_start": decade_start,
|
| 620 |
+
"start_year": min(years),
|
| 621 |
+
"end_year": max(years),
|
| 622 |
+
"count": len(values),
|
| 623 |
+
"mean_departure": f"{statistics.fmean(values):.6f}",
|
| 624 |
+
"median_departure": f"{statistics.median(values):.6f}",
|
| 625 |
+
"min_departure": f"{min(values):.6f}",
|
| 626 |
+
"max_departure": f"{max(values):.6f}",
|
| 627 |
+
"sample_std_departure": f"{statistics.stdev(values):.6f}" if len(values) >= 2 else "",
|
| 628 |
+
})
|
| 629 |
+
threshold = float(spec.get("threshold", 1.0))
|
| 630 |
+
with (output_dir / "threshold_years.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 631 |
+
fieldnames = ["rank", "year", "departure", "threshold"]
|
| 632 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 633 |
+
writer.writeheader()
|
| 634 |
+
rank = 1
|
| 635 |
+
for row in rows:
|
| 636 |
+
if row["value"] >= threshold:
|
| 637 |
+
writer.writerow({
|
| 638 |
+
"rank": rank,
|
| 639 |
+
"year": row["year"],
|
| 640 |
+
"departure": f"{row['value']:.6f}",
|
| 641 |
+
"threshold": f"{threshold:.6f}",
|
| 642 |
+
})
|
| 643 |
+
rank += 1
|
| 644 |
+
with (output_dir / "clean_series.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 645 |
+
writer = csv.DictWriter(handle, fieldnames=["Year", "Departure from Average"])
|
| 646 |
+
writer.writeheader()
|
| 647 |
+
for row in rows:
|
| 648 |
+
writer.writerow({"Year": row["year"], "Departure from Average": f"{row['value']:.6f}"})
|
| 649 |
+
values = [row["value"] for row in rows]
|
| 650 |
+
threshold_rows = [row for row in rows if row["value"] >= threshold]
|
| 651 |
+
min_row = min(rows, key=lambda row: row["value"]) if rows else None
|
| 652 |
+
max_row = max(rows, key=lambda row: row["value"]) if rows else None
|
| 653 |
+
summary = {
|
| 654 |
+
"series_name": spec.get("series_name", value_column),
|
| 655 |
+
"row_count": len(rows),
|
| 656 |
+
"year_range": {
|
| 657 |
+
"start": rows[0]["year"] if rows else None,
|
| 658 |
+
"end": rows[-1]["year"] if rows else None,
|
| 659 |
+
},
|
| 660 |
+
"value": {
|
| 661 |
+
"min": round(min(values), 6) if values else None,
|
| 662 |
+
"min_year": min_row["year"] if min_row else None,
|
| 663 |
+
"max": round(max(values), 6) if values else None,
|
| 664 |
+
"max_year": max_row["year"] if max_row else None,
|
| 665 |
+
"mean": round(statistics.fmean(values), 6) if values else None,
|
| 666 |
+
"median": round(statistics.median(values), 6) if values else None,
|
| 667 |
+
"sample_std": round(statistics.stdev(values), 6) if len(values) >= 2 else None,
|
| 668 |
+
},
|
| 669 |
+
"threshold": threshold,
|
| 670 |
+
"years_at_or_above_threshold": len(threshold_rows),
|
| 671 |
+
"first_threshold_year": threshold_rows[0]["year"] if threshold_rows else None,
|
| 672 |
+
"last_threshold_year": threshold_rows[-1]["year"] if threshold_rows else None,
|
| 673 |
+
}
|
| 674 |
+
if year_aggregation:
|
| 675 |
+
summary["year_aggregation"] = year_aggregation
|
| 676 |
+
summary["source_row_count"] = len(raw_rows)
|
| 677 |
+
_write_json(output_dir / "summary.json", summary)
|
| 678 |
+
|
| 679 |
+
|
20260907-014711-computing-math-e1c8fb/tests/reference/internal/workflow_runtime.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from workflow_adapters_runtime import software_tutorial_outputs
|
| 3 |
+
|
| 4 |
+
def run_reference(input_dir: Path, output_dir: Path) -> None:
|
| 5 |
+
software_tutorial_outputs(input_dir, output_dir)
|
20260907-014711-computing-math-e1c8fb/tests/reference/reference_manifest.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"workflow_kind": "software_tutorial_doc_audit",
|
| 3 |
+
"task_id": "repair4_20260907_029_repair3_20260907_048_repair2_20260906_053_repair_20260906_software_0084",
|
| 4 |
+
"domain": "computing_math",
|
| 5 |
+
"task": "docker_bridge_documentation_audit",
|
| 6 |
+
"variant": "base",
|
| 7 |
+
"created_from": "standard reference workflow",
|
| 8 |
+
"required_outputs": [
|
| 9 |
+
{
|
| 10 |
+
"path": "summary.json",
|
| 11 |
+
"type": "json"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"path": "section_outline.csv",
|
| 15 |
+
"type": "csv"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"path": "keyword_inventory.csv",
|
| 19 |
+
"type": "csv"
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"path": "code_block_inventory.csv",
|
| 23 |
+
"type": "csv"
|
| 24 |
+
}
|
| 25 |
+
],
|
| 26 |
+
"numeric_tolerance": 1e-09,
|
| 27 |
+
"source_prior_sha256": "34f5357f7ca4b63e6463e06c54cb0ecb9485fff6d7844e3ebf871f1694d0c58e",
|
| 28 |
+
"gold_output_hashes": {
|
| 29 |
+
"summary.json": "cf2503abe57c7bf8138ac18a418370d8b6c6c86ac1aaf72911c1462ec8ab7751",
|
| 30 |
+
"section_outline.csv": "ca0685381edfcd5a6c7073f45ec3a7e83695c98eafd631e3c6c9ff90bac9a3ae",
|
| 31 |
+
"keyword_inventory.csv": "da2a96d0bea20e2059bf36e84d917f12d29545cb68adf1cbcc9bf08f74191a7d",
|
| 32 |
+
"code_block_inventory.csv": "30fe74d82029b0cbdb380ceee6b5468ad59ef80ebff7eef7eb47d872b9199f47"
|
| 33 |
+
}
|
| 34 |
+
}
|
20260907-014711-computing-math-e1c8fb/tests/reference/reference_solution.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def main() -> int:
|
| 9 |
+
parser = argparse.ArgumentParser()
|
| 10 |
+
parser.add_argument("--input", required=True)
|
| 11 |
+
parser.add_argument("--output", required=True)
|
| 12 |
+
args = parser.parse_args()
|
| 13 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent / "internal"))
|
| 14 |
+
from workflow_runtime import run_reference
|
| 15 |
+
run_reference(Path(args.input), Path(args.output))
|
| 16 |
+
return 0
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
raise SystemExit(main())
|
20260907-014711-computing-math-e1c8fb/tests/test.sh
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -u
|
| 3 |
+
|
| 4 |
+
TESTS_DIR="${HARBOR_TESTS_DIR:-/tests}"
|
| 5 |
+
WORKSPACE_DIR="${HARBOR_WORKSPACE_DIR:-/workspace}"
|
| 6 |
+
LOGS_DIR="${HARBOR_LOGS_DIR:-/logs/verifier}"
|
| 7 |
+
|
| 8 |
+
mkdir -p "${LOGS_DIR}" "${WORKSPACE_DIR}/output"
|
| 9 |
+
|
| 10 |
+
python "${TESTS_DIR}/evaluator_runner.py" \
|
| 11 |
+
--output-dir "${WORKSPACE_DIR}/output" \
|
| 12 |
+
--reference-dir "${TESTS_DIR}/reference" \
|
| 13 |
+
--reward-json "${LOGS_DIR}/reward.json" \
|
| 14 |
+
--details-json "${LOGS_DIR}/ale_evaluator_details.json"
|
| 15 |
+
|
| 16 |
+
if [ ! -f "${LOGS_DIR}/reward.json" ]; then
|
| 17 |
+
echo '{"score":0.0,"format":0.0,"output_present":0.0,"evaluator_available":0.0,"item_count":0.0}' > "${LOGS_DIR}/reward.json"
|
| 18 |
+
fi
|
| 19 |
+
|
| 20 |
+
python - <<'PY' "${LOGS_DIR}/reward.json" "${LOGS_DIR}/reward.txt"
|
| 21 |
+
import json
|
| 22 |
+
import sys
|
| 23 |
+
from pathlib import Path
|
| 24 |
+
reward = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8"))
|
| 25 |
+
score = float(reward.get("score", 0.0))
|
| 26 |
+
Path(sys.argv[2]).write_text(f"{score}\n", encoding="utf-8")
|
| 27 |
+
PY
|
| 28 |
+
|
| 29 |
+
exit 0
|
20260907-014716-computing-math-8018f2/.DS_Store
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dc5bb7ef9a1f915b753149f58cb6cb2a8d5b69a4e4a4879a925aecfcafe0b2a6
|
| 3 |
+
size 6148
|
20260907-014716-computing-math-8018f2/environment/Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /workspace
|
| 4 |
+
|
| 5 |
+
COPY public_data/input /workspace/input
|
| 6 |
+
COPY public_data/software /workspace/software
|
| 7 |
+
COPY public_data/task_card.json /workspace/task_card.json
|
| 8 |
+
COPY public_data/main.py /workspace/main.py
|
| 9 |
+
COPY public_data/README.md /workspace/README.md
|
| 10 |
+
|
| 11 |
+
RUN mkdir -p /workspace/output /workspace/report /logs/agent /logs/artifacts \
|
| 12 |
+
&& chmod -R 777 /workspace/output /workspace/report /logs
|
20260907-014716-computing-math-8018f2/environment/public_data/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Public Task Inputs
|
| 2 |
+
|
| 3 |
+
Files in this directory are copied into the workspace:
|
| 4 |
+
|
| 5 |
+
- `input/` -> `/workspace/input/`
|
| 6 |
+
- `software/` -> `/workspace/software/`
|
| 7 |
+
- `task_card.json` -> `/workspace/task_card.json`
|
| 8 |
+
- `main.py` -> `/workspace/main.py`
|
| 9 |
+
|
| 10 |
+
Hidden reference data and evaluator files are not present in the agent workspace.
|
| 11 |
+
Final deliverables must be written under `/workspace/output/`.
|
20260907-014716-computing-math-8018f2/environment/public_data/input/README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This directory contains the public staged input for this task.
|
| 2 |
+
input/analysis_spec.json is the authoritative public contract for input columns, grouping/filtering rules, required output files, and output schemas.
|
| 3 |
+
Primary data file: input/tutorial_text_windows.csv.
|
| 4 |
+
Workflow kind: software_tutorial_doc_audit.
|
| 5 |
+
Required output files: output/summary.json, output/section_outline.csv, output/keyword_inventory.csv, output/code_block_inventory.csv.
|
| 6 |
+
Solve the task from the staged local files only; do not fetch fresh remote data during solve time.
|
20260907-014716-computing-math-8018f2/environment/public_data/input/analysis_spec.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"input_file": "tutorial_text_windows.csv",
|
| 3 |
+
"source_file": "tutorial_source.html",
|
| 4 |
+
"workflow_kind": "software_tutorial_doc_audit",
|
| 5 |
+
"software_name": "Docker",
|
| 6 |
+
"tutorial_url": "https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md",
|
| 7 |
+
"source_urls": [
|
| 8 |
+
"https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md"
|
| 9 |
+
],
|
| 10 |
+
"window_rule": {
|
| 11 |
+
"cleaning": "Strip HTML/script/style tags, decode entities, collapse whitespace, and preserve document text order.",
|
| 12 |
+
"window_size_words": 40,
|
| 13 |
+
"stride_words": 20,
|
| 14 |
+
"minimum_windows": 100
|
| 15 |
+
},
|
| 16 |
+
"heading_rule": "Extract h1-h6 headings from HTML; if no HTML headings are present, use Markdown # headings.",
|
| 17 |
+
"keyword_rule": "Count case-insensitive occurrences of required_terms and code_terms in the cleaned tutorial text.",
|
| 18 |
+
"required_terms": [
|
| 19 |
+
"Docker",
|
| 20 |
+
"container",
|
| 21 |
+
"image",
|
| 22 |
+
"Dockerfile",
|
| 23 |
+
"volume",
|
| 24 |
+
"network"
|
| 25 |
+
],
|
| 26 |
+
"code_terms": [
|
| 27 |
+
"docker run",
|
| 28 |
+
"docker build",
|
| 29 |
+
"docker compose",
|
| 30 |
+
"docker pull",
|
| 31 |
+
"docker"
|
| 32 |
+
],
|
| 33 |
+
"executables": [
|
| 34 |
+
"docker",
|
| 35 |
+
"docker compose"
|
| 36 |
+
],
|
| 37 |
+
"required_system_packages": [
|
| 38 |
+
"docker.io",
|
| 39 |
+
"docker-compose-plugin"
|
| 40 |
+
],
|
| 41 |
+
"required_outputs": [
|
| 42 |
+
{
|
| 43 |
+
"path": "summary.json",
|
| 44 |
+
"type": "json"
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"path": "section_outline.csv",
|
| 48 |
+
"type": "csv"
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"path": "keyword_inventory.csv",
|
| 52 |
+
"type": "csv"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"path": "code_block_inventory.csv",
|
| 56 |
+
"type": "csv"
|
| 57 |
+
}
|
| 58 |
+
],
|
| 59 |
+
"output_schemas": {
|
| 60 |
+
"summary.json": {
|
| 61 |
+
"software_name": "string",
|
| 62 |
+
"source_file": "string",
|
| 63 |
+
"window_count": "integer",
|
| 64 |
+
"heading_count": "integer",
|
| 65 |
+
"code_block_count": "integer",
|
| 66 |
+
"keyword_total": "integer",
|
| 67 |
+
"unique_required_terms_found": "integer",
|
| 68 |
+
"top_keyword": "string|null",
|
| 69 |
+
"source_character_count": "integer"
|
| 70 |
+
},
|
| 71 |
+
"section_outline.csv": [
|
| 72 |
+
"rank",
|
| 73 |
+
"heading_level",
|
| 74 |
+
"heading_text",
|
| 75 |
+
"slug"
|
| 76 |
+
],
|
| 77 |
+
"keyword_inventory.csv": [
|
| 78 |
+
"term",
|
| 79 |
+
"category",
|
| 80 |
+
"count",
|
| 81 |
+
"first_window",
|
| 82 |
+
"appears_in_code"
|
| 83 |
+
],
|
| 84 |
+
"code_block_inventory.csv": [
|
| 85 |
+
"block_index",
|
| 86 |
+
"line_count",
|
| 87 |
+
"char_count",
|
| 88 |
+
"contains_code_term",
|
| 89 |
+
"first_line"
|
| 90 |
+
]
|
| 91 |
+
},
|
| 92 |
+
"notes": "Audit the staged offline official tutorial corpus. Do not fetch fresh documentation. All counts must be derived from the staged source file and tutorial_text_windows.csv."
|
| 93 |
+
}
|
20260907-014716-computing-math-8018f2/environment/public_data/input/source_context_windows.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
20260907-014716-computing-math-8018f2/environment/public_data/input/tutorial_metadata.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"software_name": "Docker",
|
| 3 |
+
"tutorial_url": "https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md",
|
| 4 |
+
"source_urls": [
|
| 5 |
+
"https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md"
|
| 6 |
+
],
|
| 7 |
+
"source_file": "tutorial_source.html",
|
| 8 |
+
"window_file": "tutorial_text_windows.csv",
|
| 9 |
+
"window_rule": {
|
| 10 |
+
"cleaning": "Strip HTML/script/style tags, decode entities, collapse whitespace, and preserve document text order.",
|
| 11 |
+
"window_size_words": 40,
|
| 12 |
+
"stride_words": 20,
|
| 13 |
+
"minimum_windows": 100
|
| 14 |
+
},
|
| 15 |
+
"required_terms": [
|
| 16 |
+
"Docker",
|
| 17 |
+
"container",
|
| 18 |
+
"image",
|
| 19 |
+
"Dockerfile",
|
| 20 |
+
"volume",
|
| 21 |
+
"network"
|
| 22 |
+
],
|
| 23 |
+
"code_terms": [
|
| 24 |
+
"docker run",
|
| 25 |
+
"docker build",
|
| 26 |
+
"docker compose",
|
| 27 |
+
"docker pull",
|
| 28 |
+
"docker"
|
| 29 |
+
],
|
| 30 |
+
"note": "Provenance and public extraction rules only; scored aggregate values are intentionally not stored here."
|
| 31 |
+
}
|
20260907-014716-computing-math-8018f2/environment/public_data/input/tutorial_source.html
ADDED
|
@@ -0,0 +1,686 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Source 1: bridge.md
|
| 2 |
+
|
| 3 |
+
- URL: https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md
|
| 4 |
+
- SHA256: f5d1811100422cd6108a833b6485b7745ce7939b51f5826099242dde00b2f3b5
|
| 5 |
+
- Bytes: 27467
|
| 6 |
+
|
| 7 |
+
```markdown
|
| 8 |
+
---
|
| 9 |
+
title: Bridge network driver
|
| 10 |
+
description: All about using user-defined bridge networks and the default bridge
|
| 11 |
+
keywords: network, bridge, user-defined, standalone
|
| 12 |
+
aliases:
|
| 13 |
+
- /config/containers/bridges/
|
| 14 |
+
- /engine/userguide/networking/default_network/build-bridges/
|
| 15 |
+
- /engine/userguide/networking/default_network/custom-docker0/
|
| 16 |
+
- /engine/userguide/networking/work-with-networks/
|
| 17 |
+
- /network/bridge/
|
| 18 |
+
- /network/drivers/bridge/
|
| 19 |
+
- /engine/network/tutorials/standalone/
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
A Docker bridge network has an IPv4 subnet and, optionally, an IPv6 subnet.
|
| 23 |
+
Each container connected to the bridge network has a network interface with
|
| 24 |
+
addresses in the network's subnets. By default, it:
|
| 25 |
+
|
| 26 |
+
- Allows unrestricted network access to containers in the network from
|
| 27 |
+
the host, and from other containers connected to the same bridge network.
|
| 28 |
+
- Blocks access from containers in other networks and from outside the
|
| 29 |
+
Docker host.
|
| 30 |
+
- Uses masquerading to give containers external network access. Devices on
|
| 31 |
+
the host's external networks only see the IP address of the Docker host.
|
| 32 |
+
- Supports port publishing, where network traffic is forwarded between
|
| 33 |
+
container ports and ports on host IP addresses. The published ports
|
| 34 |
+
can be accessed from outside the Docker host, on its IP addresses.
|
| 35 |
+
|
| 36 |
+
In terms of Docker, a bridge network uses a software bridge which lets
|
| 37 |
+
containers connected to the same bridge network communicate, while providing
|
| 38 |
+
isolation from containers that aren't connected to that bridge network. By
|
| 39 |
+
default, the Docker bridge driver automatically installs rules in the host
|
| 40 |
+
machine so that containers connected to different bridge networks can only
|
| 41 |
+
communicate with each other using published ports.
|
| 42 |
+
|
| 43 |
+
Bridge networks apply to containers running on the same Docker daemon host.
|
| 44 |
+
For communication among containers running on different Docker daemon hosts, you
|
| 45 |
+
can either manage routing at the OS level, or you can use an
|
| 46 |
+
[overlay network](overlay.md).
|
| 47 |
+
|
| 48 |
+
When you start Docker, a [default bridge network](#use-the-default-bridge-network) (also
|
| 49 |
+
called `bridge`) is created automatically, and newly-started containers connect
|
| 50 |
+
to it unless otherwise specified. You can also create user-defined custom bridge
|
| 51 |
+
networks. **User-defined bridge networks are superior to the default `bridge`
|
| 52 |
+
network.**
|
| 53 |
+
|
| 54 |
+
## Differences between user-defined bridges and the default bridge
|
| 55 |
+
|
| 56 |
+
- **User-defined bridges provide automatic DNS resolution between containers**.
|
| 57 |
+
|
| 58 |
+
Containers on the default bridge network can only access each other by IP
|
| 59 |
+
addresses, unless you use the [`--link` option](../links.md), which is
|
| 60 |
+
considered legacy. On a user-defined bridge network, containers can resolve
|
| 61 |
+
each other by name or alias.
|
| 62 |
+
|
| 63 |
+
Imagine an application with a web front-end and a database back-end. If you call
|
| 64 |
+
your containers `web` and `db`, the web container can connect to the db container
|
| 65 |
+
at `db`, no matter which Docker host the application stack is running on.
|
| 66 |
+
|
| 67 |
+
If you run the same application stack on the default bridge network, you need
|
| 68 |
+
to manually create links between the containers (using the legacy `--link`
|
| 69 |
+
flag). These links need to be created in both directions, so you can see this
|
| 70 |
+
gets complex with more than two containers which need to communicate.
|
| 71 |
+
Alternatively, you can manipulate the `/etc/hosts` files within the containers,
|
| 72 |
+
but this creates problems that are difficult to debug.
|
| 73 |
+
|
| 74 |
+
- **User-defined bridges provide better isolation**.
|
| 75 |
+
|
| 76 |
+
All containers without a `--network` specified, are attached to the default bridge network. This can be a risk, as unrelated stacks/services/containers are then able to communicate.
|
| 77 |
+
|
| 78 |
+
Using a user-defined network provides a scoped network in which only containers attached to that network are able to communicate.
|
| 79 |
+
|
| 80 |
+
- **Containers can be attached and detached from user-defined networks on the fly**.
|
| 81 |
+
|
| 82 |
+
During a container's lifetime, you can connect or disconnect it from
|
| 83 |
+
user-defined networks on the fly. To remove a container from the default
|
| 84 |
+
bridge network, you need to stop the container and recreate it with different
|
| 85 |
+
network options.
|
| 86 |
+
|
| 87 |
+
- **Each user-defined network creates a configurable bridge**.
|
| 88 |
+
|
| 89 |
+
If your containers use the default bridge network, you can configure it, but
|
| 90 |
+
all the containers use the same settings, such as MTU and `iptables` rules.
|
| 91 |
+
In addition, configuring the default bridge network happens outside of Docker
|
| 92 |
+
itself, and requires a restart of Docker.
|
| 93 |
+
|
| 94 |
+
User-defined bridge networks are created and configured using
|
| 95 |
+
`docker network create`. If different groups of applications have different
|
| 96 |
+
network requirements, you can configure each user-defined bridge separately,
|
| 97 |
+
as you create it.
|
| 98 |
+
|
| 99 |
+
- **Linked containers on the default bridge network share environment variables**.
|
| 100 |
+
|
| 101 |
+
Originally, the only way to share environment variables between two containers
|
| 102 |
+
was to link them using the [`--link` flag](../links.md). This type of
|
| 103 |
+
variable sharing isn't possible with user-defined networks. However, there
|
| 104 |
+
are superior ways to share environment variables. A few ideas:
|
| 105 |
+
- Multiple containers can mount a file or directory containing the shared
|
| 106 |
+
information, using a Docker volume.
|
| 107 |
+
|
| 108 |
+
- Multiple containers can be started together using `docker-compose` and the
|
| 109 |
+
compose file can define the shared variables.
|
| 110 |
+
|
| 111 |
+
- You can use swarm services instead of standalone containers, and take
|
| 112 |
+
advantage of shared [secrets](/manuals/engine/swarm/secrets.md) and
|
| 113 |
+
[configs](/manuals/engine/swarm/configs.md).
|
| 114 |
+
|
| 115 |
+
Containers connected to the same user-defined bridge network effectively expose all ports
|
| 116 |
+
to each other. For a port to be accessible to containers or non-Docker hosts on
|
| 117 |
+
different networks, that port must be _published_ using the `-p` or `--publish`
|
| 118 |
+
flag.
|
| 119 |
+
|
| 120 |
+
## Options
|
| 121 |
+
|
| 122 |
+
The following table describes the driver-specific options that you can pass to
|
| 123 |
+
`--opt` when creating a custom network using the `bridge` driver.
|
| 124 |
+
|
| 125 |
+
| Option | Default | Description |
|
| 126 |
+
| ----------------------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
| 127 |
+
| `com.docker.network.bridge.name` | | Interface name to use when creating the Linux bridge. |
|
| 128 |
+
| `com.docker.network.bridge.enable_ip_masquerade` | `true` | Enable IP masquerading. |
|
| 129 |
+
| `com.docker.network.host_ipv4`<br/>`com.docker.network.host_ipv6` | | Address to use for source NAT. See [Port publishing](../port-publishing.md#masquerade-or-snat-for-outgoing-packets). |
|
| 130 |
+
| `com.docker.network.bridge.gateway_mode_ipv4`<br/>`com.docker.network.bridge.gateway_mode_ipv6` | `nat` | Control external connectivity. See [Port publishing](../port-publishing.md#gateway-modes). |
|
| 131 |
+
| `com.docker.network.bridge.enable_icc` | `true` | Enable or Disable inter-container connectivity. |
|
| 132 |
+
| `com.docker.network.bridge.host_binding_ipv4` | all IPv4 and IPv6 addresses | Default IP when binding container ports. |
|
| 133 |
+
| `com.docker.network.driver.mtu` | `0` (no limit) | Set the containers network Maximum Transmission Unit (MTU). |
|
| 134 |
+
| `com.docker.network.container_iface_prefix` | `eth` | Set a custom prefix for container interfaces. |
|
| 135 |
+
| `com.docker.network.bridge.inhibit_ipv4` | `false` | Prevent Docker from [assigning an IP address](#skip-bridge-ip-address-configuration) to the bridge. |
|
| 136 |
+
|
| 137 |
+
Some of these options are also available as flags to the `dockerd` CLI, and you
|
| 138 |
+
can use them to configure the default `docker0` bridge when starting the Docker
|
| 139 |
+
daemon. The following table shows which options have equivalent flags in the
|
| 140 |
+
`dockerd` CLI.
|
| 141 |
+
|
| 142 |
+
| Option | Flag |
|
| 143 |
+
| ------------------------------------------------ | ----------- |
|
| 144 |
+
| `com.docker.network.bridge.name` | - |
|
| 145 |
+
| `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq` |
|
| 146 |
+
| `com.docker.network.bridge.enable_icc` | `--icc` |
|
| 147 |
+
| `com.docker.network.bridge.host_binding_ipv4` | `--ip` |
|
| 148 |
+
| `com.docker.network.driver.mtu` | `--mtu` |
|
| 149 |
+
| `com.docker.network.container_iface_prefix` | - |
|
| 150 |
+
|
| 151 |
+
The Docker daemon supports a `--bridge` flag, which you can use to define
|
| 152 |
+
your own `docker0` bridge. Use this option if you want to run multiple daemon
|
| 153 |
+
instances on the same host. For details, see
|
| 154 |
+
[Run multiple daemons](/reference/cli/dockerd.md#run-multiple-daemons).
|
| 155 |
+
|
| 156 |
+
### Default host binding address
|
| 157 |
+
|
| 158 |
+
When no host address is given in port publishing options like `-p 80`
|
| 159 |
+
or `-p 8080:80`, the default is to make the container's port 80 available on all
|
| 160 |
+
host addresses, IPv4 and IPv6.
|
| 161 |
+
|
| 162 |
+
The bridge network driver option `com.docker.network.bridge.host_binding_ipv4`
|
| 163 |
+
can be used to modify the default address for published ports.
|
| 164 |
+
|
| 165 |
+
Despite the option's name, it is possible to specify an IPv6 address.
|
| 166 |
+
|
| 167 |
+
When the default binding address is an address assigned to a specific interface,
|
| 168 |
+
the container's port will only be accessible via that address.
|
| 169 |
+
|
| 170 |
+
Setting the default binding address to `::` means published ports will only be
|
| 171 |
+
available on the host's IPv6 addresses. However, setting it to `0.0.0.0` means it
|
| 172 |
+
will be available on the host's IPv4 and IPv6 addresses.
|
| 173 |
+
|
| 174 |
+
To restrict a published port to IPv4 only, the address must be included in the
|
| 175 |
+
container's publishing options. For example, `-p 0.0.0.0:8080:80`.
|
| 176 |
+
|
| 177 |
+
## Manage a user-defined bridge
|
| 178 |
+
|
| 179 |
+
Use the `docker network create` command to create a user-defined bridge
|
| 180 |
+
network.
|
| 181 |
+
|
| 182 |
+
```console
|
| 183 |
+
$ docker network create my-net
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
You can specify the subnet, the IP address range, the gateway, and other
|
| 187 |
+
options. See the
|
| 188 |
+
[docker network create](/reference/cli/docker/network/create/#specify-advanced-options)
|
| 189 |
+
reference or the output of `docker network create --help` for details.
|
| 190 |
+
|
| 191 |
+
Use the `docker network rm` command to remove a user-defined bridge
|
| 192 |
+
network. If containers are currently connected to the network,
|
| 193 |
+
[disconnect them](#disconnect-a-container-from-a-user-defined-bridge)
|
| 194 |
+
first.
|
| 195 |
+
|
| 196 |
+
```console
|
| 197 |
+
$ docker network rm my-net
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
> **What's really happening?**
|
| 201 |
+
>
|
| 202 |
+
> When you create or remove a user-defined bridge or connect or disconnect a
|
| 203 |
+
> container from a user-defined bridge, Docker uses tools specific to the
|
| 204 |
+
> operating system to manage the underlying network infrastructure (such as adding
|
| 205 |
+
> or removing bridge devices or configuring `iptables` rules on Linux). These
|
| 206 |
+
> details should be considered implementation details. Let Docker manage your
|
| 207 |
+
> user-defined networks for you.
|
| 208 |
+
|
| 209 |
+
## Connect a container to a user-defined bridge
|
| 210 |
+
|
| 211 |
+
When you create a new container, you can specify one or more `--network` flags.
|
| 212 |
+
This example connects an Nginx container to the `my-net` network. It also
|
| 213 |
+
publishes port 80 in the container to port 8080 on the Docker host, so external
|
| 214 |
+
clients can access that port. Any other container connected to the `my-net`
|
| 215 |
+
network has access to all ports on the `my-nginx` container, and vice versa.
|
| 216 |
+
|
| 217 |
+
```console
|
| 218 |
+
$ docker create --name my-nginx \
|
| 219 |
+
--network my-net \
|
| 220 |
+
--publish 8080:80 \
|
| 221 |
+
nginx:latest
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
To connect a **running** container to an existing user-defined bridge, use the
|
| 225 |
+
`docker network connect` command. The following command connects an already-running
|
| 226 |
+
`my-nginx` container to an already-existing `my-net` network:
|
| 227 |
+
|
| 228 |
+
```console
|
| 229 |
+
$ docker network connect my-net my-nginx
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
## Disconnect a container from a user-defined bridge
|
| 233 |
+
|
| 234 |
+
To disconnect a running container from a user-defined bridge, use the
|
| 235 |
+
`docker network disconnect` command. The following command disconnects
|
| 236 |
+
the `my-nginx` container from the `my-net` network.
|
| 237 |
+
|
| 238 |
+
```console
|
| 239 |
+
$ docker network disconnect my-net my-nginx
|
| 240 |
+
```
|
| 241 |
+
|
| 242 |
+
## Use IPv6 in a user-defined bridge network
|
| 243 |
+
|
| 244 |
+
When you create your network, you can specify the `--ipv6` flag to enable IPv6.
|
| 245 |
+
|
| 246 |
+
```console
|
| 247 |
+
$ docker network create --ipv6 --subnet 2001:db8:1234::/64 my-net
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
If you do not provide a `--subnet` option, a Unique Local Address (ULA) prefix
|
| 251 |
+
will be chosen automatically.
|
| 252 |
+
|
| 253 |
+
## IPv6-only bridge networks
|
| 254 |
+
|
| 255 |
+
To skip IPv4 address configuration on the bridge and in its containers, create
|
| 256 |
+
the network with option `--ipv4=false`, and enable IPv6 using `--ipv6`.
|
| 257 |
+
|
| 258 |
+
```console
|
| 259 |
+
$ docker network create --ipv6 --ipv4=false v6net
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
IPv4 address configuration cannot be disabled in the default bridge network.
|
| 263 |
+
|
| 264 |
+
## Use the default bridge network
|
| 265 |
+
|
| 266 |
+
The default `bridge` network is considered a legacy detail of Docker and is not
|
| 267 |
+
recommended for production use. Configuring it is a manual operation, and it has
|
| 268 |
+
[technical shortcomings](#differences-between-user-defined-bridges-and-the-default-bridge).
|
| 269 |
+
|
| 270 |
+
### Connect a container to the default bridge network
|
| 271 |
+
|
| 272 |
+
If you do not specify a network using the `--network` flag, and you do specify a
|
| 273 |
+
network driver, your container is connected to the default `bridge` network by
|
| 274 |
+
default. Containers connected to the default `bridge` network can communicate,
|
| 275 |
+
but only by IP address, unless they're linked using the
|
| 276 |
+
[legacy `--link` flag](../links.md).
|
| 277 |
+
|
| 278 |
+
### Configure the default bridge network
|
| 279 |
+
|
| 280 |
+
To configure the default `bridge` network, you specify options in `daemon.json`.
|
| 281 |
+
Here is an example `daemon.json` with several options specified. Only specify
|
| 282 |
+
the settings you need to customize.
|
| 283 |
+
|
| 284 |
+
```json
|
| 285 |
+
{
|
| 286 |
+
"bip": "192.168.1.1/24",
|
| 287 |
+
"fixed-cidr": "192.168.1.0/25",
|
| 288 |
+
"mtu": 1500,
|
| 289 |
+
"default-gateway": "192.168.1.254",
|
| 290 |
+
"dns": ["10.20.1.2", "10.20.1.3"]
|
| 291 |
+
}
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
In this example:
|
| 295 |
+
|
| 296 |
+
- The bridge's address is "192.168.1.1/24" (from `bip`).
|
| 297 |
+
- The bridge network's subnet is "192.168.1.0/24" (from `bip`).
|
| 298 |
+
- Container addresses will be allocated from "192.168.1.0/25" (from `fixed-cidr`).
|
| 299 |
+
|
| 300 |
+
### Use IPv6 with the default bridge network
|
| 301 |
+
|
| 302 |
+
IPv6 can be enabled for the default bridge using the following options in
|
| 303 |
+
`daemon.json`, or their command line equivalents.
|
| 304 |
+
|
| 305 |
+
These three options only affect the default bridge, they are not used by
|
| 306 |
+
user-defined networks. The addresses in below are examples from the
|
| 307 |
+
IPv6 documentation range.
|
| 308 |
+
|
| 309 |
+
- Option `ipv6` is required.
|
| 310 |
+
- Option `bip6` is optional, it specifies the address of the default bridge, which
|
| 311 |
+
will be used as the default gateway by containers. It also specifies the subnet
|
| 312 |
+
for the bridge network.
|
| 313 |
+
- Option `fixed-cidr-v6` is optional, it specifies the address range Docker may
|
| 314 |
+
automatically allocate to containers.
|
| 315 |
+
- The prefix should normally be `/64` or shorter.
|
| 316 |
+
- For experimentation on a local network, it is better to use a Unique Local
|
| 317 |
+
Address (ULA) prefix (matching `fd00::/8`) than a Link Local prefix (matching
|
| 318 |
+
`fe80::/10`).
|
| 319 |
+
- Option `default-gateway-v6` is optional. If unspecified, the default is the first
|
| 320 |
+
address in the `fixed-cidr-v6` subnet.
|
| 321 |
+
|
| 322 |
+
```json
|
| 323 |
+
{
|
| 324 |
+
"ipv6": true,
|
| 325 |
+
"bip6": "2001:db8::1111/64",
|
| 326 |
+
"fixed-cidr-v6": "2001:db8::/64",
|
| 327 |
+
"default-gateway-v6": "2001:db8:abcd::89"
|
| 328 |
+
}
|
| 329 |
+
```
|
| 330 |
+
|
| 331 |
+
If no `bip6` is specified, `fixed-cidr-v6` defines the subnet for the bridge
|
| 332 |
+
network. If no `bip6` or `fixed-cidr-v6` is specified, a ULA prefix will be
|
| 333 |
+
chosen.
|
| 334 |
+
|
| 335 |
+
Restart Docker for changes to take effect.
|
| 336 |
+
|
| 337 |
+
## Connection limit for bridge networks
|
| 338 |
+
|
| 339 |
+
Due to limitations set by the Linux kernel, bridge networks become unstable and
|
| 340 |
+
inter-container communications may break when 1000 containers or more connect
|
| 341 |
+
to a single network.
|
| 342 |
+
|
| 343 |
+
For more information about this limitation, see
|
| 344 |
+
[moby/moby#44973](https://github.com/moby/moby/issues/44973#issuecomment-1543747718).
|
| 345 |
+
|
| 346 |
+
## Skip Bridge IP address configuration
|
| 347 |
+
|
| 348 |
+
The bridge is normally assigned the network's `--gateway` address, which is
|
| 349 |
+
used as the default route from the bridge network to other networks.
|
| 350 |
+
|
| 351 |
+
The `com.docker.network.bridge.inhibit_ipv4` option lets you create a network
|
| 352 |
+
without the IPv4 gateway address being assigned to the bridge. This is useful
|
| 353 |
+
if you want to configure the gateway IP address for the bridge manually. For
|
| 354 |
+
instance if you add a physical interface to your bridge, and need it to have
|
| 355 |
+
the gateway address.
|
| 356 |
+
|
| 357 |
+
With this configuration, north-south traffic (to and from the bridge network)
|
| 358 |
+
won't work unless you've manually configured the gateway address on the bridge,
|
| 359 |
+
or a device attached to it.
|
| 360 |
+
|
| 361 |
+
This option can only be used with user-defined bridge networks.
|
| 362 |
+
|
| 363 |
+
## Usage examples
|
| 364 |
+
|
| 365 |
+
This section provides hands-on examples for working with bridge networks.
|
| 366 |
+
|
| 367 |
+
### Use the default bridge network
|
| 368 |
+
|
| 369 |
+
This example shows how the default `bridge` network works. You start two
|
| 370 |
+
`alpine` containers on the default bridge and test how they communicate.
|
| 371 |
+
|
| 372 |
+
> [!NOTE]
|
| 373 |
+
> The default `bridge` network is not recommended for production. Use
|
| 374 |
+
> user-defined bridge networks instead.
|
| 375 |
+
|
| 376 |
+
1. List current networks:
|
| 377 |
+
|
| 378 |
+
```console
|
| 379 |
+
$ docker network ls
|
| 380 |
+
|
| 381 |
+
NETWORK ID NAME DRIVER SCOPE
|
| 382 |
+
17e324f45964 bridge bridge local
|
| 383 |
+
6ed54d316334 host host local
|
| 384 |
+
7092879f2cc8 none null local
|
| 385 |
+
```
|
| 386 |
+
|
| 387 |
+
The default `bridge` network is listed, along with `host` and `none`.
|
| 388 |
+
|
| 389 |
+
2. Start two `alpine` containers running `ash`. The `-dit` flags mean detached,
|
| 390 |
+
interactive, and with a TTY. Since you haven't specified a `--network` flag,
|
| 391 |
+
the containers connect to the default `bridge` network.
|
| 392 |
+
|
| 393 |
+
```console
|
| 394 |
+
$ docker run -dit --name alpine1 alpine ash
|
| 395 |
+
$ docker run -dit --name alpine2 alpine ash
|
| 396 |
+
```
|
| 397 |
+
|
| 398 |
+
Verify both containers are running:
|
| 399 |
+
|
| 400 |
+
```console
|
| 401 |
+
$ docker container ls
|
| 402 |
+
|
| 403 |
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
| 404 |
+
602dbf1edc81 alpine "ash" 4 seconds ago Up 3 seconds alpine2
|
| 405 |
+
da33b7aa74b0 alpine "ash" 17 seconds ago Up 16 seconds alpine1
|
| 406 |
+
```
|
| 407 |
+
|
| 408 |
+
3. Inspect the `bridge` network to see connected containers:
|
| 409 |
+
|
| 410 |
+
```console
|
| 411 |
+
$ docker network inspect bridge
|
| 412 |
+
```
|
| 413 |
+
|
| 414 |
+
The output shows both containers connected, with their assigned IP addresses
|
| 415 |
+
(`172.17.0.2` for `alpine1` and `172.17.0.3` for `alpine2`).
|
| 416 |
+
|
| 417 |
+
4. Connect to `alpine1`:
|
| 418 |
+
|
| 419 |
+
```console
|
| 420 |
+
$ docker attach alpine1
|
| 421 |
+
|
| 422 |
+
/ #
|
| 423 |
+
```
|
| 424 |
+
|
| 425 |
+
Show the network interfaces for `alpine1` from within the container:
|
| 426 |
+
|
| 427 |
+
```console
|
| 428 |
+
# ip addr show
|
| 429 |
+
|
| 430 |
+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
|
| 431 |
+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
| 432 |
+
inet 127.0.0.1/8 scope host lo
|
| 433 |
+
valid_lft forever preferred_lft forever
|
| 434 |
+
inet6 ::1/128 scope host
|
| 435 |
+
valid_lft forever preferred_lft forever
|
| 436 |
+
27: eth0@if28: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
|
| 437 |
+
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
|
| 438 |
+
inet 172.17.0.2/16 scope global eth0
|
| 439 |
+
valid_lft forever preferred_lft forever
|
| 440 |
+
```
|
| 441 |
+
|
| 442 |
+
In this example, the `eth0` interface has the IP address `172.17.0.2`.
|
| 443 |
+
|
| 444 |
+
5. From within `alpine1`, verify you can connect to the internet:
|
| 445 |
+
|
| 446 |
+
```console
|
| 447 |
+
# ping -c 2 google.com
|
| 448 |
+
|
| 449 |
+
PING google.com (172.217.3.174): 56 data bytes
|
| 450 |
+
64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.841 ms
|
| 451 |
+
64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.897 ms
|
| 452 |
+
|
| 453 |
+
--- google.com ping statistics ---
|
| 454 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 455 |
+
round-trip min/avg/max = 9.841/9.869/9.897 ms
|
| 456 |
+
```
|
| 457 |
+
|
| 458 |
+
6. Ping the second container by its IP address:
|
| 459 |
+
|
| 460 |
+
```console
|
| 461 |
+
# ping -c 2 172.17.0.3
|
| 462 |
+
|
| 463 |
+
PING 172.17.0.3 (172.17.0.3): 56 data bytes
|
| 464 |
+
64 bytes from 172.17.0.3: seq=0 ttl=64 time=0.086 ms
|
| 465 |
+
64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.094 ms
|
| 466 |
+
|
| 467 |
+
--- 172.17.0.3 ping statistics ---
|
| 468 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 469 |
+
round-trip min/avg/max = 0.086/0.090/0.094 ms
|
| 470 |
+
```
|
| 471 |
+
|
| 472 |
+
This succeeds. Now try pinging by container name:
|
| 473 |
+
|
| 474 |
+
```console
|
| 475 |
+
# ping -c 2 alpine2
|
| 476 |
+
|
| 477 |
+
ping: bad address 'alpine2'
|
| 478 |
+
```
|
| 479 |
+
|
| 480 |
+
On the default bridge network, containers can't resolve each other by name.
|
| 481 |
+
|
| 482 |
+
7. Detach from `alpine1` without stopping it using `CTRL+p CTRL+q`.
|
| 483 |
+
|
| 484 |
+
8. Clean up: stop the containers and remove them.
|
| 485 |
+
|
| 486 |
+
```console
|
| 487 |
+
$ docker container stop alpine1 alpine2
|
| 488 |
+
$ docker container rm alpine1 alpine2
|
| 489 |
+
```
|
| 490 |
+
|
| 491 |
+
Stopped containers lose their IP addresses.
|
| 492 |
+
|
| 493 |
+
### Use user-defined bridge networks
|
| 494 |
+
|
| 495 |
+
This example shows how user-defined bridge networks provide better isolation
|
| 496 |
+
and automatic DNS resolution between containers.
|
| 497 |
+
|
| 498 |
+
1. Create the `alpine-net` network:
|
| 499 |
+
|
| 500 |
+
```console
|
| 501 |
+
$ docker network create --driver bridge alpine-net
|
| 502 |
+
```
|
| 503 |
+
|
| 504 |
+
2. List Docker's networks:
|
| 505 |
+
|
| 506 |
+
```console
|
| 507 |
+
$ docker network ls
|
| 508 |
+
|
| 509 |
+
NETWORK ID NAME DRIVER SCOPE
|
| 510 |
+
e9261a8c9a19 alpine-net bridge local
|
| 511 |
+
17e324f45964 bridge bridge local
|
| 512 |
+
6ed54d316334 host host local
|
| 513 |
+
7092879f2cc8 none null local
|
| 514 |
+
```
|
| 515 |
+
|
| 516 |
+
Inspect the `alpine-net` network:
|
| 517 |
+
|
| 518 |
+
```console
|
| 519 |
+
$ docker network inspect alpine-net
|
| 520 |
+
```
|
| 521 |
+
|
| 522 |
+
This shows the network's gateway (for example, `172.18.0.1`) and that no
|
| 523 |
+
containers are connected yet.
|
| 524 |
+
|
| 525 |
+
3. Create four containers. Three connect to `alpine-net`, and one connects to
|
| 526 |
+
the default `bridge`. Then connect one container to both networks:
|
| 527 |
+
|
| 528 |
+
```console
|
| 529 |
+
$ docker run -dit --name alpine1 --network alpine-net alpine ash
|
| 530 |
+
$ docker run -dit --name alpine2 --network alpine-net alpine ash
|
| 531 |
+
$ docker run -dit --name alpine3 alpine ash
|
| 532 |
+
$ docker run -dit --name alpine4 --network alpine-net alpine ash
|
| 533 |
+
$ docker network connect bridge alpine4
|
| 534 |
+
```
|
| 535 |
+
|
| 536 |
+
Verify all containers are running:
|
| 537 |
+
|
| 538 |
+
```console
|
| 539 |
+
$ docker container ls
|
| 540 |
+
|
| 541 |
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
| 542 |
+
156849ccd902 alpine "ash" 41 seconds ago Up 41 seconds alpine4
|
| 543 |
+
fa1340b8d83e alpine "ash" 51 seconds ago Up 51 seconds alpine3
|
| 544 |
+
a535d969081e alpine "ash" About a minute ago Up About a minute alpine2
|
| 545 |
+
0a02c449a6e9 alpine "ash" About a minute ago Up About a minute alpine1
|
| 546 |
+
```
|
| 547 |
+
|
| 548 |
+
4. Inspect both networks again to see which containers are connected:
|
| 549 |
+
|
| 550 |
+
```console
|
| 551 |
+
$ docker network inspect bridge
|
| 552 |
+
```
|
| 553 |
+
|
| 554 |
+
Containers `alpine3` and `alpine4` are connected to the `bridge` network.
|
| 555 |
+
|
| 556 |
+
```console
|
| 557 |
+
$ docker network inspect alpine-net
|
| 558 |
+
```
|
| 559 |
+
|
| 560 |
+
Containers `alpine1`, `alpine2`, and `alpine4` are connected to
|
| 561 |
+
`alpine-net`.
|
| 562 |
+
|
| 563 |
+
5. On user-defined networks, containers can resolve each other by name. Connect
|
| 564 |
+
to `alpine1` and test:
|
| 565 |
+
|
| 566 |
+
> [!NOTE]
|
| 567 |
+
> Automatic service discovery only resolves custom container names, not
|
| 568 |
+
> default automatically generated names.
|
| 569 |
+
|
| 570 |
+
```console
|
| 571 |
+
$ docker container attach alpine1
|
| 572 |
+
|
| 573 |
+
# ping -c 2 alpine2
|
| 574 |
+
|
| 575 |
+
PING alpine2 (172.18.0.3): 56 data bytes
|
| 576 |
+
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.085 ms
|
| 577 |
+
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.090 ms
|
| 578 |
+
|
| 579 |
+
--- alpine2 ping statistics ---
|
| 580 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 581 |
+
round-trip min/avg/max = 0.085/0.087/0.090 ms
|
| 582 |
+
|
| 583 |
+
# ping -c 2 alpine4
|
| 584 |
+
|
| 585 |
+
PING alpine4 (172.18.0.4): 56 data bytes
|
| 586 |
+
64 bytes from 172.18.0.4: seq=0 ttl=64 time=0.076 ms
|
| 587 |
+
64 bytes from 172.18.0.4: seq=1 ttl=64 time=0.091 ms
|
| 588 |
+
|
| 589 |
+
--- alpine4 ping statistics ---
|
| 590 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 591 |
+
round-trip min/avg/max = 0.076/0.083/0.091 ms
|
| 592 |
+
```
|
| 593 |
+
|
| 594 |
+
6. From `alpine1`, you can't connect to `alpine3` because it's on a different
|
| 595 |
+
network:
|
| 596 |
+
|
| 597 |
+
```console
|
| 598 |
+
# ping -c 2 alpine3
|
| 599 |
+
|
| 600 |
+
ping: bad address 'alpine3'
|
| 601 |
+
```
|
| 602 |
+
|
| 603 |
+
You also can't connect by IP address. If `alpine3`'s IP is `172.17.0.2`:
|
| 604 |
+
|
| 605 |
+
```console
|
| 606 |
+
# ping -c 2 172.17.0.2
|
| 607 |
+
|
| 608 |
+
PING 172.17.0.2 (172.17.0.2): 56 data bytes
|
| 609 |
+
|
| 610 |
+
--- 172.17.0.2 ping statistics ---
|
| 611 |
+
2 packets transmitted, 0 packets received, 100% packet loss
|
| 612 |
+
```
|
| 613 |
+
|
| 614 |
+
Detach from `alpine1` using `CTRL+p CTRL+q`.
|
| 615 |
+
|
| 616 |
+
7. Since `alpine4` is connected to both networks, it can reach all containers.
|
| 617 |
+
However, you need to use `alpine3`'s IP address:
|
| 618 |
+
|
| 619 |
+
```console
|
| 620 |
+
$ docker container attach alpine4
|
| 621 |
+
|
| 622 |
+
# ping -c 2 alpine1
|
| 623 |
+
|
| 624 |
+
PING alpine1 (172.18.0.2): 56 data bytes
|
| 625 |
+
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.074 ms
|
| 626 |
+
64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.082 ms
|
| 627 |
+
|
| 628 |
+
--- alpine1 ping statistics ---
|
| 629 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 630 |
+
round-trip min/avg/max = 0.074/0.078/0.082 ms
|
| 631 |
+
|
| 632 |
+
# ping -c 2 alpine2
|
| 633 |
+
|
| 634 |
+
PING alpine2 (172.18.0.3): 56 data bytes
|
| 635 |
+
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.075 ms
|
| 636 |
+
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.080 ms
|
| 637 |
+
|
| 638 |
+
--- alpine2 ping statistics ---
|
| 639 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 640 |
+
round-trip min/avg/max = 0.075/0.077/0.080 ms
|
| 641 |
+
|
| 642 |
+
# ping -c 2 alpine3
|
| 643 |
+
ping: bad address 'alpine3'
|
| 644 |
+
|
| 645 |
+
# ping -c 2 172.17.0.2
|
| 646 |
+
|
| 647 |
+
PING 172.17.0.2 (172.17.0.2): 56 data bytes
|
| 648 |
+
64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.089 ms
|
| 649 |
+
64 bytes from 172.17.0.2: seq=1 ttl=64 time=0.075 ms
|
| 650 |
+
|
| 651 |
+
--- 172.17.0.2 ping statistics ---
|
| 652 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 653 |
+
round-trip min/avg/max = 0.075/0.082/0.089 ms
|
| 654 |
+
```
|
| 655 |
+
|
| 656 |
+
8. Verify all containers can connect to the internet:
|
| 657 |
+
|
| 658 |
+
```console
|
| 659 |
+
# ping -c 2 google.com
|
| 660 |
+
|
| 661 |
+
PING google.com (172.217.3.174): 56 data bytes
|
| 662 |
+
64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.778 ms
|
| 663 |
+
64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.634 ms
|
| 664 |
+
|
| 665 |
+
--- google.com ping statistics ---
|
| 666 |
+
2 packets transmitted, 2 packets received, 0% packet loss
|
| 667 |
+
round-trip min/avg/max = 9.634/9.706/9.778 ms
|
| 668 |
+
```
|
| 669 |
+
|
| 670 |
+
Detach with `CTRL+p CTRL+q` and repeat for `alpine3` and `alpine1` if
|
| 671 |
+
desired.
|
| 672 |
+
|
| 673 |
+
9. Clean up:
|
| 674 |
+
|
| 675 |
+
```console
|
| 676 |
+
$ docker container stop alpine1 alpine2 alpine3 alpine4
|
| 677 |
+
$ docker container rm alpine1 alpine2 alpine3 alpine4
|
| 678 |
+
$ docker network rm alpine-net
|
| 679 |
+
```
|
| 680 |
+
|
| 681 |
+
## Next steps
|
| 682 |
+
|
| 683 |
+
- Learn about [networking from the container's point of view](../_index.md)
|
| 684 |
+
- Learn about [overlay networks](./overlay.md)
|
| 685 |
+
- Learn about [Macvlan networks](./macvlan.md)
|
| 686 |
+
```
|
20260907-014716-computing-math-8018f2/environment/public_data/input/tutorial_text_windows.csv
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
window_id,start_word,end_word,text,contains_code_term,matched_required_terms
|
| 2 |
+
1,0,40,"# Source 1: bridge.md - URL: https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md - SHA256: f5d1811100422cd6108a833b6485b7745ce7939b51f5826099242dde00b2f3b5 - Bytes: 27467 ```markdown --- title: Bridge network driver description: All about using user-defined bridge networks and the default bridge keywords: network, bridge, user-defined, standalone aliases: - /config/containers/bridges/ - /engine/userguide/networking/default_network/build-bridges/",true,Docker|container|network
|
| 3 |
+
2,20,60,"All about using user-defined bridge networks and the default bridge keywords: network, bridge, user-defined, standalone aliases: - /config/containers/bridges/ - /engine/userguide/networking/default_network/build-bridges/ - /engine/userguide/networking/default_network/custom-docker0/ - /engine/userguide/networking/work-with-networks/ - /network/bridge/ - /network/drivers/bridge/ - /engine/network/tutorials/standalone/ --- A Docker bridge network has an IPv4 subnet and,",true,Docker|container|network
|
| 4 |
+
3,40,80,"- /engine/userguide/networking/default_network/custom-docker0/ - /engine/userguide/networking/work-with-networks/ - /network/bridge/ - /network/drivers/bridge/ - /engine/network/tutorials/standalone/ --- A Docker bridge network has an IPv4 subnet and, optionally, an IPv6 subnet. Each container connected to the bridge network has a network interface with addresses in the network's",true,Docker|container|network
|
| 5 |
+
4,60,100,"optionally, an IPv6 subnet. Each container connected to the bridge network has a network interface with addresses in the network's subnets. By default, it: - Allows unrestricted network access to containers in the network from the host, and from other",false,container|network
|
| 6 |
+
5,80,120,"subnets. By default, it: - Allows unrestricted network access to containers in the network from the host, and from other containers connected to the same bridge network. - Blocks access from containers in other networks and from outside the Docker",true,Docker|container|network
|
| 7 |
+
6,100,140,containers connected to the same bridge network. - Blocks access from containers in other networks and from outside the Docker host. - Uses masquerading to give containers external network access. Devices on the host's external networks only see the IP,true,Docker|container|network
|
| 8 |
+
7,120,160,"host. - Uses masquerading to give containers external network access. Devices on the host's external networks only see the IP address of the Docker host. - Supports port publishing, where network traffic is forwarded between container ports and ports on",true,Docker|container|network
|
| 9 |
+
8,140,180,"address of the Docker host. - Supports port publishing, where network traffic is forwarded between container ports and ports on host IP addresses. The published ports can be accessed from outside the Docker host, on its IP addresses. In terms",true,Docker|container|network
|
| 10 |
+
9,160,200,"host IP addresses. The published ports can be accessed from outside the Docker host, on its IP addresses. In terms of Docker, a bridge network uses a software bridge which lets containers connected to the same bridge network communicate, while",true,Docker|container|network
|
| 11 |
+
10,180,220,"of Docker, a bridge network uses a software bridge which lets containers connected to the same bridge network communicate, while providing isolation from containers that aren't connected to that bridge network. By default, the Docker bridge driver automatically installs rules",true,Docker|container|network
|
| 12 |
+
11,200,240,"providing isolation from containers that aren't connected to that bridge network. By default, the Docker bridge driver automatically installs rules in the host machine so that containers connected to different bridge networks can only communicate with each other using published",true,Docker|container|network
|
| 13 |
+
12,220,260,in the host machine so that containers connected to different bridge networks can only communicate with each other using published ports. Bridge networks apply to containers running on the same Docker daemon host. For communication among containers running on different,true,Docker|container|network
|
| 14 |
+
13,240,280,"ports. Bridge networks apply to containers running on the same Docker daemon host. For communication among containers running on different Docker daemon hosts, you can either manage routing at the OS level, or you can use an [overlay network](overlay.md). When",true,Docker|container|network
|
| 15 |
+
14,260,300,"Docker daemon hosts, you can either manage routing at the OS level, or you can use an [overlay network](overlay.md). When you start Docker, a [default bridge network](#use-the-default-bridge-network) (also called `bridge`) is created automatically, and newly-started containers connect to it unless",true,Docker|container|network
|
| 16 |
+
15,280,320,"you start Docker, a [default bridge network](#use-the-default-bridge-network) (also called `bridge`) is created automatically, and newly-started containers connect to it unless otherwise specified. You can also create user-defined custom bridge networks. **User-defined bridge networks are superior to the default `bridge` network.**",true,Docker|container|network
|
| 17 |
+
16,300,340,otherwise specified. You can also create user-defined custom bridge networks. **User-defined bridge networks are superior to the default `bridge` network.** ## Differences between user-defined bridges and the default bridge - **User-defined bridges provide automatic DNS resolution between containers**. Containers on,false,container|network
|
| 18 |
+
17,320,360,"## Differences between user-defined bridges and the default bridge - **User-defined bridges provide automatic DNS resolution between containers**. Containers on the default bridge network can only access each other by IP addresses, unless you use the [`--link` option](../links.md), which is",false,container|network
|
| 19 |
+
18,340,380,"the default bridge network can only access each other by IP addresses, unless you use the [`--link` option](../links.md), which is considered legacy. On a user-defined bridge network, containers can resolve each other by name or alias. Imagine an application with",false,container|network
|
| 20 |
+
19,360,400,"considered legacy. On a user-defined bridge network, containers can resolve each other by name or alias. Imagine an application with a web front-end and a database back-end. If you call your containers `web` and `db`, the web container can connect",false,container|network
|
| 21 |
+
20,380,420,"a web front-end and a database back-end. If you call your containers `web` and `db`, the web container can connect to the db container at `db`, no matter which Docker host the application stack is running on. If you run",true,Docker|container
|
| 22 |
+
21,400,440,"to the db container at `db`, no matter which Docker host the application stack is running on. If you run the same application stack on the default bridge network, you need to manually create links between the containers (using the",true,Docker|container|network
|
| 23 |
+
22,420,460,"the same application stack on the default bridge network, you need to manually create links between the containers (using the legacy `--link` flag). These links need to be created in both directions, so you can see this gets complex with",false,container|network
|
| 24 |
+
23,440,480,"legacy `--link` flag). These links need to be created in both directions, so you can see this gets complex with more than two containers which need to communicate. Alternatively, you can manipulate the `/etc/hosts` files within the containers, but this",false,container
|
| 25 |
+
24,460,500,"more than two containers which need to communicate. Alternatively, you can manipulate the `/etc/hosts` files within the containers, but this creates problems that are difficult to debug. - **User-defined bridges provide better isolation**. All containers without a `--network` specified, are",false,container|network
|
| 26 |
+
25,480,520,"creates problems that are difficult to debug. - **User-defined bridges provide better isolation**. All containers without a `--network` specified, are attached to the default bridge network. This can be a risk, as unrelated stacks/services/containers are then able to communicate. Using",false,container|network
|
| 27 |
+
26,500,540,"attached to the default bridge network. This can be a risk, as unrelated stacks/services/containers are then able to communicate. Using a user-defined network provides a scoped network in which only containers attached to that network are able to communicate. -",false,container|network
|
| 28 |
+
27,520,560,"a user-defined network provides a scoped network in which only containers attached to that network are able to communicate. - **Containers can be attached and detached from user-defined networks on the fly**. During a container's lifetime, you can connect or",false,container|network
|
| 29 |
+
28,540,580,"**Containers can be attached and detached from user-defined networks on the fly**. During a container's lifetime, you can connect or disconnect it from user-defined networks on the fly. To remove a container from the default bridge network, you need to",false,container|network
|
| 30 |
+
29,560,600,"disconnect it from user-defined networks on the fly. To remove a container from the default bridge network, you need to stop the container and recreate it with different network options. - **Each user-defined network creates a configurable bridge**. If your",false,container|network
|
| 31 |
+
30,580,620,"stop the container and recreate it with different network options. - **Each user-defined network creates a configurable bridge**. If your containers use the default bridge network, you can configure it, but all the containers use the same settings, such as",false,container|network
|
| 32 |
+
31,600,640,"containers use the default bridge network, you can configure it, but all the containers use the same settings, such as MTU and `iptables` rules. In addition, configuring the default bridge network happens outside of Docker itself, and requires a restart",true,Docker|container|network
|
| 33 |
+
32,620,660,"MTU and `iptables` rules. In addition, configuring the default bridge network happens outside of Docker itself, and requires a restart of Docker. User-defined bridge networks are created and configured using `docker network create`. If different groups of applications have different",true,Docker|network
|
| 34 |
+
33,640,680,"of Docker. User-defined bridge networks are created and configured using `docker network create`. If different groups of applications have different network requirements, you can configure each user-defined bridge separately, as you create it. - **Linked containers on the default bridge",true,Docker|container|network
|
| 35 |
+
34,660,700,"network requirements, you can configure each user-defined bridge separately, as you create it. - **Linked containers on the default bridge network share environment variables**. Originally, the only way to share environment variables between two containers was to link them using",false,container|network
|
| 36 |
+
35,680,720,"network share environment variables**. Originally, the only way to share environment variables between two containers was to link them using the [`--link` flag](../links.md). This type of variable sharing isn't possible with user-defined networks. However, there are superior ways to share",false,container|network
|
| 37 |
+
36,700,740,"the [`--link` flag](../links.md). This type of variable sharing isn't possible with user-defined networks. However, there are superior ways to share environment variables. A few ideas: - Multiple containers can mount a file or directory containing the shared information, using a",false,container|network
|
| 38 |
+
37,720,760,"environment variables. A few ideas: - Multiple containers can mount a file or directory containing the shared information, using a Docker volume. - Multiple containers can be started together using `docker-compose` and the compose file can define the shared variables.",true,Docker|container|volume
|
| 39 |
+
38,740,780,"Docker volume. - Multiple containers can be started together using `docker-compose` and the compose file can define the shared variables. - You can use swarm services instead of standalone containers, and take advantage of shared [secrets](/manuals/engine/swarm/secrets.md) and [configs](/manuals/engine/swarm/configs.md). Containers connected",true,Docker|container|volume
|
| 40 |
+
39,760,800,"- You can use swarm services instead of standalone containers, and take advantage of shared [secrets](/manuals/engine/swarm/secrets.md) and [configs](/manuals/engine/swarm/configs.md). Containers connected to the same user-defined bridge network effectively expose all ports to each other. For a port to be accessible to",false,container|network
|
| 41 |
+
40,780,820,"to the same user-defined bridge network effectively expose all ports to each other. For a port to be accessible to containers or non-Docker hosts on different networks, that port must be _published_ using the `-p` or `--publish` flag. ## Options",true,Docker|container|network
|
| 42 |
+
41,800,840,"containers or non-Docker hosts on different networks, that port must be _published_ using the `-p` or `--publish` flag. ## Options The following table describes the driver-specific options that you can pass to `--opt` when creating a custom network using the",true,Docker|container|network
|
| 43 |
+
42,820,860,The following table describes the driver-specific options that you can pass to `--opt` when creating a custom network using the `bridge` driver. | Option | Default | Description | | ----------------------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------- | | `com.docker.network.bridge.name` | |,true,Docker|network
|
| 44 |
+
43,840,880,`bridge` driver. | Option | Default | Description | | ----------------------------------------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------- | | `com.docker.network.bridge.name` | | Interface name to use when creating the Linux bridge. | | `com.docker.network.bridge.enable_ip_masquerade` | `true` | Enable IP masquerading. | |,true,Docker|network
|
| 45 |
+
44,860,900,Interface name to use when creating the Linux bridge. | | `com.docker.network.bridge.enable_ip_masquerade` | `true` | Enable IP masquerading. | | `com.docker.network.host_ipv4` `com.docker.network.host_ipv6` | | Address to use for source NAT. See [Port publishing](../port-publishing.md#masquerade-or-snat-for-outgoing-packets). | | `com.docker.network.bridge.gateway_mode_ipv4` `com.docker.network.bridge.gateway_mode_ipv6` | `nat` |,true,Docker|network
|
| 46 |
+
45,880,920,`com.docker.network.host_ipv4` `com.docker.network.host_ipv6` | | Address to use for source NAT. See [Port publishing](../port-publishing.md#masquerade-or-snat-for-outgoing-packets). | | `com.docker.network.bridge.gateway_mode_ipv4` `com.docker.network.bridge.gateway_mode_ipv6` | `nat` | Control external connectivity. See [Port publishing](../port-publishing.md#gateway-modes). | | `com.docker.network.bridge.enable_icc` | `true` | Enable or Disable inter-container connectivity. | | `com.docker.network.bridge.host_binding_ipv4`,true,Docker|container|network
|
| 47 |
+
46,900,940,Control external connectivity. See [Port publishing](../port-publishing.md#gateway-modes). | | `com.docker.network.bridge.enable_icc` | `true` | Enable or Disable inter-container connectivity. | | `com.docker.network.bridge.host_binding_ipv4` | all IPv4 and IPv6 addresses | Default IP when binding container ports. | | `com.docker.network.driver.mtu` | `0` (no limit),true,Docker|container|network
|
| 48 |
+
47,920,960,| all IPv4 and IPv6 addresses | Default IP when binding container ports. | | `com.docker.network.driver.mtu` | `0` (no limit) | Set the containers network Maximum Transmission Unit (MTU). | | `com.docker.network.container_iface_prefix` | `eth` | Set a custom prefix for,true,Docker|container|network
|
| 49 |
+
48,940,980,| Set the containers network Maximum Transmission Unit (MTU). | | `com.docker.network.container_iface_prefix` | `eth` | Set a custom prefix for container interfaces. | | `com.docker.network.bridge.inhibit_ipv4` | `false` | Prevent Docker from [assigning an IP address](#skip-bridge-ip-address-configuration) to the bridge. | Some,true,Docker|container|network
|
| 50 |
+
49,960,1000,"container interfaces. | | `com.docker.network.bridge.inhibit_ipv4` | `false` | Prevent Docker from [assigning an IP address](#skip-bridge-ip-address-configuration) to the bridge. | Some of these options are also available as flags to the `dockerd` CLI, and you can use them to configure the",true,Docker|container|network
|
| 51 |
+
50,980,1020,"of these options are also available as flags to the `dockerd` CLI, and you can use them to configure the default `docker0` bridge when starting the Docker daemon. The following table shows which options have equivalent flags in the `dockerd`",true,Docker
|
| 52 |
+
51,1000,1040,default `docker0` bridge when starting the Docker daemon. The following table shows which options have equivalent flags in the `dockerd` CLI. | Option | Flag | | ------------------------------------------------ | ----------- | | `com.docker.network.bridge.name` | - | | `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq`,true,Docker|network
|
| 53 |
+
52,1020,1060,CLI. | Option | Flag | | ------------------------------------------------ | ----------- | | `com.docker.network.bridge.name` | - | | `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq` | | `com.docker.network.bridge.enable_icc` | `--icc` | | `com.docker.network.bridge.host_binding_ipv4` | `--ip` | | `com.docker.network.driver.mtu` | `--mtu` | | `com.docker.network.container_iface_prefix` | -,true,Docker|container|network
|
| 54 |
+
53,1040,1080,"| | `com.docker.network.bridge.enable_icc` | `--icc` | | `com.docker.network.bridge.host_binding_ipv4` | `--ip` | | `com.docker.network.driver.mtu` | `--mtu` | | `com.docker.network.container_iface_prefix` | - | The Docker daemon supports a `--bridge` flag, which you can use to define your own `docker0` bridge. Use this",true,Docker|container|network
|
| 55 |
+
54,1060,1100,"| The Docker daemon supports a `--bridge` flag, which you can use to define your own `docker0` bridge. Use this option if you want to run multiple daemon instances on the same host. For details, see [Run multiple daemons](/reference/cli/dockerd.md#run-multiple-daemons). ###",true,Docker
|
| 56 |
+
55,1080,1120,"option if you want to run multiple daemon instances on the same host. For details, see [Run multiple daemons](/reference/cli/dockerd.md#run-multiple-daemons). ### Default host binding address When no host address is given in port publishing options like `-p 80` or `-p 8080:80`,",true,Docker
|
| 57 |
+
56,1100,1140,"Default host binding address When no host address is given in port publishing options like `-p 80` or `-p 8080:80`, the default is to make the container's port 80 available on all host addresses, IPv4 and IPv6. The bridge network",false,container|network
|
| 58 |
+
57,1120,1160,"the default is to make the container's port 80 available on all host addresses, IPv4 and IPv6. The bridge network driver option `com.docker.network.bridge.host_binding_ipv4` can be used to modify the default address for published ports. Despite the option's name, it is",true,Docker|container|network
|
| 59 |
+
58,1140,1180,"driver option `com.docker.network.bridge.host_binding_ipv4` can be used to modify the default address for published ports. Despite the option's name, it is possible to specify an IPv6 address. When the default binding address is an address assigned to a specific interface, the",true,Docker|network
|
| 60 |
+
59,1160,1200,"possible to specify an IPv6 address. When the default binding address is an address assigned to a specific interface, the container's port will only be accessible via that address. Setting the default binding address to `::` means published ports will",false,container
|
| 61 |
+
60,1180,1220,"container's port will only be accessible via that address. Setting the default binding address to `::` means published ports will only be available on the host's IPv6 addresses. However, setting it to `0.0.0.0` means it will be available on the",false,container
|
| 62 |
+
61,1200,1240,"only be available on the host's IPv6 addresses. However, setting it to `0.0.0.0` means it will be available on the host's IPv4 and IPv6 addresses. To restrict a published port to IPv4 only, the address must be included in the",false,
|
| 63 |
+
62,1220,1260,"host's IPv4 and IPv6 addresses. To restrict a published port to IPv4 only, the address must be included in the container's publishing options. For example, `-p 0.0.0.0:8080:80`. ## Manage a user-defined bridge Use the `docker network create` command to create",true,Docker|container|network
|
| 64 |
+
63,1240,1280,"container's publishing options. For example, `-p 0.0.0.0:8080:80`. ## Manage a user-defined bridge Use the `docker network create` command to create a user-defined bridge network. ```console $ docker network create my-net ``` You can specify the subnet, the IP address range,",true,Docker|container|network
|
| 65 |
+
64,1260,1300,"a user-defined bridge network. ```console $ docker network create my-net ``` You can specify the subnet, the IP address range, the gateway, and other options. See the [docker network create](/reference/cli/docker/network/create/#specify-advanced-options) reference or the output of `docker network create --help` for",true,Docker|network
|
| 66 |
+
65,1280,1320,"the gateway, and other options. See the [docker network create](/reference/cli/docker/network/create/#specify-advanced-options) reference or the output of `docker network create --help` for details. Use the `docker network rm` command to remove a user-defined bridge network. If containers are currently connected to the",true,Docker|container|network
|
| 67 |
+
66,1300,1340,"details. Use the `docker network rm` command to remove a user-defined bridge network. If containers are currently connected to the network, [disconnect them](#disconnect-a-container-from-a-user-defined-bridge) first. ```console $ docker network rm my-net ``` > **What's really happening?** > > When you create",true,Docker|container|network
|
| 68 |
+
67,1320,1360,"network, [disconnect them](#disconnect-a-container-from-a-user-defined-bridge) first. ```console $ docker network rm my-net ``` > **What's really happening?** > > When you create or remove a user-defined bridge or connect or disconnect a > container from a user-defined bridge, Docker uses tools specific",true,Docker|container|network
|
| 69 |
+
68,1340,1380,"or remove a user-defined bridge or connect or disconnect a > container from a user-defined bridge, Docker uses tools specific to the > operating system to manage the underlying network infrastructure (such as adding > or removing bridge devices or",true,Docker|container|network
|
| 70 |
+
69,1360,1400,to the > operating system to manage the underlying network infrastructure (such as adding > or removing bridge devices or configuring `iptables` rules on Linux). These > details should be considered implementation details. Let Docker manage your > user-defined networks,true,Docker|network
|
| 71 |
+
70,1380,1420,"configuring `iptables` rules on Linux). These > details should be considered implementation details. Let Docker manage your > user-defined networks for you. ## Connect a container to a user-defined bridge When you create a new container, you can specify one",true,Docker|container|network
|
| 72 |
+
71,1400,1440,"for you. ## Connect a container to a user-defined bridge When you create a new container, you can specify one or more `--network` flags. This example connects an Nginx container to the `my-net` network. It also publishes port 80 in",false,container|network
|
| 73 |
+
72,1420,1460,"or more `--network` flags. This example connects an Nginx container to the `my-net` network. It also publishes port 80 in the container to port 8080 on the Docker host, so external clients can access that port. Any other container connected",true,Docker|container|network
|
| 74 |
+
73,1440,1480,"the container to port 8080 on the Docker host, so external clients can access that port. Any other container connected to the `my-net` network has access to all ports on the `my-nginx` container, and vice versa. ```console $ docker create",true,Docker|container|network
|
| 75 |
+
74,1460,1500,"to the `my-net` network has access to all ports on the `my-nginx` container, and vice versa. ```console $ docker create --name my-nginx \ --network my-net \ --publish 8080:80 \ nginx:latest ``` To connect a **running** container to an existing user-defined",true,Docker|container|network
|
| 76 |
+
75,1480,1520,"--name my-nginx \ --network my-net \ --publish 8080:80 \ nginx:latest ``` To connect a **running** container to an existing user-defined bridge, use the `docker network connect` command. The following command connects an already-running `my-nginx` container to an already-existing `my-net` network:",true,Docker|container|network
|
| 77 |
+
76,1500,1540,"bridge, use the `docker network connect` command. The following command connects an already-running `my-nginx` container to an already-existing `my-net` network: ```console $ docker network connect my-net my-nginx ``` ## Disconnect a container from a user-defined bridge To disconnect a running",true,Docker|container|network
|
| 78 |
+
77,1520,1560,"```console $ docker network connect my-net my-nginx ``` ## Disconnect a container from a user-defined bridge To disconnect a running container from a user-defined bridge, use the `docker network disconnect` command. The following command disconnects the `my-nginx` container from the",true,Docker|container|network
|
| 79 |
+
78,1540,1580,"container from a user-defined bridge, use the `docker network disconnect` command. The following command disconnects the `my-nginx` container from the `my-net` network. ```console $ docker network disconnect my-net my-nginx ``` ## Use IPv6 in a user-defined bridge network When you",true,Docker|container|network
|
| 80 |
+
79,1560,1600,"`my-net` network. ```console $ docker network disconnect my-net my-nginx ``` ## Use IPv6 in a user-defined bridge network When you create your network, you can specify the `--ipv6` flag to enable IPv6. ```console $ docker network create --ipv6 --subnet 2001:db8:1234::/64",true,Docker|network
|
| 81 |
+
80,1580,1620,"create your network, you can specify the `--ipv6` flag to enable IPv6. ```console $ docker network create --ipv6 --subnet 2001:db8:1234::/64 my-net ``` If you do not provide a `--subnet` option, a Unique Local Address (ULA) prefix will be chosen automatically.",true,Docker|network
|
| 82 |
+
81,1600,1640,"my-net ``` If you do not provide a `--subnet` option, a Unique Local Address (ULA) prefix will be chosen automatically. ## IPv6-only bridge networks To skip IPv4 address configuration on the bridge and in its containers, create the network with",false,container|network
|
| 83 |
+
82,1620,1660,"## IPv6-only bridge networks To skip IPv4 address configuration on the bridge and in its containers, create the network with option `--ipv4=false`, and enable IPv6 using `--ipv6`. ```console $ docker network create --ipv6 --ipv4=false v6net ``` IPv4 address configuration cannot",true,Docker|container|network
|
| 84 |
+
83,1640,1680,"option `--ipv4=false`, and enable IPv6 using `--ipv6`. ```console $ docker network create --ipv6 --ipv4=false v6net ``` IPv4 address configuration cannot be disabled in the default bridge network. ## Use the default bridge network The default `bridge` network is considered a",true,Docker|network
|
| 85 |
+
84,1660,1700,"be disabled in the default bridge network. ## Use the default bridge network The default `bridge` network is considered a legacy detail of Docker and is not recommended for production use. Configuring it is a manual operation, and it has",true,Docker|network
|
| 86 |
+
85,1680,1720,"legacy detail of Docker and is not recommended for production use. Configuring it is a manual operation, and it has [technical shortcomings](#differences-between-user-defined-bridges-and-the-default-bridge). ### Connect a container to the default bridge network If you do not specify a network using the",true,Docker|container|network
|
| 87 |
+
86,1700,1740,"[technical shortcomings](#differences-between-user-defined-bridges-and-the-default-bridge). ### Connect a container to the default bridge network If you do not specify a network using the `--network` flag, and you do specify a network driver, your container is connected to the default `bridge` network by default.",false,container|network
|
| 88 |
+
87,1720,1760,"`--network` flag, and you do specify a network driver, your container is connected to the default `bridge` network by default. Containers connected to the default `bridge` network can communicate, but only by IP address, unless they're linked using the [legacy",false,container|network
|
| 89 |
+
88,1740,1780,"Containers connected to the default `bridge` network can communicate, but only by IP address, unless they're linked using the [legacy `--link` flag](../links.md). ### Configure the default bridge network To configure the default `bridge` network, you specify options in `daemon.json`. Here",false,container|network
|
| 90 |
+
89,1760,1800,"`--link` flag](../links.md). ### Configure the default bridge network To configure the default `bridge` network, you specify options in `daemon.json`. Here is an example `daemon.json` with several options specified. Only specify the settings you need to customize. ```json { ""bip"": ""192.168.1.1/24"",",false,network
|
| 91 |
+
90,1780,1820,"is an example `daemon.json` with several options specified. Only specify the settings you need to customize. ```json { ""bip"": ""192.168.1.1/24"", ""fixed-cidr"": ""192.168.1.0/25"", ""mtu"": 1500, ""default-gateway"": ""192.168.1.254"", ""dns"": [""10.20.1.2"", ""10.20.1.3""] } ``` In this example: - The bridge's address is ""192.168.1.1/24""",false,
|
| 92 |
+
91,1800,1840,"""fixed-cidr"": ""192.168.1.0/25"", ""mtu"": 1500, ""default-gateway"": ""192.168.1.254"", ""dns"": [""10.20.1.2"", ""10.20.1.3""] } ``` In this example: - The bridge's address is ""192.168.1.1/24"" (from `bip`). - The bridge network's subnet is ""192.168.1.0/24"" (from `bip`). - Container addresses will be allocated from ""192.168.1.0/25"" (from",false,container|network
|
| 93 |
+
92,1820,1860,"(from `bip`). - The bridge network's subnet is ""192.168.1.0/24"" (from `bip`). - Container addresses will be allocated from ""192.168.1.0/25"" (from `fixed-cidr`). ### Use IPv6 with the default bridge network IPv6 can be enabled for the default bridge using the following",false,container|network
|
| 94 |
+
93,1840,1880,"`fixed-cidr`). ### Use IPv6 with the default bridge network IPv6 can be enabled for the default bridge using the following options in `daemon.json`, or their command line equivalents. These three options only affect the default bridge, they are not used",false,network
|
| 95 |
+
94,1860,1900,"options in `daemon.json`, or their command line equivalents. These three options only affect the default bridge, they are not used by user-defined networks. The addresses in below are examples from the IPv6 documentation range. - Option `ipv6` is required. -",false,network
|
| 96 |
+
95,1880,1920,"by user-defined networks. The addresses in below are examples from the IPv6 documentation range. - Option `ipv6` is required. - Option `bip6` is optional, it specifies the address of the default bridge, which will be used as the default gateway",false,network
|
| 97 |
+
96,1900,1940,"Option `bip6` is optional, it specifies the address of the default bridge, which will be used as the default gateway by containers. It also specifies the subnet for the bridge network. - Option `fixed-cidr-v6` is optional, it specifies the address",false,container|network
|
| 98 |
+
97,1920,1960,"by containers. It also specifies the subnet for the bridge network. - Option `fixed-cidr-v6` is optional, it specifies the address range Docker may automatically allocate to containers. - The prefix should normally be `/64` or shorter. - For experimentation on",true,Docker|container|network
|
| 99 |
+
98,1940,1980,"range Docker may automatically allocate to containers. - The prefix should normally be `/64` or shorter. - For experimentation on a local network, it is better to use a Unique Local Address (ULA) prefix (matching `fd00::/8`) than a Link Local",true,Docker|container|network
|
| 100 |
+
99,1960,2000,"a local network, it is better to use a Unique Local Address (ULA) prefix (matching `fd00::/8`) than a Link Local prefix (matching `fe80::/10`). - Option `default-gateway-v6` is optional. If unspecified, the default is the first address in the `fixed-cidr-v6` subnet.",false,network
|
| 101 |
+
100,1980,2020,"prefix (matching `fe80::/10`). - Option `default-gateway-v6` is optional. If unspecified, the default is the first address in the `fixed-cidr-v6` subnet. ```json { ""ipv6"": true, ""bip6"": ""2001:db8::1111/64"", ""fixed-cidr-v6"": ""2001:db8::/64"", ""default-gateway-v6"": ""2001:db8:abcd::89"" } ``` If no `bip6` is specified, `fixed-cidr-v6` defines the",false,
|
| 102 |
+
101,2000,2040,"```json { ""ipv6"": true, ""bip6"": ""2001:db8::1111/64"", ""fixed-cidr-v6"": ""2001:db8::/64"", ""default-gateway-v6"": ""2001:db8:abcd::89"" } ``` If no `bip6` is specified, `fixed-cidr-v6` defines the subnet for the bridge network. If no `bip6` or `fixed-cidr-v6` is specified, a ULA prefix will be chosen. Restart Docker",true,Docker|network
|
| 103 |
+
102,2020,2060,"subnet for the bridge network. If no `bip6` or `fixed-cidr-v6` is specified, a ULA prefix will be chosen. Restart Docker for changes to take effect. ## Connection limit for bridge networks Due to limitations set by the Linux kernel, bridge",true,Docker|network
|
| 104 |
+
103,2040,2080,"for changes to take effect. ## Connection limit for bridge networks Due to limitations set by the Linux kernel, bridge networks become unstable and inter-container communications may break when 1000 containers or more connect to a single network. For more",false,container|network
|
| 105 |
+
104,2060,2100,"networks become unstable and inter-container communications may break when 1000 containers or more connect to a single network. For more information about this limitation, see [moby/moby#44973](https://github.com/moby/moby/issues/44973#issuecomment-1543747718). ## Skip Bridge IP address configuration The bridge is normally assigned the network's `--gateway`",false,container|network
|
| 106 |
+
105,2080,2120,"information about this limitation, see [moby/moby#44973](https://github.com/moby/moby/issues/44973#issuecomment-1543747718). ## Skip Bridge IP address configuration The bridge is normally assigned the network's `--gateway` address, which is used as the default route from the bridge network to other networks. The `com.docker.network.bridge.inhibit_ipv4` option lets you",true,Docker|network
|
| 107 |
+
106,2100,2140,"address, which is used as the default route from the bridge network to other networks. The `com.docker.network.bridge.inhibit_ipv4` option lets you create a network without the IPv4 gateway address being assigned to the bridge. This is useful if you want to",true,Docker|network
|
| 108 |
+
107,2120,2160,"create a network without the IPv4 gateway address being assigned to the bridge. This is useful if you want to configure the gateway IP address for the bridge manually. For instance if you add a physical interface to your bridge,",false,network
|
| 109 |
+
108,2140,2180,"configure the gateway IP address for the bridge manually. For instance if you add a physical interface to your bridge, and need it to have the gateway address. With this configuration, north-south traffic (to and from the bridge network) won't",false,network
|
| 110 |
+
109,2160,2200,"and need it to have the gateway address. With this configuration, north-south traffic (to and from the bridge network) won't work unless you've manually configured the gateway address on the bridge, or a device attached to it. This option can",false,network
|
| 111 |
+
110,2180,2220,"work unless you've manually configured the gateway address on the bridge, or a device attached to it. This option can only be used with user-defined bridge networks. ## Usage examples This section provides hands-on examples for working with bridge networks.",false,network
|
| 112 |
+
111,2200,2240,only be used with user-defined bridge networks. ## Usage examples This section provides hands-on examples for working with bridge networks. ### Use the default bridge network This example shows how the default `bridge` network works. You start two `alpine` containers,false,container|network
|
| 113 |
+
112,2220,2260,### Use the default bridge network This example shows how the default `bridge` network works. You start two `alpine` containers on the default bridge and test how they communicate. > [!NOTE] > The default `bridge` network is not recommended for,false,container|network
|
| 114 |
+
113,2240,2280,on the default bridge and test how they communicate. > [!NOTE] > The default `bridge` network is not recommended for production. Use > user-defined bridge networks instead. 1. List current networks: ```console $ docker network ls NETWORK ID NAME DRIVER,true,Docker|network
|
| 115 |
+
114,2260,2300,"production. Use > user-defined bridge networks instead. 1. List current networks: ```console $ docker network ls NETWORK ID NAME DRIVER SCOPE 17e324f45964 bridge bridge local 6ed54d316334 host host local 7092879f2cc8 none null local ``` The default `bridge` network is listed,",true,Docker|network
|
| 116 |
+
115,2280,2320,"SCOPE 17e324f45964 bridge bridge local 6ed54d316334 host host local 7092879f2cc8 none null local ``` The default `bridge` network is listed, along with `host` and `none`. 2. Start two `alpine` containers running `ash`. The `-dit` flags mean detached, interactive, and with",false,container|network
|
| 117 |
+
116,2300,2340,"along with `host` and `none`. 2. Start two `alpine` containers running `ash`. The `-dit` flags mean detached, interactive, and with a TTY. Since you haven't specified a `--network` flag, the containers connect to the default `bridge` network. ```console $ docker",true,Docker|container|network
|
| 118 |
+
117,2320,2360,"a TTY. Since you haven't specified a `--network` flag, the containers connect to the default `bridge` network. ```console $ docker run -dit --name alpine1 alpine ash $ docker run -dit --name alpine2 alpine ash ``` Verify both containers are running:",true,Docker|container|network
|
| 119 |
+
118,2340,2380,"run -dit --name alpine1 alpine ash $ docker run -dit --name alpine2 alpine ash ``` Verify both containers are running: ```console $ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 602dbf1edc81 alpine ""ash"" 4 seconds ago Up",true,Docker|container|image
|
| 120 |
+
119,2360,2400,"```console $ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 602dbf1edc81 alpine ""ash"" 4 seconds ago Up 3 seconds alpine2 da33b7aa74b0 alpine ""ash"" 17 seconds ago Up 16 seconds alpine1 ``` 3. Inspect the `bridge` network to",true,Docker|container|image|network
|
| 121 |
+
120,2380,2420,"3 seconds alpine2 da33b7aa74b0 alpine ""ash"" 17 seconds ago Up 16 seconds alpine1 ``` 3. Inspect the `bridge` network to see connected containers: ```console $ docker network inspect bridge ``` The output shows both containers connected, with their assigned IP",true,Docker|container|network
|
| 122 |
+
121,2400,2440,"see connected containers: ```console $ docker network inspect bridge ``` The output shows both containers connected, with their assigned IP addresses (`172.17.0.2` for `alpine1` and `172.17.0.3` for `alpine2`). 4. Connect to `alpine1`: ```console $ docker attach alpine1 / # ```",true,Docker|container|network
|
| 123 |
+
122,2420,2460,addresses (`172.17.0.2` for `alpine1` and `172.17.0.3` for `alpine2`). 4. Connect to `alpine1`: ```console $ docker attach alpine1 / # ``` Show the network interfaces for `alpine1` from within the container: ```console # ip addr show 1: lo: mtu 65536 qdisc,true,Docker|container|network
|
| 124 |
+
123,2440,2480,Show the network interfaces for `alpine1` from within the container: ```console # ip addr show 1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128,false,container|network
|
| 125 |
+
124,2460,2500,noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 27: eth0@if28: mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff inet 172.17.0.2/16,false,
|
| 126 |
+
125,2480,2520,"scope host valid_lft forever preferred_lft forever 27: eth0@if28: mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff inet 172.17.0.2/16 scope global eth0 valid_lft forever preferred_lft forever ``` In this example, the `eth0` interface has the IP address `172.17.0.2`. 5.",false,
|
| 127 |
+
126,2500,2540,"scope global eth0 valid_lft forever preferred_lft forever ``` In this example, the `eth0` interface has the IP address `172.17.0.2`. 5. From within `alpine1`, verify you can connect to the internet: ```console # ping -c 2 google.com PING google.com (172.217.3.174): 56",false,
|
| 128 |
+
127,2520,2560,"From within `alpine1`, verify you can connect to the internet: ```console # ping -c 2 google.com PING google.com (172.217.3.174): 56 data bytes 64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.841 ms 64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.897 ms --- google.com",false,
|
| 129 |
+
128,2540,2580,"data bytes 64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.841 ms 64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.897 ms --- google.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 9.841/9.869/9.897 ms ``` 6. Ping",false,
|
| 130 |
+
129,2560,2600,"ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 9.841/9.869/9.897 ms ``` 6. Ping the second container by its IP address: ```console # ping -c 2 172.17.0.3 PING 172.17.0.3 (172.17.0.3): 56 data bytes 64",false,container
|
| 131 |
+
130,2580,2620,the second container by its IP address: ```console # ping -c 2 172.17.0.3 PING 172.17.0.3 (172.17.0.3): 56 data bytes 64 bytes from 172.17.0.3: seq=0 ttl=64 time=0.086 ms 64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.094 ms --- 172.17.0.3 ping statistics ---,false,container
|
| 132 |
+
131,2600,2640,"bytes from 172.17.0.3: seq=0 ttl=64 time=0.086 ms 64 bytes from 172.17.0.3: seq=1 ttl=64 time=0.094 ms --- 172.17.0.3 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.086/0.090/0.094 ms ``` This succeeds. Now try pinging",false,
|
| 133 |
+
132,2620,2660,"2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.086/0.090/0.094 ms ``` This succeeds. Now try pinging by container name: ```console # ping -c 2 alpine2 ping: bad address 'alpine2' ``` On the default bridge network, containers",false,container|network
|
| 134 |
+
133,2640,2680,"by container name: ```console # ping -c 2 alpine2 ping: bad address 'alpine2' ``` On the default bridge network, containers can't resolve each other by name. 7. Detach from `alpine1` without stopping it using `CTRL+p CTRL+q`. 8. Clean up: stop",false,container|network
|
| 135 |
+
134,2660,2700,can't resolve each other by name. 7. Detach from `alpine1` without stopping it using `CTRL+p CTRL+q`. 8. Clean up: stop the containers and remove them. ```console $ docker container stop alpine1 alpine2 $ docker container rm alpine1 alpine2 ``` Stopped,true,Docker|container
|
| 136 |
+
135,2680,2720,the containers and remove them. ```console $ docker container stop alpine1 alpine2 $ docker container rm alpine1 alpine2 ``` Stopped containers lose their IP addresses. ### Use user-defined bridge networks This example shows how user-defined bridge networks provide better isolation,true,Docker|container|network
|
| 137 |
+
136,2700,2740,containers lose their IP addresses. ### Use user-defined bridge networks This example shows how user-defined bridge networks provide better isolation and automatic DNS resolution between containers. 1. Create the `alpine-net` network: ```console $ docker network create --driver bridge alpine-net ```,true,Docker|container|network
|
| 138 |
+
137,2720,2760,and automatic DNS resolution between containers. 1. Create the `alpine-net` network: ```console $ docker network create --driver bridge alpine-net ``` 2. List Docker's networks: ```console $ docker network ls NETWORK ID NAME DRIVER SCOPE e9261a8c9a19 alpine-net bridge local 17e324f45964 bridge,true,Docker|container|network
|
| 139 |
+
138,2740,2780,2. List Docker's networks: ```console $ docker network ls NETWORK ID NAME DRIVER SCOPE e9261a8c9a19 alpine-net bridge local 17e324f45964 bridge bridge local 6ed54d316334 host host local 7092879f2cc8 none null local ``` Inspect the `alpine-net` network: ```console $ docker network inspect,true,Docker|network
|
| 140 |
+
139,2760,2800,"bridge local 6ed54d316334 host host local 7092879f2cc8 none null local ``` Inspect the `alpine-net` network: ```console $ docker network inspect alpine-net ``` This shows the network's gateway (for example, `172.18.0.1`) and that no containers are connected yet. 3. Create four",true,Docker|container|network
|
| 141 |
+
140,2780,2820,"alpine-net ``` This shows the network's gateway (for example, `172.18.0.1`) and that no containers are connected yet. 3. Create four containers. Three connect to `alpine-net`, and one connects to the default `bridge`. Then connect one container to both networks: ```console",false,container|network
|
| 142 |
+
141,2800,2840,"containers. Three connect to `alpine-net`, and one connects to the default `bridge`. Then connect one container to both networks: ```console $ docker run -dit --name alpine1 --network alpine-net alpine ash $ docker run -dit --name alpine2 --network alpine-net alpine ash",true,Docker|container|network
|
| 143 |
+
142,2820,2860,$ docker run -dit --name alpine1 --network alpine-net alpine ash $ docker run -dit --name alpine2 --network alpine-net alpine ash $ docker run -dit --name alpine3 alpine ash $ docker run -dit --name alpine4 --network alpine-net alpine ash $ docker,true,Docker|network
|
| 144 |
+
143,2840,2880,$ docker run -dit --name alpine3 alpine ash $ docker run -dit --name alpine4 --network alpine-net alpine ash $ docker network connect bridge alpine4 ``` Verify all containers are running: ```console $ docker container ls CONTAINER ID IMAGE COMMAND CREATED,true,Docker|container|image|network
|
| 145 |
+
144,2860,2900,"network connect bridge alpine4 ``` Verify all containers are running: ```console $ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 156849ccd902 alpine ""ash"" 41 seconds ago Up 41 seconds alpine4 fa1340b8d83e alpine ""ash"" 51 seconds ago Up",true,Docker|container|image|network
|
| 146 |
+
145,2880,2920,"STATUS PORTS NAMES 156849ccd902 alpine ""ash"" 41 seconds ago Up 41 seconds alpine4 fa1340b8d83e alpine ""ash"" 51 seconds ago Up 51 seconds alpine3 a535d969081e alpine ""ash"" About a minute ago Up About a minute alpine2 0a02c449a6e9 alpine ""ash"" About a",false,
|
| 147 |
+
146,2900,2940,"51 seconds alpine3 a535d969081e alpine ""ash"" About a minute ago Up About a minute alpine2 0a02c449a6e9 alpine ""ash"" About a minute ago Up About a minute alpine1 ``` 4. Inspect both networks again to see which containers are connected: ```console",false,container|network
|
| 148 |
+
147,2920,2960,minute ago Up About a minute alpine1 ``` 4. Inspect both networks again to see which containers are connected: ```console $ docker network inspect bridge ``` Containers `alpine3` and `alpine4` are connected to the `bridge` network. ```console $ docker network,true,Docker|container|network
|
| 149 |
+
148,2940,2980,"$ docker network inspect bridge ``` Containers `alpine3` and `alpine4` are connected to the `bridge` network. ```console $ docker network inspect alpine-net ``` Containers `alpine1`, `alpine2`, and `alpine4` are connected to `alpine-net`. 5. On user-defined networks, containers can resolve each",true,Docker|container|network
|
| 150 |
+
149,2960,3000,"inspect alpine-net ``` Containers `alpine1`, `alpine2`, and `alpine4` are connected to `alpine-net`. 5. On user-defined networks, containers can resolve each other by name. Connect to `alpine1` and test: > [!NOTE] > Automatic service discovery only resolves custom container names, not",false,container|network
|
| 151 |
+
150,2980,3020,"other by name. Connect to `alpine1` and test: > [!NOTE] > Automatic service discovery only resolves custom container names, not > default automatically generated names. ```console $ docker container attach alpine1 # ping -c 2 alpine2 PING alpine2 (172.18.0.3): 56",true,Docker|container
|
| 152 |
+
151,3000,3040,> default automatically generated names. ```console $ docker container attach alpine1 # ping -c 2 alpine2 PING alpine2 (172.18.0.3): 56 data bytes 64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.085 ms 64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.090 ms --- alpine2,true,Docker|container
|
| 153 |
+
152,3020,3060,"data bytes 64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.085 ms 64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.090 ms --- alpine2 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.085/0.087/0.090 ms # ping -c",false,
|
| 154 |
+
153,3040,3080,"ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.085/0.087/0.090 ms # ping -c 2 alpine4 PING alpine4 (172.18.0.4): 56 data bytes 64 bytes from 172.18.0.4: seq=0 ttl=64 time=0.076 ms 64 bytes from 172.18.0.4:",false,
|
| 155 |
+
154,3060,3100,"2 alpine4 PING alpine4 (172.18.0.4): 56 data bytes 64 bytes from 172.18.0.4: seq=0 ttl=64 time=0.076 ms 64 bytes from 172.18.0.4: seq=1 ttl=64 time=0.091 ms --- alpine4 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max",false,
|
| 156 |
+
155,3080,3120,"seq=1 ttl=64 time=0.091 ms --- alpine4 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.076/0.083/0.091 ms ``` 6. From `alpine1`, you can't connect to `alpine3` because it's on a different network: ```console #",false,network
|
| 157 |
+
156,3100,3140,"= 0.076/0.083/0.091 ms ``` 6. From `alpine1`, you can't connect to `alpine3` because it's on a different network: ```console # ping -c 2 alpine3 ping: bad address 'alpine3' ``` You also can't connect by IP address. If `alpine3`'s IP is",false,network
|
| 158 |
+
157,3120,3160,ping -c 2 alpine3 ping: bad address 'alpine3' ``` You also can't connect by IP address. If `alpine3`'s IP is `172.17.0.2`: ```console # ping -c 2 172.17.0.2 PING 172.17.0.2 (172.17.0.2): 56 data bytes --- 172.17.0.2 ping statistics --- 2 packets,false,
|
| 159 |
+
158,3140,3180,"`172.17.0.2`: ```console # ping -c 2 172.17.0.2 PING 172.17.0.2 (172.17.0.2): 56 data bytes --- 172.17.0.2 ping statistics --- 2 packets transmitted, 0 packets received, 100% packet loss ``` Detach from `alpine1` using `CTRL+p CTRL+q`. 7. Since `alpine4` is connected to",false,
|
| 160 |
+
159,3160,3200,"transmitted, 0 packets received, 100% packet loss ``` Detach from `alpine1` using `CTRL+p CTRL+q`. 7. Since `alpine4` is connected to both networks, it can reach all containers. However, you need to use `alpine3`'s IP address: ```console $ docker container attach",true,Docker|container|network
|
| 161 |
+
160,3180,3220,"both networks, it can reach all containers. However, you need to use `alpine3`'s IP address: ```console $ docker container attach alpine4 # ping -c 2 alpine1 PING alpine1 (172.18.0.2): 56 data bytes 64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.074 ms",true,Docker|container|network
|
| 162 |
+
161,3200,3240,"alpine4 # ping -c 2 alpine1 PING alpine1 (172.18.0.2): 56 data bytes 64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.074 ms 64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.082 ms --- alpine1 ping statistics --- 2 packets transmitted, 2 packets received, 0%",false,
|
| 163 |
+
162,3220,3260,"64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.082 ms --- alpine1 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.074/0.078/0.082 ms # ping -c 2 alpine2 PING alpine2 (172.18.0.3): 56 data bytes 64 bytes",false,
|
| 164 |
+
163,3240,3280,packet loss round-trip min/avg/max = 0.074/0.078/0.082 ms # ping -c 2 alpine2 PING alpine2 (172.18.0.3): 56 data bytes 64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.075 ms 64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.080 ms --- alpine2 ping statistics --- 2,false,
|
| 165 |
+
164,3260,3300,"from 172.18.0.3: seq=0 ttl=64 time=0.075 ms 64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.080 ms --- alpine2 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.075/0.077/0.080 ms # ping -c 2 alpine3 ping: bad",false,
|
| 166 |
+
165,3280,3320,"packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.075/0.077/0.080 ms # ping -c 2 alpine3 ping: bad address 'alpine3' # ping -c 2 172.17.0.2 PING 172.17.0.2 (172.17.0.2): 56 data bytes 64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.089",false,
|
| 167 |
+
166,3300,3340,"address 'alpine3' # ping -c 2 172.17.0.2 PING 172.17.0.2 (172.17.0.2): 56 data bytes 64 bytes from 172.17.0.2: seq=0 ttl=64 time=0.089 ms 64 bytes from 172.17.0.2: seq=1 ttl=64 time=0.075 ms --- 172.17.0.2 ping statistics --- 2 packets transmitted, 2 packets received,",false,
|
| 168 |
+
167,3320,3360,"ms 64 bytes from 172.17.0.2: seq=1 ttl=64 time=0.075 ms --- 172.17.0.2 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.075/0.082/0.089 ms ``` 8. Verify all containers can connect to the internet: ```console #",false,container
|
| 169 |
+
168,3340,3380,0% packet loss round-trip min/avg/max = 0.075/0.082/0.089 ms ``` 8. Verify all containers can connect to the internet: ```console # ping -c 2 google.com PING google.com (172.217.3.174): 56 data bytes 64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.778 ms 64 bytes,false,container
|
| 170 |
+
169,3360,3400,"ping -c 2 google.com PING google.com (172.217.3.174): 56 data bytes 64 bytes from 172.217.3.174: seq=0 ttl=41 time=9.778 ms 64 bytes from 172.217.3.174: seq=1 ttl=41 time=9.634 ms --- google.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss",false,
|
| 171 |
+
170,3380,3420,"from 172.217.3.174: seq=1 ttl=41 time=9.634 ms --- google.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 9.634/9.706/9.778 ms ``` Detach with `CTRL+p CTRL+q` and repeat for `alpine3` and `alpine1` if desired. 9. Clean",false,
|
| 172 |
+
171,3400,3440,round-trip min/avg/max = 9.634/9.706/9.778 ms ``` Detach with `CTRL+p CTRL+q` and repeat for `alpine3` and `alpine1` if desired. 9. Clean up: ```console $ docker container stop alpine1 alpine2 alpine3 alpine4 $ docker container rm alpine1 alpine2 alpine3 alpine4 $ docker,true,Docker|container
|
| 173 |
+
172,3420,3460,up: ```console $ docker container stop alpine1 alpine2 alpine3 alpine4 $ docker container rm alpine1 alpine2 alpine3 alpine4 $ docker network rm alpine-net ``` ## Next steps - Learn about [networking from the container's point of view](../_index.md) - Learn about,true,Docker|container|network
|
| 174 |
+
173,3440,3468,network rm alpine-net ``` ## Next steps - Learn about [networking from the container's point of view](../_index.md) - Learn about [overlay networks](./overlay.md) - Learn about [Macvlan networks](./macvlan.md) ```,false,container|network
|
20260907-014716-computing-math-8018f2/environment/public_data/main.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import importlib.util
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import shlex
|
| 7 |
+
import shutil
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Task:
|
| 13 |
+
def __init__(self, task_id: str, description: str, metadata: dict[str, Any]):
|
| 14 |
+
self.task_id = task_id
|
| 15 |
+
self.description = description
|
| 16 |
+
self.prompt = description
|
| 17 |
+
self.metadata = metadata
|
| 18 |
+
self.computer = {"setup_config": {"os_type": "linux"}}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _task_dir() -> Path:
|
| 22 |
+
return Path(__file__).resolve().parent
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _load_card() -> dict[str, Any]:
|
| 26 |
+
path = _task_dir() / "task_card.json"
|
| 27 |
+
if not path.is_file():
|
| 28 |
+
return {
|
| 29 |
+
"taskId": os.environ.get("ALE_TASK_ID", "computing_math/offline_docker_bridge_document_audit"),
|
| 30 |
+
"taskPrompt": "Task card has not been rendered yet; this fallback exists for stage-03 hook smoke only.",
|
| 31 |
+
"metadata": {
|
| 32 |
+
"domain": "computing_math",
|
| 33 |
+
"task": "offline_docker_bridge_document_audit",
|
| 34 |
+
"variant": "base",
|
| 35 |
+
"domain_name": "computing_math",
|
| 36 |
+
"task_name": "offline_docker_bridge_document_audit",
|
| 37 |
+
"variant_name": "base",
|
| 38 |
+
"requires_task_data": True,
|
| 39 |
+
"task_dir": "/media/user/data/agenthle/computing_math/offline_docker_bridge_document_audit/base",
|
| 40 |
+
"input_dir": "/media/user/data/agenthle/computing_math/offline_docker_bridge_document_audit/base/input",
|
| 41 |
+
"software_dir": "/media/user/data/agenthle/computing_math/offline_docker_bridge_document_audit/base/software",
|
| 42 |
+
"remote_output_dir": "/media/user/data/agenthle/computing_math/offline_docker_bridge_document_audit/base/output",
|
| 43 |
+
"reference_dir": "/media/user/data/agenthle/computing_math/offline_docker_bridge_document_audit/base/reference",
|
| 44 |
+
},
|
| 45 |
+
}
|
| 46 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 47 |
+
return json.load(handle)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def load() -> list[Task]:
|
| 51 |
+
card = _load_card()
|
| 52 |
+
metadata = dict(card.get("metadata") or {})
|
| 53 |
+
if not metadata:
|
| 54 |
+
domain, _, task = str(card["taskId"]).partition("/")
|
| 55 |
+
variant = "base"
|
| 56 |
+
task_dir = f"/media/user/data/agenthle/{domain}/{task}/{variant}"
|
| 57 |
+
metadata.update({
|
| 58 |
+
"domain": domain,
|
| 59 |
+
"task": task,
|
| 60 |
+
"variant": variant,
|
| 61 |
+
"domain_name": domain,
|
| 62 |
+
"task_name": task,
|
| 63 |
+
"variant_name": variant,
|
| 64 |
+
"requires_task_data": True,
|
| 65 |
+
"task_dir": task_dir,
|
| 66 |
+
"input_dir": f"{task_dir}/input",
|
| 67 |
+
"software_dir": f"{task_dir}/software",
|
| 68 |
+
"remote_output_dir": f"{task_dir}/output",
|
| 69 |
+
"reference_dir": f"{task_dir}/reference",
|
| 70 |
+
})
|
| 71 |
+
return [Task(task_id=card["taskId"], description=card["taskPrompt"], metadata=metadata)]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _metadata(cfg: Any = None) -> dict[str, Any]:
|
| 75 |
+
if cfg is None:
|
| 76 |
+
return {}
|
| 77 |
+
value = getattr(cfg, "metadata", None)
|
| 78 |
+
return value if isinstance(value, dict) else {}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _remote_path(metadata: dict[str, Any], key: str, fallback: str) -> str:
|
| 82 |
+
value = str(metadata.get(key) or "").strip()
|
| 83 |
+
return value or fallback
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
async def _remote_run(session: Any, command: str, *, check: bool = False) -> Any:
|
| 87 |
+
try:
|
| 88 |
+
return await session.run_command(command, check=check)
|
| 89 |
+
except TypeError:
|
| 90 |
+
return await session.run_command(command)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
async def _remote_start(cfg: Any, session: Any) -> dict[str, Any]:
|
| 94 |
+
metadata = _metadata(cfg)
|
| 95 |
+
output_dir = _remote_path(metadata, "remote_output_dir", "output")
|
| 96 |
+
input_dir = _remote_path(metadata, "input_dir", "input")
|
| 97 |
+
software_dir = _remote_path(metadata, "software_dir", "software")
|
| 98 |
+
command = (
|
| 99 |
+
"set -eu\n"
|
| 100 |
+
f"mkdir -p {shlex.quote(output_dir)}\n"
|
| 101 |
+
f"find {shlex.quote(output_dir)} -mindepth 1 -maxdepth 1 -exec rm -rf -- {{}} +\n"
|
| 102 |
+
)
|
| 103 |
+
await _remote_run(session, command, check=True)
|
| 104 |
+
return {"ok": True, "input_dir": input_dir, "software_dir": software_dir, "output_dir": output_dir}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def start(cfg: Any = None, session: Any = None) -> dict[str, Any]:
|
| 108 |
+
if session is not None:
|
| 109 |
+
return _remote_start(cfg, session)
|
| 110 |
+
del cfg
|
| 111 |
+
output_dir = Path(os.environ.get("ALE_OUTPUT_DIR", "output"))
|
| 112 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 113 |
+
for child in output_dir.iterdir():
|
| 114 |
+
if child.is_dir():
|
| 115 |
+
shutil.rmtree(child)
|
| 116 |
+
else:
|
| 117 |
+
child.unlink()
|
| 118 |
+
input_dir = Path(os.environ.get("ALE_INPUT_DIR", "input"))
|
| 119 |
+
software_dir = Path(os.environ.get("ALE_SOFTWARE_DIR", "software"))
|
| 120 |
+
return {
|
| 121 |
+
"ok": True,
|
| 122 |
+
"input_dir": str(input_dir),
|
| 123 |
+
"software_dir": str(software_dir),
|
| 124 |
+
"output_dir": str(output_dir),
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
async def _remote_evaluate(cfg: Any, session: Any) -> list[float]:
|
| 129 |
+
metadata = _metadata(cfg)
|
| 130 |
+
output_dir = _remote_path(metadata, "remote_output_dir", "output")
|
| 131 |
+
reference_dir = _remote_path(metadata, "reference_dir", "reference")
|
| 132 |
+
script = f"""
|
| 133 |
+
import importlib.util
|
| 134 |
+
import json
|
| 135 |
+
import pathlib
|
| 136 |
+
|
| 137 |
+
output_dir = pathlib.Path({output_dir!r})
|
| 138 |
+
reference_dir = pathlib.Path({reference_dir!r})
|
| 139 |
+
evaluator_path = reference_dir / "evaluator.py"
|
| 140 |
+
if not evaluator_path.is_file():
|
| 141 |
+
raise FileNotFoundError(f"hidden evaluator is missing: {{evaluator_path}}")
|
| 142 |
+
spec = importlib.util.spec_from_file_location("hidden_ale_evaluator", evaluator_path)
|
| 143 |
+
if spec is None or spec.loader is None:
|
| 144 |
+
raise RuntimeError(f"cannot import hidden evaluator: {{evaluator_path}}")
|
| 145 |
+
module = importlib.util.module_from_spec(spec)
|
| 146 |
+
spec.loader.exec_module(module)
|
| 147 |
+
result = module.evaluate(output_dir, reference_dir)
|
| 148 |
+
print(json.dumps(result))
|
| 149 |
+
"""
|
| 150 |
+
command = "python3 - <<'PY'\n" + script + "\nPY"
|
| 151 |
+
result = await _remote_run(session, command, check=True)
|
| 152 |
+
stdout = getattr(result, "stdout", "") or ""
|
| 153 |
+
for line in reversed([item.strip() for item in stdout.splitlines() if item.strip()]):
|
| 154 |
+
try:
|
| 155 |
+
payload = json.loads(line)
|
| 156 |
+
if isinstance(payload, list):
|
| 157 |
+
return [float(max(0.0, min(1.0, value))) for value in payload]
|
| 158 |
+
except Exception:
|
| 159 |
+
continue
|
| 160 |
+
raise RuntimeError("hidden evaluator did not emit a JSON score list")
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def evaluate(cfg: Any = None, session: Any = None) -> list[float]:
|
| 164 |
+
if session is not None:
|
| 165 |
+
return _remote_evaluate(cfg, session)
|
| 166 |
+
del cfg
|
| 167 |
+
output_dir = Path(os.environ.get("ALE_OUTPUT_DIR", "output"))
|
| 168 |
+
reference_dir = Path(os.environ.get("ALE_REFERENCE_DIR", "reference"))
|
| 169 |
+
evaluator_path = reference_dir / "evaluator.py"
|
| 170 |
+
if not evaluator_path.is_file():
|
| 171 |
+
raise FileNotFoundError(f"hidden evaluator is missing: {evaluator_path}")
|
| 172 |
+
spec = importlib.util.spec_from_file_location("hidden_ale_evaluator", evaluator_path)
|
| 173 |
+
if spec is None or spec.loader is None:
|
| 174 |
+
raise RuntimeError(f"cannot import hidden evaluator: {evaluator_path}")
|
| 175 |
+
module = importlib.util.module_from_spec(spec)
|
| 176 |
+
spec.loader.exec_module(module)
|
| 177 |
+
result = module.evaluate(output_dir, reference_dir)
|
| 178 |
+
if not isinstance(result, list):
|
| 179 |
+
raise TypeError("hidden evaluator must return list[float]")
|
| 180 |
+
return [float(max(0.0, min(1.0, value))) for value in result]
|
20260907-014716-computing-math-8018f2/environment/public_data/software/command_examples.csv
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
term,kind,software_name
|
| 2 |
+
docker run,code_term,Docker
|
| 3 |
+
docker build,code_term,Docker
|
| 4 |
+
docker compose,code_term,Docker
|
| 5 |
+
docker pull,code_term,Docker
|
| 6 |
+
docker,code_term,Docker
|
| 7 |
+
docker,executable,Docker
|
| 8 |
+
docker compose,executable,Docker
|
20260907-014716-computing-math-8018f2/environment/public_data/software/software_manifest.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"software_name": "Docker",
|
| 3 |
+
"executables": [
|
| 4 |
+
"docker",
|
| 5 |
+
"docker compose"
|
| 6 |
+
],
|
| 7 |
+
"required_system_packages": [
|
| 8 |
+
"docker.io",
|
| 9 |
+
"docker-compose-plugin"
|
| 10 |
+
],
|
| 11 |
+
"official_sources": [
|
| 12 |
+
"https://github.com/docker/docs/raw/refs/heads/main/content/manuals/engine/network/drivers/bridge.md"
|
| 13 |
+
],
|
| 14 |
+
"solve_time_network": "disabled",
|
| 15 |
+
"python_wrapper_only": false,
|
| 16 |
+
"note": "This task audits real official software documentation/source staged offline; Python helpers only validate outputs."
|
| 17 |
+
}
|
20260907-014716-computing-math-8018f2/environment/public_data/software/validate_outputs.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def required_outputs(input_dir: Path) -> list[str]:
|
| 11 |
+
spec_path = input_dir / "analysis_spec.json"
|
| 12 |
+
if spec_path.is_file():
|
| 13 |
+
payload = json.loads(spec_path.read_text(encoding="utf-8"))
|
| 14 |
+
required = payload.get("required_outputs") if isinstance(payload, dict) else None
|
| 15 |
+
if isinstance(required, list):
|
| 16 |
+
rows = [str(item.get("path") or "") for item in required if isinstance(item, dict)]
|
| 17 |
+
rows = [item for item in rows if item]
|
| 18 |
+
if rows:
|
| 19 |
+
return rows
|
| 20 |
+
return [
|
| 21 |
+
"summary.json",
|
| 22 |
+
"magnitude_depth_bins.csv",
|
| 23 |
+
"region_daily_counts.csv",
|
| 24 |
+
"filtered_events.geojson",
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def main() -> int:
|
| 29 |
+
output_dir = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("output")
|
| 30 |
+
input_dir = Path(sys.argv[2]) if len(sys.argv) > 2 else Path(os.environ.get("ALE_INPUT_DIR", "input"))
|
| 31 |
+
required = required_outputs(input_dir)
|
| 32 |
+
missing = [name for name in required if not (output_dir / name).is_file()]
|
| 33 |
+
if missing:
|
| 34 |
+
print(json.dumps({"ok": False, "missing": missing}, indent=2))
|
| 35 |
+
return 1
|
| 36 |
+
print(json.dumps({"ok": True, "required": required}, indent=2))
|
| 37 |
+
return 0
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
raise SystemExit(main())
|
20260907-014716-computing-math-8018f2/environment/public_data/task_card.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"taskId": "computing_math/offline_docker_bridge_document_audit__20260907-014716_computing_math_8018f2",
|
| 3 |
+
"title": "Repair4 20260907 030 Repair3 20260907 049 Repair2 20260906 054 Repair 20260906 Software 0085",
|
| 4 |
+
"summary": "Audit a staged offline Docker official tutorial corpus and produce reproducible section, keyword, and command inventories from local files (keyword-subset experiment 1: 6 terms) (ALE-100 software diversity variant 3) (independent source snapshot 3). (repair batch 20260906; independent official source) (targeted repair round 2). (targeted repair round 3). (targeted repair round 4).",
|
| 5 |
+
"category": "computing_math",
|
| 6 |
+
"taxonomy": {
|
| 7 |
+
"domain_id": "9",
|
| 8 |
+
"domain_code": "computing_math",
|
| 9 |
+
"subdomain_id": "9.6",
|
| 10 |
+
"subdomain_code": "infra_cloud",
|
| 11 |
+
"subdomain_name": "Infrastructure Engineering & Cloud Operations",
|
| 12 |
+
"classifier": {
|
| 13 |
+
"source": "public software metadata mapping",
|
| 14 |
+
"rationale": "Subdomain selected from public task metadata."
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"taskPrompt": "Use a Linux command-line workflow to audit the staged offline official tutorial corpus for Docker. The source document is input/tutorial_source.html, and input/tutorial_text_windows.csv contains deterministic text windows derived from it. Your job is to reconstruct the section outline, keyword inventory, code-block inventory, and summary statistics from the local files. Read only the staged files in input/ and software/, write final deliverables under output/, and do not use network access, credentials, GUI tools, browser automation, Windows-only tooling, or mobile apps. The authoritative public contract is input/analysis_spec.json; if any wording elsewhere is less specific, follow analysis_spec.json for file names, columns, filters, grouping rules, rounding rules, and output schemas. The workflow kind is software_tutorial_doc_audit. The primary staged data file is input/tutorial_text_windows.csv. Produce exactly these required deliverables: output/summary.json, output/section_outline.csv, output/keyword_inventory.csv, output/code_block_inventory.csv. The output schemas are:\n- output/summary.json: JSON keys and nested shape {\"code_block_count\": \"integer\", \"heading_count\": \"integer\", \"keyword_total\": \"integer\", \"software_name\": \"string\", \"source_character_count\": \"integer\", \"source_file\": \"string\", \"top_keyword\": \"string|null\", \"unique_required_terms_found\": \"integer\", \"window_count\": \"integer\"}\n- output/section_outline.csv: CSV header exactly rank, heading_level, heading_text, slug\n- output/keyword_inventory.csv: CSV header exactly term, category, count, first_window, appears_in_code\n- output/code_block_inventory.csv: CSV header exactly block_index, line_count, char_count, contains_code_term, first_line\nCompute all requested values from the staged data rather than hard-coding constants. Use deterministic ordering, UTF-8 text, explicit CSV headers, valid JSON/GeoJSON where applicable, and stable numeric formatting. You may run software/validate_outputs.py as a public sanity check after writing outputs, but the deliverables in output/ are what will be evaluated.",
|
| 18 |
+
"agentMustDo": [
|
| 19 |
+
"Read input/analysis_spec.json first and treat it as the authoritative public specification.",
|
| 20 |
+
"Read input/tutorial_text_windows.csv and compute results from the staged local data.",
|
| 21 |
+
"Create output/summary.json as json exactly as specified by analysis_spec.json.",
|
| 22 |
+
"Create output/section_outline.csv as csv exactly as specified by analysis_spec.json.",
|
| 23 |
+
"Create output/keyword_inventory.csv as csv exactly as specified by analysis_spec.json.",
|
| 24 |
+
"Create output/code_block_inventory.csv as csv exactly as specified by analysis_spec.json.",
|
| 25 |
+
"Place every final deliverable directly under output/ with the exact required filename.",
|
| 26 |
+
"Use only local staged files and installed Linux CLI tooling; do not download fresh data."
|
| 27 |
+
],
|
| 28 |
+
"inputFiles": [
|
| 29 |
+
{
|
| 30 |
+
"name": "README.md",
|
| 31 |
+
"format": "Markdown",
|
| 32 |
+
"path": "input/README.md",
|
| 33 |
+
"description": "Agent-visible staged input file for this task."
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"name": "analysis_spec.json",
|
| 37 |
+
"format": "JSON",
|
| 38 |
+
"path": "input/analysis_spec.json",
|
| 39 |
+
"description": "Agent-visible staged input file for this task."
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"name": "source_context_windows.jsonl",
|
| 43 |
+
"format": "JSONL",
|
| 44 |
+
"path": "input/source_context_windows.jsonl",
|
| 45 |
+
"description": "Agent-visible staged input file for this task."
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"name": "tutorial_metadata.json",
|
| 49 |
+
"format": "JSON",
|
| 50 |
+
"path": "input/tutorial_metadata.json",
|
| 51 |
+
"description": "Agent-visible staged input file for this task."
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"name": "tutorial_source.html",
|
| 55 |
+
"format": "HTML",
|
| 56 |
+
"path": "input/tutorial_source.html",
|
| 57 |
+
"description": "Agent-visible staged input file for this task."
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"name": "tutorial_text_windows.csv",
|
| 61 |
+
"format": "CSV",
|
| 62 |
+
"path": "input/tutorial_text_windows.csv",
|
| 63 |
+
"description": "Agent-visible staged input file for this task."
|
| 64 |
+
}
|
| 65 |
+
],
|
| 66 |
+
"referenceFiles": [
|
| 67 |
+
{
|
| 68 |
+
"name": "summary.json",
|
| 69 |
+
"format": "JSON",
|
| 70 |
+
"path": "output/summary.json",
|
| 71 |
+
"description": "Required agent output file evaluated against hidden reference data."
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "section_outline.csv",
|
| 75 |
+
"format": "CSV",
|
| 76 |
+
"path": "output/section_outline.csv",
|
| 77 |
+
"description": "Required agent output file evaluated against hidden reference data."
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"name": "keyword_inventory.csv",
|
| 81 |
+
"format": "CSV",
|
| 82 |
+
"path": "output/keyword_inventory.csv",
|
| 83 |
+
"description": "Required agent output file evaluated against hidden reference data."
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"name": "code_block_inventory.csv",
|
| 87 |
+
"format": "CSV",
|
| 88 |
+
"path": "output/code_block_inventory.csv",
|
| 89 |
+
"description": "Required agent output file evaluated against hidden reference data."
|
| 90 |
+
}
|
| 91 |
+
],
|
| 92 |
+
"software": [
|
| 93 |
+
"Docker",
|
| 94 |
+
"docker",
|
| 95 |
+
"docker compose",
|
| 96 |
+
"Python 3.11",
|
| 97 |
+
"standard Unix shell",
|
| 98 |
+
"software/command_examples.csv",
|
| 99 |
+
"software/software_manifest.json",
|
| 100 |
+
"software/validate_outputs.py"
|
| 101 |
+
],
|
| 102 |
+
"requiredSystemPackages": [
|
| 103 |
+
"docker.io",
|
| 104 |
+
"docker-compose-plugin"
|
| 105 |
+
],
|
| 106 |
+
"evaluation": "Final required files under output/ are compared against standard-reference outputs generated by the deterministic workflow for this task.",
|
| 107 |
+
"vm": {
|
| 108 |
+
"machineType": "c4-standard-4",
|
| 109 |
+
"snapshot": "cpu-free-ubuntu",
|
| 110 |
+
"timeout": 7200
|
| 111 |
+
}
|
| 112 |
+
}
|
20260907-014716-computing-math-8018f2/instruction.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Repair4 20260907 030 Repair3 20260907 049 Repair2 20260906 054 Repair 20260906 Software 0085
|
| 2 |
+
|
| 3 |
+
Audit a staged offline Docker official tutorial corpus and produce reproducible section, keyword, and command inventories from local files (keyword-subset experiment 1: 6 terms) (ALE-100 software diversity variant 3) (independent source snapshot 3). (repair batch 20260906; independent official source) (targeted repair round 2). (targeted repair round 3). (targeted repair round 4).
|
| 4 |
+
|
| 5 |
+
## Task
|
| 6 |
+
|
| 7 |
+
Use a Linux command-line workflow to audit the staged offline official tutorial corpus for Docker. The source document is input/tutorial_source.html, and input/tutorial_text_windows.csv contains deterministic text windows derived from it. Your job is to reconstruct the section outline, keyword inventory, code-block inventory, and summary statistics from the local files. Read only the staged files in input/ and software/, write final deliverables under output/, and do not use network access, credentials, GUI tools, browser automation, Windows-only tooling, or mobile apps. The authoritative public contract is input/analysis_spec.json; if any wording elsewhere is less specific, follow analysis_spec.json for file names, columns, filters, grouping rules, rounding rules, and output schemas. The workflow kind is software_tutorial_doc_audit. The primary staged data file is input/tutorial_text_windows.csv. Produce exactly these required deliverables: output/summary.json, output/section_outline.csv, output/keyword_inventory.csv, output/code_block_inventory.csv. The output schemas are:
|
| 8 |
+
- output/summary.json: JSON keys and nested shape {"code_block_count": "integer", "heading_count": "integer", "keyword_total": "integer", "software_name": "string", "source_character_count": "integer", "source_file": "string", "top_keyword": "string|null", "unique_required_terms_found": "integer", "window_count": "integer"}
|
| 9 |
+
- output/section_outline.csv: CSV header exactly rank, heading_level, heading_text, slug
|
| 10 |
+
- output/keyword_inventory.csv: CSV header exactly term, category, count, first_window, appears_in_code
|
| 11 |
+
- output/code_block_inventory.csv: CSV header exactly block_index, line_count, char_count, contains_code_term, first_line
|
| 12 |
+
Compute all requested values from the staged data rather than hard-coding constants. Use deterministic ordering, UTF-8 text, explicit CSV headers, valid JSON/GeoJSON where applicable, and stable numeric formatting. You may run software/validate_outputs.py as a public sanity check after writing outputs, but the deliverables in output/ are what will be evaluated.
|
| 13 |
+
|
| 14 |
+
## Workspace
|
| 15 |
+
|
| 16 |
+
You are working in `/workspace`.
|
| 17 |
+
|
| 18 |
+
- Public input files are under `/workspace/input/`.
|
| 19 |
+
- Public helper software and validation scripts are under `/workspace/software/`.
|
| 20 |
+
- The public task card is available at `/workspace/task_card.json`.
|
| 21 |
+
- The public task driver is available at `/workspace/main.py` for reference only.
|
| 22 |
+
- Do not use hidden reference data, network downloads, credentials, GUI tools, or browser automation.
|
| 23 |
+
|
| 24 |
+
## Required Outputs
|
| 25 |
+
|
| 26 |
+
Create every final deliverable exactly at these paths:
|
| 27 |
+
|
| 28 |
+
- `/workspace/output/summary.json` (json)
|
| 29 |
+
- `/workspace/output/section_outline.csv` (csv)
|
| 30 |
+
- `/workspace/output/keyword_inventory.csv` (csv)
|
| 31 |
+
- `/workspace/output/code_block_inventory.csv` (csv)
|
| 32 |
+
|
| 33 |
+
Follow `/workspace/input/analysis_spec.json` whenever it is more specific than prose. You may run public validation helpers, but the files under `/workspace/output/` are what will be evaluated.
|
20260907-014716-computing-math-8018f2/solution/internal/workflow_adapters_runtime.py
ADDED
|
@@ -0,0 +1,679 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
import datetime as dt
|
| 5 |
+
import html
|
| 6 |
+
import json
|
| 7 |
+
import math
|
| 8 |
+
import re
|
| 9 |
+
import shutil
|
| 10 |
+
import statistics
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _read_json(path: Path) -> Any:
|
| 16 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 17 |
+
return json.load(handle)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _write_json(path: Path, payload: Any) -> None:
|
| 21 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 22 |
+
with path.open("w", encoding="utf-8") as handle:
|
| 23 |
+
json.dump(payload, handle, ensure_ascii=False, indent=2)
|
| 24 |
+
handle.write("\n")
|
| 25 |
+
|
| 26 |
+
def _stable_region(place: str) -> str:
|
| 27 |
+
if not place:
|
| 28 |
+
return "unknown"
|
| 29 |
+
if "," in place:
|
| 30 |
+
return place.split(",")[-1].strip() or place.strip()
|
| 31 |
+
parts = place.split()
|
| 32 |
+
return " ".join(parts[-2:]) if len(parts) >= 2 else place.strip()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _mag_bin(value: float | None) -> str:
|
| 36 |
+
if value is None or math.isnan(value):
|
| 37 |
+
return "unknown"
|
| 38 |
+
lower = math.floor(value)
|
| 39 |
+
upper = lower + 1
|
| 40 |
+
return f"{lower:.0f}-{upper:.0f}"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _depth_bin(value: float | None) -> str:
|
| 44 |
+
if value is None or math.isnan(value):
|
| 45 |
+
return "unknown"
|
| 46 |
+
if value < 0:
|
| 47 |
+
return "<0"
|
| 48 |
+
if value < 10:
|
| 49 |
+
return "0-10"
|
| 50 |
+
if value < 30:
|
| 51 |
+
return "10-30"
|
| 52 |
+
if value < 70:
|
| 53 |
+
return "30-70"
|
| 54 |
+
if value < 300:
|
| 55 |
+
return "70-300"
|
| 56 |
+
return "300+"
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _clean_markup_text(raw: str) -> str:
|
| 60 |
+
text = re.sub(r"(?is)<(script|style|noscript)[^>]*>.*?</\1>", " ", raw)
|
| 61 |
+
text = re.sub(r"(?is)<br\s*/?>", "\n", text)
|
| 62 |
+
text = re.sub(r"(?is)</(p|div|li|tr|h[1-6]|pre)>", "\n", text)
|
| 63 |
+
text = re.sub(r"(?is)<[^>]+>", " ", text)
|
| 64 |
+
text = html.unescape(text)
|
| 65 |
+
text = re.sub(r"[ \t]+", " ", text)
|
| 66 |
+
text = re.sub(r"\n\s+", "\n", text)
|
| 67 |
+
return text.strip()
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _heading_slug(value: str) -> str:
|
| 71 |
+
slug = re.sub(r"[^a-z0-9]+", "_", value.lower()).strip("_")
|
| 72 |
+
return slug[:80] or "section"
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _extract_headings(raw: str) -> list[dict[str, str]]:
|
| 76 |
+
headings: list[dict[str, str]] = []
|
| 77 |
+
for match in re.finditer(r"(?is)<h([1-6])[^>]*>(.*?)</h\1>", raw):
|
| 78 |
+
text = _clean_markup_text(match.group(2))
|
| 79 |
+
if text:
|
| 80 |
+
headings.append({"level": f"h{match.group(1)}", "text": text})
|
| 81 |
+
if headings:
|
| 82 |
+
return headings
|
| 83 |
+
for line in raw.splitlines():
|
| 84 |
+
match = re.match(r"^(#{1,6})\s+(.+?)\s*$", line)
|
| 85 |
+
if match:
|
| 86 |
+
headings.append({"level": f"h{len(match.group(1))}", "text": match.group(2).strip()})
|
| 87 |
+
return headings
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _extract_code_blocks(raw: str) -> list[str]:
|
| 91 |
+
blocks: list[str] = []
|
| 92 |
+
for match in re.finditer(r"(?is)<pre[^>]*>(.*?)</pre>", raw):
|
| 93 |
+
text = _clean_markup_text(match.group(1))
|
| 94 |
+
if text:
|
| 95 |
+
blocks.append(text)
|
| 96 |
+
for match in re.finditer(r"(?is)<code[^>]*>(.*?)</code>", raw):
|
| 97 |
+
text = _clean_markup_text(match.group(1))
|
| 98 |
+
if text and text not in blocks:
|
| 99 |
+
blocks.append(text)
|
| 100 |
+
for match in re.finditer(r"(?s)```(?:[A-Za-z0-9_-]+)?\n(.*?)```", raw):
|
| 101 |
+
text = html.unescape(match.group(1).strip())
|
| 102 |
+
if text and text not in blocks:
|
| 103 |
+
blocks.append(text)
|
| 104 |
+
return blocks
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def _window_rows(clean_text: str, *, width: int = 40, stride: int = 20) -> list[dict[str, Any]]:
|
| 108 |
+
words = re.findall(r"\S+", clean_text)
|
| 109 |
+
rows: list[dict[str, Any]] = []
|
| 110 |
+
if not words:
|
| 111 |
+
return rows
|
| 112 |
+
start = 0
|
| 113 |
+
while start < len(words):
|
| 114 |
+
end = min(start + width, len(words))
|
| 115 |
+
rows.append({
|
| 116 |
+
"window_id": len(rows) + 1,
|
| 117 |
+
"start_word": start,
|
| 118 |
+
"end_word": end,
|
| 119 |
+
"text": " ".join(words[start:end]),
|
| 120 |
+
})
|
| 121 |
+
if end == len(words):
|
| 122 |
+
break
|
| 123 |
+
start += stride
|
| 124 |
+
return rows
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _term_count(text: str, term: str) -> int:
|
| 128 |
+
term = term.strip()
|
| 129 |
+
if not term:
|
| 130 |
+
return 0
|
| 131 |
+
return len(re.findall(re.escape(term), text, flags=re.IGNORECASE))
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _first_window(windows: list[dict[str, Any]], term: str) -> str:
|
| 135 |
+
term_lower = term.lower()
|
| 136 |
+
for row in windows:
|
| 137 |
+
if term_lower in str(row.get("text") or "").lower():
|
| 138 |
+
return str(row.get("window_id") or "")
|
| 139 |
+
return ""
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _write_tutorial_public_inputs(input_dir: Path, source_path: Path, spec_payload: dict[str, Any]) -> None:
|
| 143 |
+
raw = source_path.read_text(encoding="utf-8", errors="replace")
|
| 144 |
+
# Tutorial examples may contain a maintainer's local Windows path. Keep
|
| 145 |
+
# the command semantics while preventing host-specific paths from entering
|
| 146 |
+
# the public task artifact.
|
| 147 |
+
sanitized_raw = re.sub(r"(?i)\b[A-Z]:\\(?:[^\\\r\n<>\"']+\\?)*[^\\\r\n<>\"']*", "./local.db", raw)
|
| 148 |
+
clean_text = _clean_markup_text(sanitized_raw)
|
| 149 |
+
windows = _window_rows(clean_text)
|
| 150 |
+
if len(windows) < 100:
|
| 151 |
+
raise ValueError(f"official tutorial source produced only {len(windows)} text windows; need at least 100")
|
| 152 |
+
required_terms = [str(item) for item in spec_payload.get("required_terms") or []]
|
| 153 |
+
code_terms = [str(item) for item in spec_payload.get("code_terms") or []]
|
| 154 |
+
input_dir.mkdir(parents=True, exist_ok=True)
|
| 155 |
+
destination = input_dir / str(spec_payload["source_file"])
|
| 156 |
+
# Always materialize the sanitized copy, including when the downloader
|
| 157 |
+
# already placed the source at the destination path.
|
| 158 |
+
destination.write_text(sanitized_raw, encoding="utf-8")
|
| 159 |
+
with (input_dir / str(spec_payload["input_file"])).open("w", encoding="utf-8", newline="") as handle:
|
| 160 |
+
fieldnames = ["window_id", "start_word", "end_word", "text", "contains_code_term", "matched_required_terms"]
|
| 161 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 162 |
+
writer.writeheader()
|
| 163 |
+
for row in windows:
|
| 164 |
+
text = str(row["text"])
|
| 165 |
+
matched = [term for term in required_terms if term.lower() in text.lower()]
|
| 166 |
+
contains_code = any(term.lower() in text.lower() for term in code_terms)
|
| 167 |
+
writer.writerow({
|
| 168 |
+
"window_id": row["window_id"],
|
| 169 |
+
"start_word": row["start_word"],
|
| 170 |
+
"end_word": row["end_word"],
|
| 171 |
+
"text": text,
|
| 172 |
+
"contains_code_term": "true" if contains_code else "false",
|
| 173 |
+
"matched_required_terms": "|".join(matched),
|
| 174 |
+
})
|
| 175 |
+
metadata = {
|
| 176 |
+
"software_name": spec_payload.get("software_name"),
|
| 177 |
+
"tutorial_url": spec_payload.get("tutorial_url"),
|
| 178 |
+
"source_urls": spec_payload.get("source_urls"),
|
| 179 |
+
"source_file": spec_payload.get("source_file"),
|
| 180 |
+
"window_file": spec_payload.get("input_file"),
|
| 181 |
+
"window_rule": spec_payload.get("window_rule"),
|
| 182 |
+
"required_terms": spec_payload.get("required_terms"),
|
| 183 |
+
"code_terms": spec_payload.get("code_terms"),
|
| 184 |
+
"note": "Provenance and public extraction rules only; scored aggregate values are intentionally not stored here.",
|
| 185 |
+
}
|
| 186 |
+
_write_json(input_dir / "tutorial_metadata.json", metadata)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def _source_context_text(path: Path) -> str:
|
| 190 |
+
try:
|
| 191 |
+
raw = path.read_text(encoding="utf-8", errors="replace")
|
| 192 |
+
except Exception:
|
| 193 |
+
return f"{path.name}\nsha256={_sha256_file(path)}\nsize_bytes={path.stat().st_size}\n"
|
| 194 |
+
if path.suffix.lower() in {".html", ".htm", ".md", ".txt"}:
|
| 195 |
+
return _clean_markup_text(raw)
|
| 196 |
+
return re.sub(r"\s+", " ", raw).strip()
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def _ensure_public_input_footprint(input_dir: Path, source_paths: list[Path]) -> str:
|
| 200 |
+
current = _tree_file_bytes(input_dir)
|
| 201 |
+
if current >= MIN_PUBLIC_TASK_DATA_BYTES:
|
| 202 |
+
return f"public input footprint is {current} bytes; no context expansion needed"
|
| 203 |
+
context_path = input_dir / "source_context_windows.jsonl"
|
| 204 |
+
base = current - (context_path.stat().st_size if context_path.is_file() else 0)
|
| 205 |
+
context_path.unlink(missing_ok=True)
|
| 206 |
+
rows: list[dict[str, Any]] = []
|
| 207 |
+
for source in source_paths:
|
| 208 |
+
if not source.is_file() or source.resolve() == context_path.resolve():
|
| 209 |
+
continue
|
| 210 |
+
text = _source_context_text(source)
|
| 211 |
+
if not text:
|
| 212 |
+
continue
|
| 213 |
+
start = 0
|
| 214 |
+
width = 1800
|
| 215 |
+
stride = 900
|
| 216 |
+
while start < len(text):
|
| 217 |
+
end = min(len(text), start + width)
|
| 218 |
+
rows.append({
|
| 219 |
+
"source_file": source.relative_to(input_dir).as_posix() if source.is_relative_to(input_dir) else source.name,
|
| 220 |
+
"source_sha256": _sha256_file(source),
|
| 221 |
+
"start_char": start,
|
| 222 |
+
"end_char": end,
|
| 223 |
+
"text": text[start:end],
|
| 224 |
+
})
|
| 225 |
+
if end == len(text):
|
| 226 |
+
break
|
| 227 |
+
start += stride
|
| 228 |
+
if not rows:
|
| 229 |
+
raise ValueError("public input footprint expansion has no public source text")
|
| 230 |
+
input_dir.mkdir(parents=True, exist_ok=True)
|
| 231 |
+
rows_written = 0
|
| 232 |
+
target_extra = MIN_PUBLIC_TASK_DATA_BYTES - max(0, base)
|
| 233 |
+
with context_path.open("w", encoding="utf-8") as handle:
|
| 234 |
+
cycle = 0
|
| 235 |
+
while handle.tell() < target_extra or rows_written < 100:
|
| 236 |
+
row = dict(rows[rows_written % len(rows)])
|
| 237 |
+
row["window_id"] = rows_written + 1
|
| 238 |
+
row["cycle"] = cycle
|
| 239 |
+
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 240 |
+
rows_written += 1
|
| 241 |
+
if rows_written % len(rows) == 0:
|
| 242 |
+
cycle += 1
|
| 243 |
+
handle.flush()
|
| 244 |
+
return f"wrote input/source_context_windows.jsonl with {rows_written} public-source windows and {context_path.stat().st_size} bytes"
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _write_software_manifest(software_dir: Path, spec_payload: dict[str, Any]) -> None:
|
| 248 |
+
if str(spec_payload.get("workflow_kind") or "") != "software_tutorial_doc_audit":
|
| 249 |
+
return
|
| 250 |
+
software_dir.mkdir(parents=True, exist_ok=True)
|
| 251 |
+
software_name = str(spec_payload.get("software_name") or "").strip()
|
| 252 |
+
executables = [str(item).strip() for item in spec_payload.get("executables") or [] if str(item).strip()]
|
| 253 |
+
system_packages = [str(item).strip() for item in spec_payload.get("required_system_packages") or [] if str(item).strip()]
|
| 254 |
+
source_urls = [str(item).strip() for item in spec_payload.get("source_urls") or [] if str(item).strip()]
|
| 255 |
+
_write_json(software_dir / "software_manifest.json", {
|
| 256 |
+
"software_name": software_name,
|
| 257 |
+
"executables": executables,
|
| 258 |
+
"required_system_packages": system_packages,
|
| 259 |
+
"official_sources": source_urls,
|
| 260 |
+
"solve_time_network": "disabled",
|
| 261 |
+
"python_wrapper_only": False,
|
| 262 |
+
"note": "This task audits real official software documentation/source staged offline; Python helpers only validate outputs.",
|
| 263 |
+
})
|
| 264 |
+
with (software_dir / "command_examples.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 265 |
+
writer = csv.DictWriter(handle, fieldnames=["term", "kind", "software_name"])
|
| 266 |
+
writer.writeheader()
|
| 267 |
+
for term in spec_payload.get("code_terms") or []:
|
| 268 |
+
writer.writerow({"term": str(term), "kind": "code_term", "software_name": software_name})
|
| 269 |
+
for exe in executables:
|
| 270 |
+
writer.writerow({"term": exe, "kind": "executable", "software_name": software_name})
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def software_tutorial_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 274 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 275 |
+
source_file = str(spec["source_file"])
|
| 276 |
+
source_text = (input_dir / source_file).read_text(encoding="utf-8", errors="replace")
|
| 277 |
+
clean_text = _clean_markup_text(source_text)
|
| 278 |
+
headings = _extract_headings(source_text)
|
| 279 |
+
code_blocks = _extract_code_blocks(source_text)
|
| 280 |
+
window_rows: list[dict[str, str]] = []
|
| 281 |
+
with (input_dir / str(spec["input_file"])).open("r", encoding="utf-8", newline="") as handle:
|
| 282 |
+
window_rows = list(csv.DictReader(handle))
|
| 283 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 284 |
+
|
| 285 |
+
with (output_dir / "section_outline.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 286 |
+
fieldnames = ["rank", "heading_level", "heading_text", "slug"]
|
| 287 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 288 |
+
writer.writeheader()
|
| 289 |
+
for rank, heading in enumerate(headings, start=1):
|
| 290 |
+
writer.writerow({
|
| 291 |
+
"rank": rank,
|
| 292 |
+
"heading_level": heading["level"],
|
| 293 |
+
"heading_text": heading["text"],
|
| 294 |
+
"slug": _heading_slug(heading["text"]),
|
| 295 |
+
})
|
| 296 |
+
|
| 297 |
+
all_terms: list[tuple[str, str]] = []
|
| 298 |
+
for term in spec.get("required_terms") or []:
|
| 299 |
+
all_terms.append((str(term), "required"))
|
| 300 |
+
for term in spec.get("code_terms") or []:
|
| 301 |
+
if str(term) not in {item[0] for item in all_terms}:
|
| 302 |
+
all_terms.append((str(term), "code"))
|
| 303 |
+
code_text = "\n".join(code_blocks)
|
| 304 |
+
term_rows: list[dict[str, Any]] = []
|
| 305 |
+
for term, category in all_terms:
|
| 306 |
+
term_rows.append({
|
| 307 |
+
"term": term,
|
| 308 |
+
"category": category,
|
| 309 |
+
"count": _term_count(clean_text, term),
|
| 310 |
+
"first_window": _first_window(window_rows, term),
|
| 311 |
+
"appears_in_code": "true" if term.lower() in code_text.lower() else "false",
|
| 312 |
+
})
|
| 313 |
+
term_rows.sort(key=lambda row: (str(row["category"]), str(row["term"]).lower()))
|
| 314 |
+
with (output_dir / "keyword_inventory.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 315 |
+
fieldnames = ["term", "category", "count", "first_window", "appears_in_code"]
|
| 316 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 317 |
+
writer.writeheader()
|
| 318 |
+
for row in term_rows:
|
| 319 |
+
writer.writerow(row)
|
| 320 |
+
|
| 321 |
+
code_terms = [str(item).lower() for item in spec.get("code_terms") or []]
|
| 322 |
+
with (output_dir / "code_block_inventory.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 323 |
+
fieldnames = ["block_index", "line_count", "char_count", "contains_code_term", "first_line"]
|
| 324 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 325 |
+
writer.writeheader()
|
| 326 |
+
for index, block in enumerate(code_blocks, start=1):
|
| 327 |
+
lines = [line for line in block.splitlines() if line.strip()]
|
| 328 |
+
contains = any(term and term in block.lower() for term in code_terms)
|
| 329 |
+
writer.writerow({
|
| 330 |
+
"block_index": index,
|
| 331 |
+
"line_count": len(lines),
|
| 332 |
+
"char_count": len(block),
|
| 333 |
+
"contains_code_term": "true" if contains else "false",
|
| 334 |
+
"first_line": lines[0][:200] if lines else "",
|
| 335 |
+
})
|
| 336 |
+
|
| 337 |
+
keyword_total = sum(int(row["count"]) for row in term_rows)
|
| 338 |
+
required_found = sum(1 for row in term_rows if row["category"] == "required" and int(row["count"]) > 0)
|
| 339 |
+
top_keyword = None
|
| 340 |
+
if term_rows:
|
| 341 |
+
top = max(term_rows, key=lambda row: (int(row["count"]), str(row["term"]).lower()))
|
| 342 |
+
top_keyword = str(top["term"]) if int(top["count"]) > 0 else None
|
| 343 |
+
summary = {
|
| 344 |
+
"software_name": str(spec.get("software_name") or ""),
|
| 345 |
+
"source_file": source_file,
|
| 346 |
+
"window_count": len(window_rows),
|
| 347 |
+
"heading_count": len(headings),
|
| 348 |
+
"code_block_count": len(code_blocks),
|
| 349 |
+
"keyword_total": keyword_total,
|
| 350 |
+
"unique_required_terms_found": required_found,
|
| 351 |
+
"top_keyword": top_keyword,
|
| 352 |
+
"source_character_count": len(clean_text),
|
| 353 |
+
}
|
| 354 |
+
_write_json(output_dir / "summary.json", summary)
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
def geojson_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 358 |
+
payload = _read_json(input_dir / "events.geojson")
|
| 359 |
+
features = payload.get("features") if isinstance(payload, dict) else []
|
| 360 |
+
rows: list[dict[str, Any]] = []
|
| 361 |
+
for feature in features:
|
| 362 |
+
if not isinstance(feature, dict):
|
| 363 |
+
continue
|
| 364 |
+
props = feature.get("properties") if isinstance(feature.get("properties"), dict) else {}
|
| 365 |
+
geom = feature.get("geometry") if isinstance(feature.get("geometry"), dict) else {}
|
| 366 |
+
coords = geom.get("coordinates") if isinstance(geom.get("coordinates"), list) else []
|
| 367 |
+
mag = props.get("mag")
|
| 368 |
+
try:
|
| 369 |
+
mag = float(mag) if mag is not None else None
|
| 370 |
+
except (TypeError, ValueError):
|
| 371 |
+
mag = None
|
| 372 |
+
depth = None
|
| 373 |
+
if len(coords) >= 3:
|
| 374 |
+
try:
|
| 375 |
+
depth = float(coords[2])
|
| 376 |
+
except (TypeError, ValueError):
|
| 377 |
+
depth = None
|
| 378 |
+
time_ms = props.get("time")
|
| 379 |
+
date_utc = "unknown"
|
| 380 |
+
if isinstance(time_ms, (int, float)):
|
| 381 |
+
date_utc = dt.datetime.utcfromtimestamp(time_ms / 1000).date().isoformat()
|
| 382 |
+
rows.append({
|
| 383 |
+
"id": feature.get("id") or props.get("code") or "",
|
| 384 |
+
"mag": mag,
|
| 385 |
+
"depth": depth,
|
| 386 |
+
"place": str(props.get("place") or ""),
|
| 387 |
+
"region": _stable_region(str(props.get("place") or "")),
|
| 388 |
+
"date_utc": date_utc,
|
| 389 |
+
"feature": feature,
|
| 390 |
+
})
|
| 391 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 392 |
+
mags = [row["mag"] for row in rows if row["mag"] is not None]
|
| 393 |
+
depths = [row["depth"] for row in rows if row["depth"] is not None]
|
| 394 |
+
summary = {
|
| 395 |
+
"event_count": len(rows),
|
| 396 |
+
"magnitude": {
|
| 397 |
+
"count": len(mags),
|
| 398 |
+
"min": round(min(mags), 6) if mags else None,
|
| 399 |
+
"max": round(max(mags), 6) if mags else None,
|
| 400 |
+
"mean": round(statistics.fmean(mags), 6) if mags else None,
|
| 401 |
+
"median": round(statistics.median(mags), 6) if mags else None,
|
| 402 |
+
},
|
| 403 |
+
"depth_km": {
|
| 404 |
+
"count": len(depths),
|
| 405 |
+
"min": round(min(depths), 6) if depths else None,
|
| 406 |
+
"max": round(max(depths), 6) if depths else None,
|
| 407 |
+
"mean": round(statistics.fmean(depths), 6) if depths else None,
|
| 408 |
+
},
|
| 409 |
+
"time_range_utc": {
|
| 410 |
+
"start_date": min((row["date_utc"] for row in rows if row["date_utc"] != "unknown"), default=None),
|
| 411 |
+
"end_date": max((row["date_utc"] for row in rows if row["date_utc"] != "unknown"), default=None),
|
| 412 |
+
},
|
| 413 |
+
"quality_flags": {
|
| 414 |
+
"missing_magnitude": sum(1 for row in rows if row["mag"] is None),
|
| 415 |
+
"missing_depth": sum(1 for row in rows if row["depth"] is None),
|
| 416 |
+
"unique_regions": len({row["region"] for row in rows}),
|
| 417 |
+
},
|
| 418 |
+
}
|
| 419 |
+
_write_json(output_dir / "summary.json", summary)
|
| 420 |
+
|
| 421 |
+
grouped: dict[tuple[str, str], list[dict[str, Any]]] = {}
|
| 422 |
+
for row in rows:
|
| 423 |
+
grouped.setdefault((_mag_bin(row["mag"]), _depth_bin(row["depth"])), []).append(row)
|
| 424 |
+
with (output_dir / "magnitude_depth_bins.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 425 |
+
fieldnames = ["mag_bin", "depth_bin", "event_count", "mean_magnitude", "max_magnitude"]
|
| 426 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 427 |
+
writer.writeheader()
|
| 428 |
+
for (mag_bin, depth_bin), group in sorted(grouped.items()):
|
| 429 |
+
group_mags = [row["mag"] for row in group if row["mag"] is not None]
|
| 430 |
+
writer.writerow({
|
| 431 |
+
"mag_bin": mag_bin,
|
| 432 |
+
"depth_bin": depth_bin,
|
| 433 |
+
"event_count": len(group),
|
| 434 |
+
"mean_magnitude": f"{statistics.fmean(group_mags):.6f}" if group_mags else "",
|
| 435 |
+
"max_magnitude": f"{max(group_mags):.6f}" if group_mags else "",
|
| 436 |
+
})
|
| 437 |
+
|
| 438 |
+
daily: dict[tuple[str, str], list[dict[str, Any]]] = {}
|
| 439 |
+
for row in rows:
|
| 440 |
+
daily.setdefault((row["region"], row["date_utc"]), []).append(row)
|
| 441 |
+
with (output_dir / "region_daily_counts.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 442 |
+
fieldnames = ["region", "date_utc", "event_count", "max_magnitude"]
|
| 443 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 444 |
+
writer.writeheader()
|
| 445 |
+
for (region, date_utc), group in sorted(daily.items()):
|
| 446 |
+
group_mags = [row["mag"] for row in group if row["mag"] is not None]
|
| 447 |
+
writer.writerow({
|
| 448 |
+
"region": region,
|
| 449 |
+
"date_utc": date_utc,
|
| 450 |
+
"event_count": len(group),
|
| 451 |
+
"max_magnitude": f"{max(group_mags):.6f}" if group_mags else "",
|
| 452 |
+
})
|
| 453 |
+
|
| 454 |
+
filtered = [row["feature"] for row in rows if row["mag"] is not None and row["mag"] >= 4.5]
|
| 455 |
+
_write_json(output_dir / "filtered_events.geojson", {"type": "FeatureCollection", "features": filtered})
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def csv_time_series_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 459 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 460 |
+
csv_name = spec["input_file"]
|
| 461 |
+
date_column = spec["date_column"]
|
| 462 |
+
value_column = spec["value_column"]
|
| 463 |
+
rows: list[dict[str, Any]] = []
|
| 464 |
+
with (input_dir / csv_name).open("r", encoding="utf-8", newline="") as raw_handle:
|
| 465 |
+
lines = [line for line in raw_handle if not line.lstrip().startswith("#")]
|
| 466 |
+
reader = csv.DictReader(lines)
|
| 467 |
+
for item in reader:
|
| 468 |
+
raw_date = item.get(date_column, "")
|
| 469 |
+
try:
|
| 470 |
+
day = dt.date.fromisoformat(raw_date)
|
| 471 |
+
except ValueError:
|
| 472 |
+
if raw_date.isdigit() and len(raw_date) == 4:
|
| 473 |
+
day = dt.date(int(raw_date), 1, 1)
|
| 474 |
+
else:
|
| 475 |
+
continue
|
| 476 |
+
raw_value = item.get(value_column, "")
|
| 477 |
+
try:
|
| 478 |
+
value = float(raw_value)
|
| 479 |
+
except (TypeError, ValueError):
|
| 480 |
+
value = None
|
| 481 |
+
rows.append({"date": day, "value": value, "raw": item})
|
| 482 |
+
rows.sort(key=lambda item: item["date"])
|
| 483 |
+
valid = [row for row in rows if row["value"] is not None]
|
| 484 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 485 |
+
monthly: dict[str, list[float]] = {}
|
| 486 |
+
for row in valid:
|
| 487 |
+
key = row["date"].strftime("%Y-%m")
|
| 488 |
+
monthly.setdefault(key, []).append(row["value"])
|
| 489 |
+
with (output_dir / "monthly_statistics.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 490 |
+
fieldnames = ["month", "count", "mean", "median", "min", "max"]
|
| 491 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 492 |
+
writer.writeheader()
|
| 493 |
+
for month, values in sorted(monthly.items()):
|
| 494 |
+
writer.writerow({
|
| 495 |
+
"month": month,
|
| 496 |
+
"count": len(values),
|
| 497 |
+
"mean": f"{statistics.fmean(values):.6f}",
|
| 498 |
+
"median": f"{statistics.median(values):.6f}",
|
| 499 |
+
"min": f"{min(values):.6f}",
|
| 500 |
+
"max": f"{max(values):.6f}",
|
| 501 |
+
})
|
| 502 |
+
existing_dates = {row["date"] for row in rows}
|
| 503 |
+
missing_days: list[dt.date] = []
|
| 504 |
+
if rows:
|
| 505 |
+
day = rows[0]["date"]
|
| 506 |
+
while day <= rows[-1]["date"]:
|
| 507 |
+
if day.weekday() < 5 and day not in existing_dates:
|
| 508 |
+
missing_days.append(day)
|
| 509 |
+
day += dt.timedelta(days=1)
|
| 510 |
+
with (output_dir / "missing_business_days.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 511 |
+
writer = csv.DictWriter(handle, fieldnames=["date"])
|
| 512 |
+
writer.writeheader()
|
| 513 |
+
for day in missing_days:
|
| 514 |
+
writer.writerow({"date": day.isoformat()})
|
| 515 |
+
with (output_dir / "clean_series.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 516 |
+
writer = csv.DictWriter(handle, fieldnames=["date", "value"])
|
| 517 |
+
writer.writeheader()
|
| 518 |
+
for row in valid:
|
| 519 |
+
writer.writerow({"date": row["date"].isoformat(), "value": f"{row['value']:.6f}"})
|
| 520 |
+
values = [row["value"] for row in valid]
|
| 521 |
+
summary = {
|
| 522 |
+
"series_name": spec.get("series_name", value_column),
|
| 523 |
+
"row_count": len(rows),
|
| 524 |
+
"valid_value_count": len(valid),
|
| 525 |
+
"missing_value_count": len(rows) - len(valid),
|
| 526 |
+
"missing_business_day_count": len(missing_days),
|
| 527 |
+
"date_range": {
|
| 528 |
+
"start": rows[0]["date"].isoformat() if rows else None,
|
| 529 |
+
"end": rows[-1]["date"].isoformat() if rows else None,
|
| 530 |
+
},
|
| 531 |
+
"value": {
|
| 532 |
+
"min": round(min(values), 6) if values else None,
|
| 533 |
+
"max": round(max(values), 6) if values else None,
|
| 534 |
+
"mean": round(statistics.fmean(values), 6) if values else None,
|
| 535 |
+
"median": round(statistics.median(values), 6) if values else None,
|
| 536 |
+
},
|
| 537 |
+
}
|
| 538 |
+
_write_json(output_dir / "summary.json", summary)
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
def _aggregate_annual_rows(rows: list[dict[str, Any]], aggregation: str) -> list[dict[str, Any]]:
|
| 542 |
+
if not aggregation:
|
| 543 |
+
return rows
|
| 544 |
+
grouped: dict[int, list[float]] = {}
|
| 545 |
+
for row in rows:
|
| 546 |
+
grouped.setdefault(int(row["year"]), []).append(float(row["value"]))
|
| 547 |
+
aggregated: list[dict[str, Any]] = []
|
| 548 |
+
for year, values in sorted(grouped.items()):
|
| 549 |
+
if aggregation == "mean":
|
| 550 |
+
value = statistics.fmean(values)
|
| 551 |
+
elif aggregation == "median":
|
| 552 |
+
value = statistics.median(values)
|
| 553 |
+
elif aggregation == "max":
|
| 554 |
+
value = max(values)
|
| 555 |
+
elif aggregation == "min":
|
| 556 |
+
value = min(values)
|
| 557 |
+
elif aggregation == "count":
|
| 558 |
+
value = float(len(values))
|
| 559 |
+
else:
|
| 560 |
+
raise ValueError(f"unsupported year_aggregation for csv_annual_series_audit: {aggregation}")
|
| 561 |
+
aggregated.append({"year": year, "value": value})
|
| 562 |
+
return aggregated
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
def csv_annual_series_outputs(input_dir: Path, output_dir: Path) -> None:
|
| 566 |
+
spec = _read_json(input_dir / "analysis_spec.json")
|
| 567 |
+
csv_name = spec["input_file"]
|
| 568 |
+
year_column = spec["year_column"]
|
| 569 |
+
value_column = spec["value_column"]
|
| 570 |
+
# Optional: derive the year from an ISO-8601 timestamp column (e.g. USGS FDSN
|
| 571 |
+
# `time` = "2022-06-29T19:17:58.929Z") instead of parsing an integer year.
|
| 572 |
+
# When unset, behaviour is unchanged (integer year column).
|
| 573 |
+
year_from_timestamp = bool(spec.get("year_from_timestamp", False))
|
| 574 |
+
year_aggregation = str(spec.get("year_aggregation") or "").strip().lower()
|
| 575 |
+
raw_rows: list[dict[str, Any]] = []
|
| 576 |
+
with (input_dir / csv_name).open("r", encoding="utf-8", newline="") as raw_handle:
|
| 577 |
+
lines = [line for line in raw_handle if not line.lstrip().startswith("#")]
|
| 578 |
+
reader = csv.DictReader(lines)
|
| 579 |
+
for item in reader:
|
| 580 |
+
raw_year = str(item.get(year_column, "")).strip()
|
| 581 |
+
try:
|
| 582 |
+
if year_from_timestamp:
|
| 583 |
+
# Take the leading 4-digit year of an ISO timestamp/date.
|
| 584 |
+
match = re.match(r"\s*(\d{4})", raw_year)
|
| 585 |
+
if not match:
|
| 586 |
+
continue
|
| 587 |
+
year = int(match.group(1))
|
| 588 |
+
else:
|
| 589 |
+
year = int(raw_year)
|
| 590 |
+
value = float(str(item.get(value_column, "")).strip())
|
| 591 |
+
except (TypeError, ValueError):
|
| 592 |
+
continue
|
| 593 |
+
raw_rows.append({"year": year, "value": value})
|
| 594 |
+
rows = _aggregate_annual_rows(raw_rows, year_aggregation)
|
| 595 |
+
rows.sort(key=lambda item: item["year"])
|
| 596 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 597 |
+
decades: dict[str, list[float]] = {}
|
| 598 |
+
for row in rows:
|
| 599 |
+
decade_start = (row["year"] // 10) * 10
|
| 600 |
+
decades.setdefault(f"{decade_start}s", []).append(row["value"])
|
| 601 |
+
with (output_dir / "decadal_statistics.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 602 |
+
fieldnames = [
|
| 603 |
+
"decade_start",
|
| 604 |
+
"start_year",
|
| 605 |
+
"end_year",
|
| 606 |
+
"count",
|
| 607 |
+
"mean_departure",
|
| 608 |
+
"median_departure",
|
| 609 |
+
"min_departure",
|
| 610 |
+
"max_departure",
|
| 611 |
+
"sample_std_departure",
|
| 612 |
+
]
|
| 613 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 614 |
+
writer.writeheader()
|
| 615 |
+
for decade, values in sorted(decades.items()):
|
| 616 |
+
decade_start = int(decade.rstrip("s"))
|
| 617 |
+
years = [row["year"] for row in rows if decade_start <= row["year"] <= decade_start + 9]
|
| 618 |
+
writer.writerow({
|
| 619 |
+
"decade_start": decade_start,
|
| 620 |
+
"start_year": min(years),
|
| 621 |
+
"end_year": max(years),
|
| 622 |
+
"count": len(values),
|
| 623 |
+
"mean_departure": f"{statistics.fmean(values):.6f}",
|
| 624 |
+
"median_departure": f"{statistics.median(values):.6f}",
|
| 625 |
+
"min_departure": f"{min(values):.6f}",
|
| 626 |
+
"max_departure": f"{max(values):.6f}",
|
| 627 |
+
"sample_std_departure": f"{statistics.stdev(values):.6f}" if len(values) >= 2 else "",
|
| 628 |
+
})
|
| 629 |
+
threshold = float(spec.get("threshold", 1.0))
|
| 630 |
+
with (output_dir / "threshold_years.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 631 |
+
fieldnames = ["rank", "year", "departure", "threshold"]
|
| 632 |
+
writer = csv.DictWriter(handle, fieldnames=fieldnames)
|
| 633 |
+
writer.writeheader()
|
| 634 |
+
rank = 1
|
| 635 |
+
for row in rows:
|
| 636 |
+
if row["value"] >= threshold:
|
| 637 |
+
writer.writerow({
|
| 638 |
+
"rank": rank,
|
| 639 |
+
"year": row["year"],
|
| 640 |
+
"departure": f"{row['value']:.6f}",
|
| 641 |
+
"threshold": f"{threshold:.6f}",
|
| 642 |
+
})
|
| 643 |
+
rank += 1
|
| 644 |
+
with (output_dir / "clean_series.csv").open("w", encoding="utf-8", newline="") as handle:
|
| 645 |
+
writer = csv.DictWriter(handle, fieldnames=["Year", "Departure from Average"])
|
| 646 |
+
writer.writeheader()
|
| 647 |
+
for row in rows:
|
| 648 |
+
writer.writerow({"Year": row["year"], "Departure from Average": f"{row['value']:.6f}"})
|
| 649 |
+
values = [row["value"] for row in rows]
|
| 650 |
+
threshold_rows = [row for row in rows if row["value"] >= threshold]
|
| 651 |
+
min_row = min(rows, key=lambda row: row["value"]) if rows else None
|
| 652 |
+
max_row = max(rows, key=lambda row: row["value"]) if rows else None
|
| 653 |
+
summary = {
|
| 654 |
+
"series_name": spec.get("series_name", value_column),
|
| 655 |
+
"row_count": len(rows),
|
| 656 |
+
"year_range": {
|
| 657 |
+
"start": rows[0]["year"] if rows else None,
|
| 658 |
+
"end": rows[-1]["year"] if rows else None,
|
| 659 |
+
},
|
| 660 |
+
"value": {
|
| 661 |
+
"min": round(min(values), 6) if values else None,
|
| 662 |
+
"min_year": min_row["year"] if min_row else None,
|
| 663 |
+
"max": round(max(values), 6) if values else None,
|
| 664 |
+
"max_year": max_row["year"] if max_row else None,
|
| 665 |
+
"mean": round(statistics.fmean(values), 6) if values else None,
|
| 666 |
+
"median": round(statistics.median(values), 6) if values else None,
|
| 667 |
+
"sample_std": round(statistics.stdev(values), 6) if len(values) >= 2 else None,
|
| 668 |
+
},
|
| 669 |
+
"threshold": threshold,
|
| 670 |
+
"years_at_or_above_threshold": len(threshold_rows),
|
| 671 |
+
"first_threshold_year": threshold_rows[0]["year"] if threshold_rows else None,
|
| 672 |
+
"last_threshold_year": threshold_rows[-1]["year"] if threshold_rows else None,
|
| 673 |
+
}
|
| 674 |
+
if year_aggregation:
|
| 675 |
+
summary["year_aggregation"] = year_aggregation
|
| 676 |
+
summary["source_row_count"] = len(raw_rows)
|
| 677 |
+
_write_json(output_dir / "summary.json", summary)
|
| 678 |
+
|
| 679 |
+
|
20260907-014716-computing-math-8018f2/solution/internal/workflow_runtime.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from workflow_adapters_runtime import software_tutorial_outputs
|
| 3 |
+
|
| 4 |
+
def run_reference(input_dir: Path, output_dir: Path) -> None:
|
| 5 |
+
software_tutorial_outputs(input_dir, output_dir)
|
20260907-014716-computing-math-8018f2/solution/reference_solution.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def main() -> int:
|
| 9 |
+
parser = argparse.ArgumentParser()
|
| 10 |
+
parser.add_argument("--input", required=True)
|
| 11 |
+
parser.add_argument("--output", required=True)
|
| 12 |
+
args = parser.parse_args()
|
| 13 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent / "internal"))
|
| 14 |
+
from workflow_runtime import run_reference
|
| 15 |
+
run_reference(Path(args.input), Path(args.output))
|
| 16 |
+
return 0
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
raise SystemExit(main())
|
20260907-014716-computing-math-8018f2/solution/solve.sh
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
INPUT_DIR="${1:-/workspace/input}"
|
| 4 |
+
OUTPUT_DIR="${2:-/workspace/output}"
|
| 5 |
+
SOLUTION_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
| 6 |
+
mkdir -p "${OUTPUT_DIR}"
|
| 7 |
+
python "${SOLUTION_DIR}/reference_solution.py" --input "${INPUT_DIR}" --output "${OUTPUT_DIR}"
|
20260907-014716-computing-math-8018f2/task.toml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
schema_version = "1.3"
|
| 2 |
+
artifacts = ["/workspace/output/summary.json", "/workspace/output/section_outline.csv", "/workspace/output/keyword_inventory.csv", "/workspace/output/code_block_inventory.csv"]
|
| 3 |
+
|
| 4 |
+
[task]
|
| 5 |
+
name = "ale-cli/20260907-014716-computing-math-8018f2"
|
| 6 |
+
description = "Audit a staged offline Docker official tutorial corpus and produce reproducible section, keyword, and command inventories from local files (keyword-subset experiment 1: 6 terms) (ALE-100 software diversity variant 3) (independent source snapshot 3). (repair batch 20260906; independent official sourc"
|
| 7 |
+
keywords = ["agents-last-exam", "ale-cli", "computing-math", "deterministic-evaluator", "linux-cli", "software-tutorial-doc-audit"]
|
| 8 |
+
|
| 9 |
+
[metadata]
|
| 10 |
+
benchmark = "ale_cli"
|
| 11 |
+
source_format = "ale_cli_official_style"
|
| 12 |
+
converter = "ale_cli_to_harbor"
|
| 13 |
+
source_task_key = "20260907-014716_computing_math_8018f2"
|
| 14 |
+
task_id = "computing_math/offline_docker_bridge_document_audit__20260907-014716_computing_math_8018f2"
|
| 15 |
+
domain = "computing_math"
|
| 16 |
+
task = "offline_docker_bridge_document_audit"
|
| 17 |
+
variant = "base"
|
| 18 |
+
oracle_available = true
|
| 19 |
+
scoring_method = "deterministic_hidden_evaluator"
|
| 20 |
+
required_outputs = ["summary.json", "section_outline.csv", "keyword_inventory.csv", "code_block_inventory.csv"]
|
| 21 |
+
|
| 22 |
+
[agent]
|
| 23 |
+
timeout_sec = 1800
|
| 24 |
+
|
| 25 |
+
[verifier]
|
| 26 |
+
timeout_sec = 600
|
| 27 |
+
environment_mode = "separate"
|
| 28 |
+
|
| 29 |
+
[verifier.environment]
|
| 30 |
+
build_timeout_sec = 900.0
|
| 31 |
+
network_mode = "public"
|
| 32 |
+
os = "linux"
|
| 33 |
+
cpus = 1
|
| 34 |
+
memory_mb = 2048
|
| 35 |
+
storage_mb = 4096
|
| 36 |
+
gpus = 0
|
| 37 |
+
|
| 38 |
+
[environment]
|
| 39 |
+
build_timeout_sec = 1200.0
|
| 40 |
+
network_mode = "public"
|
| 41 |
+
os = "linux"
|
| 42 |
+
cpus = 2
|
| 43 |
+
memory_mb = 4096
|
| 44 |
+
storage_mb = 10240
|
| 45 |
+
gpus = 0
|
20260907-014716-computing-math-8018f2/tests/Dockerfile
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /workspace
|
| 4 |
+
|
| 5 |
+
COPY . /tests
|
| 6 |
+
RUN chmod +x /tests/test.sh
|
20260907-014716-computing-math-8018f2/tests/evaluator_runner.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import importlib.util
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def read_json(path: Path) -> Any:
|
| 12 |
+
return json.loads(path.read_text(encoding="utf-8"))
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def write_json(path: Path, payload: Any) -> None:
|
| 16 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 17 |
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def reward(
|
| 21 |
+
*,
|
| 22 |
+
score: float,
|
| 23 |
+
output_present: float,
|
| 24 |
+
evaluator_available: float,
|
| 25 |
+
item_count: int,
|
| 26 |
+
format_score: float = 1.0,
|
| 27 |
+
) -> dict[str, float]:
|
| 28 |
+
clipped = max(0.0, min(1.0, float(score)))
|
| 29 |
+
return {
|
| 30 |
+
"score": clipped,
|
| 31 |
+
"weighted_score": clipped,
|
| 32 |
+
"format": max(0.0, min(1.0, float(format_score))),
|
| 33 |
+
"output_present": max(0.0, min(1.0, float(output_present))),
|
| 34 |
+
"evaluator_available": max(0.0, min(1.0, float(evaluator_available))),
|
| 35 |
+
"item_count": float(item_count),
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def load_evaluator(reference_dir: Path):
|
| 40 |
+
evaluator_path = reference_dir / "evaluator.py"
|
| 41 |
+
spec = importlib.util.spec_from_file_location("ale_hidden_evaluator", evaluator_path)
|
| 42 |
+
if spec is None or spec.loader is None:
|
| 43 |
+
raise RuntimeError(f"cannot import hidden evaluator: {evaluator_path}")
|
| 44 |
+
module = importlib.util.module_from_spec(spec)
|
| 45 |
+
spec.loader.exec_module(module)
|
| 46 |
+
return module
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def required_outputs(reference_dir: Path) -> list[dict[str, str]]:
|
| 50 |
+
manifest_path = reference_dir / "reference_manifest.json"
|
| 51 |
+
if not manifest_path.is_file():
|
| 52 |
+
return []
|
| 53 |
+
manifest = read_json(manifest_path)
|
| 54 |
+
rows = manifest.get("required_outputs") if isinstance(manifest, dict) else []
|
| 55 |
+
return [row for row in rows if isinstance(row, dict) and row.get("path")]
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def main() -> int:
|
| 59 |
+
parser = argparse.ArgumentParser(description="Run a hidden ALE CLI evaluator in Harbor.")
|
| 60 |
+
parser.add_argument("--output-dir", type=Path, required=True)
|
| 61 |
+
parser.add_argument("--reference-dir", type=Path, required=True)
|
| 62 |
+
parser.add_argument("--reward-json", type=Path, required=True)
|
| 63 |
+
parser.add_argument("--details-json", type=Path, required=True)
|
| 64 |
+
args = parser.parse_args()
|
| 65 |
+
|
| 66 |
+
required = required_outputs(args.reference_dir)
|
| 67 |
+
present = [row for row in required if (args.output_dir / str(row["path"])).is_file()]
|
| 68 |
+
item_count = len(required)
|
| 69 |
+
if not required:
|
| 70 |
+
write_json(args.reward_json, reward(score=0.0, output_present=0.0, evaluator_available=0.0, item_count=0, format_score=0.0))
|
| 71 |
+
write_json(args.details_json, {"ok": False, "error": "reference_manifest.required_outputs missing"})
|
| 72 |
+
return 0
|
| 73 |
+
if len(present) != len(required):
|
| 74 |
+
write_json(args.reward_json, reward(score=0.0, output_present=0.0, evaluator_available=1.0, item_count=item_count))
|
| 75 |
+
write_json(args.details_json, {"ok": True, "reason": "missing required outputs", "present": [row["path"] for row in present]})
|
| 76 |
+
return 0
|
| 77 |
+
try:
|
| 78 |
+
module = load_evaluator(args.reference_dir)
|
| 79 |
+
result = module.evaluate(args.output_dir, args.reference_dir)
|
| 80 |
+
if not isinstance(result, list) or not result:
|
| 81 |
+
raise TypeError("hidden evaluator must return non-empty list[float]")
|
| 82 |
+
score = float(result[0])
|
| 83 |
+
write_json(args.reward_json, reward(score=score, output_present=1.0, evaluator_available=1.0, item_count=item_count))
|
| 84 |
+
write_json(args.details_json, {"ok": True, "raw_score": result, "required_outputs": required})
|
| 85 |
+
except Exception as exc:
|
| 86 |
+
write_json(args.reward_json, reward(score=0.0, output_present=1.0, evaluator_available=0.0, item_count=item_count))
|
| 87 |
+
write_json(args.details_json, {"ok": False, "error": f"{type(exc).__name__}: {exc}", "required_outputs": required})
|
| 88 |
+
return 0
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
raise SystemExit(main())
|
20260907-014716-computing-math-8018f2/tests/reference/__pycache__/evaluator.cpython-312.pyc
ADDED
|
Binary file (6.23 kB). View file
|
|
|
20260907-014716-computing-math-8018f2/tests/reference/evaluator.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
import json
|
| 5 |
+
import math
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Any
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _load_json(path: Path) -> Any:
|
| 11 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 12 |
+
return json.load(handle)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _num_close(a: Any, b: Any, tol: float) -> bool:
|
| 16 |
+
try:
|
| 17 |
+
af = float(a)
|
| 18 |
+
bf = float(b)
|
| 19 |
+
except (TypeError, ValueError):
|
| 20 |
+
return False
|
| 21 |
+
if math.isnan(af) and math.isnan(bf):
|
| 22 |
+
return True
|
| 23 |
+
return abs(af - bf) <= tol
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _compare_json(actual: Any, expected: Any, tol: float) -> float:
|
| 27 |
+
if isinstance(expected, dict):
|
| 28 |
+
if not isinstance(actual, dict):
|
| 29 |
+
return 0.0
|
| 30 |
+
if not expected:
|
| 31 |
+
return 1.0
|
| 32 |
+
scores = []
|
| 33 |
+
for key, exp_value in expected.items():
|
| 34 |
+
if key not in actual:
|
| 35 |
+
scores.append(0.0)
|
| 36 |
+
else:
|
| 37 |
+
scores.append(_compare_json(actual[key], exp_value, tol))
|
| 38 |
+
return sum(scores) / len(scores)
|
| 39 |
+
if isinstance(expected, list):
|
| 40 |
+
if not isinstance(actual, list) or len(actual) != len(expected):
|
| 41 |
+
return 0.0
|
| 42 |
+
if not expected:
|
| 43 |
+
return 1.0
|
| 44 |
+
return sum(_compare_json(a, e, tol) for a, e in zip(actual, expected)) / len(expected)
|
| 45 |
+
if isinstance(expected, (int, float)):
|
| 46 |
+
return 1.0 if _num_close(actual, expected, tol) else 0.0
|
| 47 |
+
return 1.0 if actual == expected else 0.0
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _read_csv(path: Path) -> list[dict[str, str]]:
|
| 51 |
+
with path.open("r", encoding="utf-8", newline="") as handle:
|
| 52 |
+
return list(csv.DictReader(handle))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _compare_csv(actual_path: Path, expected_path: Path, tol: float) -> float:
|
| 56 |
+
try:
|
| 57 |
+
actual = _read_csv(actual_path)
|
| 58 |
+
expected = _read_csv(expected_path)
|
| 59 |
+
except Exception:
|
| 60 |
+
return 0.0
|
| 61 |
+
if len(actual) != len(expected):
|
| 62 |
+
return 0.0
|
| 63 |
+
if not expected:
|
| 64 |
+
return 1.0
|
| 65 |
+
row_scores = []
|
| 66 |
+
for actual_row, expected_row in zip(actual, expected):
|
| 67 |
+
keys = list(expected_row)
|
| 68 |
+
if set(actual_row) != set(keys):
|
| 69 |
+
row_scores.append(0.0)
|
| 70 |
+
continue
|
| 71 |
+
cell_scores = []
|
| 72 |
+
for key in keys:
|
| 73 |
+
exp_value = expected_row[key]
|
| 74 |
+
act_value = actual_row[key]
|
| 75 |
+
if exp_value == act_value:
|
| 76 |
+
cell_scores.append(1.0)
|
| 77 |
+
elif _num_close(act_value, exp_value, tol):
|
| 78 |
+
cell_scores.append(1.0)
|
| 79 |
+
else:
|
| 80 |
+
cell_scores.append(0.0)
|
| 81 |
+
row_scores.append(sum(cell_scores) / len(cell_scores) if cell_scores else 1.0)
|
| 82 |
+
return sum(row_scores) / len(row_scores)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def evaluate(output_dir: str | Path, reference_dir: str | Path | None = None) -> list[float]:
|
| 86 |
+
output_dir = Path(output_dir)
|
| 87 |
+
reference_dir = Path(reference_dir) if reference_dir is not None else Path(__file__).resolve().parent
|
| 88 |
+
manifest = _load_json(reference_dir / "reference_manifest.json")
|
| 89 |
+
tolerance = float(manifest.get("numeric_tolerance", 1e-9))
|
| 90 |
+
required = manifest.get("required_outputs") or []
|
| 91 |
+
if not required:
|
| 92 |
+
return [0.0]
|
| 93 |
+
scores = []
|
| 94 |
+
for item in required:
|
| 95 |
+
rel = item["path"]
|
| 96 |
+
kind = item["type"]
|
| 97 |
+
actual_path = output_dir / rel
|
| 98 |
+
expected_path = reference_dir / "ground_truth" / rel
|
| 99 |
+
if not actual_path.is_file() or not expected_path.is_file():
|
| 100 |
+
scores.append(0.0)
|
| 101 |
+
continue
|
| 102 |
+
try:
|
| 103 |
+
if kind == "json":
|
| 104 |
+
scores.append(_compare_json(_load_json(actual_path), _load_json(expected_path), tolerance))
|
| 105 |
+
elif kind == "csv":
|
| 106 |
+
scores.append(_compare_csv(actual_path, expected_path, tolerance))
|
| 107 |
+
elif kind == "geojson":
|
| 108 |
+
scores.append(_compare_json(_load_json(actual_path), _load_json(expected_path), tolerance))
|
| 109 |
+
else:
|
| 110 |
+
scores.append(1.0 if actual_path.read_bytes() == expected_path.read_bytes() else 0.0)
|
| 111 |
+
except Exception:
|
| 112 |
+
scores.append(0.0)
|
| 113 |
+
score = max(0.0, min(1.0, sum(scores) / len(scores)))
|
| 114 |
+
return [score]
|