1
1
import os
2
+ import secrets
2
3
import socket
3
- from pathlib import Path
4
4
import subprocess
5
+ import time
6
+ from pathlib import Path
7
+
5
8
import pytest
9
+ import requests
10
+
6
11
from repo2docker .__main__ import make_r2d
7
12
from repo2docker .utils import get_free_port
8
- import time
9
- import requests
10
- import secrets
11
13
12
14
HERE = Path (__file__ ).parent
13
15
16
+
14
17
@pytest .fixture (scope = "session" )
15
18
def dind (registry , host_ip ):
16
19
port = get_free_port ()
@@ -21,11 +24,19 @@ def dind(registry, host_ip):
21
24
# but also docker this is your own fucking fault for making technical choices that force dockerhub
22
25
# to be the primary registry, so your registry handling sucks and forces these kinds of difficulties.
23
26
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" ,
29
40
]
30
41
proc = subprocess .Popen (cmd )
31
42
time .sleep (5 )
@@ -36,6 +47,7 @@ def dind(registry, host_ip):
36
47
proc .terminate ()
37
48
proc .wait ()
38
49
50
+
39
51
@pytest .fixture (scope = "session" )
40
52
def host_ip ():
41
53
# Get the IP of the current machine, as we need to use the same IP
@@ -46,27 +58,24 @@ def host_ip():
46
58
s .settimeout (0 )
47
59
try :
48
60
# doesn't even have to be reachable
49
- s .connect ((' 10.254.254.254' , 1 ))
61
+ s .connect ((" 10.254.254.254" , 1 ))
50
62
host_ip = s .getsockname ()[0 ]
51
63
finally :
52
64
s .close ()
53
65
54
66
return host_ip
55
67
68
+
56
69
@pytest .fixture (scope = "session" )
57
70
def registry (host_ip ):
58
71
port = get_free_port ()
59
72
# 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"
61
74
subprocess .check_call (["docker" , "pull" , registry_image ])
62
75
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 ]
68
77
proc = subprocess .Popen (cmd )
69
- health_url = f' http://{ host_ip } :{ port } /v2'
78
+ health_url = f" http://{ host_ip } :{ port } /v2"
70
79
# Wait for the registry to actually come up
71
80
for i in range (10 ):
72
81
try :
@@ -89,10 +98,7 @@ def registry(host_ip):
89
98
90
99
def test_registry (registry , dind ):
91
100
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 )])
96
102
97
103
os .environ ["DOCKER_HOST" ] = dind
98
104
r2d .start ()
0 commit comments