Skip to content

Commit

Permalink
Enabling network for neard localnet docker run
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-near committed Feb 1, 2023
1 parent 699bfc5 commit b562141
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 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,14 +82,14 @@ 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]}']

Expand Down Expand Up @@ -187,14 +187,14 @@ 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'))
docker_run(cmd, volume=(dot_near, '/home/near'), network=True)

# Start all the nodes
for ordinal in range(NUM_NODES):
Expand Down

0 comments on commit b562141

Please sign in to comment.