@@ -11,9 +11,7 @@ import (
11
11
"slices"
12
12
"strings"
13
13
"testing"
14
- "time"
15
14
16
- "github.com/docker/docker/api/types"
17
15
"github.com/docker/docker/api/types/filters"
18
16
"github.com/docker/docker/pkg/jsonmessage"
19
17
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -26,83 +24,20 @@ import (
26
24
27
25
"github.com/docker/docker/api/types/image"
28
26
"github.com/docker/docker/client"
29
- "github.com/testcontainers/testcontainers-go"
30
- "github.com/testcontainers/testcontainers-go/wait"
31
27
)
32
28
33
29
func TestRegistryPushPull (t * testing.T ) {
34
30
ctx := context .Background ()
35
-
36
- // Start unregistry in a Docker-in-Docker container with Docker using containerd image store.
37
- req := testcontainers.GenericContainerRequest {
38
- ContainerRequest : testcontainers.ContainerRequest {
39
- FromDockerfile : testcontainers.FromDockerfile {
40
- Context : filepath .Join (".." , ".." ),
41
- Dockerfile : "Dockerfile.test" ,
42
- BuildOptionsModifier : func (buildOptions * types.ImageBuildOptions ) {
43
- buildOptions .Target = "unregistry-dind"
44
- },
45
- },
46
- Env : map [string ]string {
47
- "UNREGISTRY_LOG_LEVEL" : "debug" ,
48
- },
49
- Privileged : true ,
50
- // Explicitly specify the host port for the registry because if not specified, 'docker push' from Docker
51
- // Desktop is unable to reach the automatically mapped one for some reason.
52
- ExposedPorts : []string {"2375" , "50000:5000" },
53
- WaitingFor : wait .ForAll (
54
- wait .ForListeningPort ("2375" ),
55
- wait .ForListeningPort ("5000" ),
56
- ).WithStartupTimeoutDefault (15 * time .Second ),
57
- },
58
- Started : true ,
59
- }
60
- unregistryContainer , err := testcontainers .GenericContainer (ctx , req )
61
- require .NoError (t , err )
62
-
63
- t .Cleanup (func () {
64
- // Print last 20 lines of unregistry container logs.
65
- logs , err := unregistryContainer .Logs (ctx )
66
- assert .NoError (t , err , "Failed to get logs from unregistry container." )
67
- if err == nil {
68
- defer logs .Close ()
69
- logsContent , err := io .ReadAll (logs )
70
- assert .NoError (t , err , "Failed to read logs from unregistry container." )
71
- if err == nil {
72
-
73
- lines := strings .Split (string (logsContent ), "\n " )
74
- start := len (lines ) - 20
75
- if start < 0 {
76
- start = 0
77
- }
78
-
79
- t .Log ("=== Last 20 lines of unregistry container logs ===" )
80
- for i := start ; i < len (lines ); i ++ {
81
- if lines [i ] != "" {
82
- t .Log (lines [i ])
83
- }
84
- }
85
- t .Log ("=== End of unregistry container logs ===" )
86
- }
87
- }
88
-
89
- // Ensure the container is terminated after the test.
90
- assert .NoError (t , unregistryContainer .Terminate (ctx ))
91
- })
92
-
93
- mappedDockerPort , err := unregistryContainer .MappedPort (ctx , "2375" )
94
- require .NoError (t , err )
95
- mappedRegistryPort , err := unregistryContainer .MappedPort (ctx , "5000" )
96
- require .NoError (t , err )
31
+ mappedDockerPort , mappedRegistryPort := runUnregistryDinD (t , true )
97
32
98
33
remoteCli , err := client .NewClientWithOpts (
99
- client .WithHost ("tcp://localhost:" + mappedDockerPort . Port () ),
34
+ client .WithHost ("tcp://localhost:" + mappedDockerPort ),
100
35
client .WithAPIVersionNegotiation (),
101
36
)
102
37
require .NoError (t , err )
103
38
defer remoteCli .Close ()
104
39
105
- registryAddr := "localhost:" + mappedRegistryPort . Port ()
40
+ registryAddr := "localhost:" + mappedRegistryPort
106
41
t .Logf ("Unregistry started at %s" , registryAddr )
107
42
108
43
localCli , err := client .NewClientWithOpts (client .FromEnv , client .WithAPIVersionNegotiation ())
0 commit comments