Skip to content

Commit

Permalink
Enabling ipv6 when docker --network=none
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-near committed Feb 1, 2023
1 parent 699bfc5 commit 9223b68
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pytest/tests/sanity/docker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""Verifies that node can be started inside of a Docker image.
The script builds Docker image using make docker-nearcore command and then
The script builds Docker image using 'make docker-nearcore' command and then
starts a cluster with all nodes running inside of containers. As sanity check
to see if the cluster works correctly, the test waits for a several blocks and
then interrogates each node about block with specified hash expecting all of
Expand Down Expand Up @@ -48,7 +48,7 @@ def run(cmd: _Command, *, capture_output: bool = False) -> typing.Optional[str]:
capture_output: If true, captures standard output of the command and
returns it.
Returns:
Commands stripped standard output if `capture_output` is true, None
Command's stripped standard output if `capture_output` is true, None
otherwise.
"""
global _CD_PRINTED
Expand All @@ -73,7 +73,7 @@ def docker_run(shell_cmd: typing.Optional[str] = None,
Args:
shell_cmd: Optionally a shell command to execute inside of the
container. Its going to be run using `sh -c` and its callers
container. It's going to be run using `sh -c` and it's caller's
responsibility to make sure all data inside is properly sanitised.
If not given, command configured via CMD when building the container
will be executed as typical for Docker images.
Expand All @@ -82,16 +82,22 @@ def docker_run(shell_cmd: typing.Optional[str] = None,
test outputs. If True, the container will be detached and the
function will return its container id.
network: Whether to enable network. If True, the container will be
configured to use hosts network. This allows processes in
configured to use host's network. This allows processes in
different containers to connect with each other easily.
volume: A (path, container_path) tuple denoting that local `path` should
be mounted under `container_path` inside of the container.
env: *Additional* environment variables set inside of the container.
Returns:
Commands stripped standard output if `detach` is true, None otherwise.
Command's stripped standard output if `detach` is true, None otherwise.
"""
cmd = ['docker', 'run', '--read-only', f'-v{volume[0]}:{volume[1]}']

# When --network=none, ipv6 is disabled by default in docker images.
# Required as neard localnet is binding on V6 address instead of V4
cmd = [
'docker', 'run', '--read-only', f'-v{volume[0]}:{volume[1]}',
'--sysctl', 'net.ipv6.conf.all.disable_ipv6=0'
]

# Either run detached or attach standard output and standard error so they
# are visible.
Expand Down Expand Up @@ -187,12 +193,12 @@ def output_logs(self):
def main():
nodes = []

# Build the container
logger.info("Build the container")
run(('make', 'DOCKER_TAG=' + _DOCKER_IMAGE_TAG, 'docker-nearcore'))
try:
dot_near = pathlib.Path.home() / '.near'

# Initialise local network
logger.info("Initialise local network nodes config.")
cmd = f'neard --home /home/near localnet --v {NUM_NODES} --prefix test'
docker_run(cmd, volume=(dot_near, '/home/near'))

Expand Down

0 comments on commit 9223b68

Please sign in to comment.