Skip to content

Commit 9f6fbf7

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a8369be commit 9f6fbf7

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

repo2docker/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
RBuildPack,
3838
)
3939
from .engine import BuildError, ContainerEngineException, ImageLoadError
40-
from .utils import ByteSpecification, R2dState, chdir, get_platform, get_free_port
40+
from .utils import ByteSpecification, R2dState, chdir, get_free_port, get_platform
4141

4242

4343
class Repo2Docker(Application):
@@ -744,7 +744,6 @@ def wait_for_container(self, container):
744744
if exit_code:
745745
sys.exit(exit_code)
746746

747-
748747
def find_image(self):
749748
# if this is a dry run it is Ok for dockerd to be unreachable so we
750749
# always return False for dry runs.

repo2docker/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2-
import socket
32
import platform
43
import re
4+
import socket
55
import subprocess
66
import warnings
77
from contextlib import contextmanager
@@ -556,4 +556,4 @@ def get_free_port():
556556
s.bind(("", 0))
557557
port = s.getsockname()[1]
558558
s.close()
559-
return port
559+
return port

tests/registry/test_registry.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import os
2+
import secrets
23
import socket
3-
from pathlib import Path
44
import subprocess
5+
import time
6+
from pathlib import Path
7+
58
import pytest
9+
import requests
10+
611
from repo2docker.__main__ import make_r2d
712
from repo2docker.utils import get_free_port
8-
import time
9-
import requests
10-
import secrets
1113

1214
HERE = Path(__file__).parent
1315

16+
1417
@pytest.fixture(scope="session")
1518
def dind(registry, host_ip):
1619
port = get_free_port()
@@ -21,11 +24,19 @@ def dind(registry, host_ip):
2124
# but also docker this is your own fucking fault for making technical choices that force dockerhub
2225
# to be the primary registry, so your registry handling sucks and forces these kinds of difficulties.
2326
cmd = [
24-
"docker", "run", "-e", 'DOCKER_TLS_CERTDIR=',
25-
"--privileged", "-p", f"{port}:2376", dind_image,
26-
"--host", "0.0.0.0:2376",
27-
"--insecure-registry", registry,
28-
"--tls=false"
27+
"docker",
28+
"run",
29+
"-e",
30+
"DOCKER_TLS_CERTDIR=",
31+
"--privileged",
32+
"-p",
33+
f"{port}:2376",
34+
dind_image,
35+
"--host",
36+
"0.0.0.0:2376",
37+
"--insecure-registry",
38+
registry,
39+
"--tls=false",
2940
]
3041
proc = subprocess.Popen(cmd)
3142
time.sleep(5)
@@ -36,6 +47,7 @@ def dind(registry, host_ip):
3647
proc.terminate()
3748
proc.wait()
3849

50+
3951
@pytest.fixture(scope="session")
4052
def host_ip():
4153
# Get the IP of the current machine, as we need to use the same IP
@@ -46,27 +58,24 @@ def host_ip():
4658
s.settimeout(0)
4759
try:
4860
# doesn't even have to be reachable
49-
s.connect(('10.254.254.254', 1))
61+
s.connect(("10.254.254.254", 1))
5062
host_ip = s.getsockname()[0]
5163
finally:
5264
s.close()
5365

5466
return host_ip
5567

68+
5669
@pytest.fixture(scope="session")
5770
def registry(host_ip):
5871
port = get_free_port()
5972
# Explicitly pull the image first so it runs on time
60-
registry_image = "registry:3.0.0-rc.3"
73+
registry_image = "registry:3.0.0-rc.3"
6174
subprocess.check_call(["docker", "pull", registry_image])
6275

63-
64-
cmd = [
65-
"docker", "run", "--rm",
66-
"-p", f"{port}:5000", registry_image
67-
]
76+
cmd = ["docker", "run", "--rm", "-p", f"{port}:5000", registry_image]
6877
proc = subprocess.Popen(cmd)
69-
health_url = f'http://{host_ip}:{port}/v2'
78+
health_url = f"http://{host_ip}:{port}/v2"
7079
# Wait for the registry to actually come up
7180
for i in range(10):
7281
try:
@@ -89,10 +98,7 @@ def registry(host_ip):
8998

9099
def test_registry(registry, dind):
91100
image_name = f"{registry}/{secrets.token_hex(8)}:latest"
92-
r2d = make_r2d([
93-
"--image", image_name,
94-
"--push", "--no-run", str(HERE)
95-
])
101+
r2d = make_r2d(["--image", image_name, "--push", "--no-run", str(HERE)])
96102

97103
os.environ["DOCKER_HOST"] = dind
98104
r2d.start()

0 commit comments

Comments
 (0)