diff --git a/modules/registry/options.go b/modules/registry/options.go index f5253aedf7..cca394391b 100644 --- a/modules/registry/options.go +++ b/modules/registry/options.go @@ -20,13 +20,16 @@ const ( // The dataPath must have the same structure as the registry data directory. func WithData(dataPath string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) error { - req.Files = append(req.Files, testcontainers.ContainerFile{ + if err := testcontainers.WithFiles(testcontainers.ContainerFile{ HostFilePath: dataPath, ContainerFilePath: containerDataPath, - }) + })(req); err != nil { + return err + } - req.Env["REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY"] = containerDataPath - return nil + return testcontainers.WithEnv(map[string]string{ + "REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY": containerDataPath, + })(req) } } @@ -60,16 +63,18 @@ func WithHtpasswd(credentials string) testcontainers.CustomizeRequestOption { // thanks to the REGISTRY_AUTH_HTPASSWD_PATH environment variable. func WithHtpasswdFile(htpasswdPath string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) error { - req.Files = append(req.Files, testcontainers.ContainerFile{ + if err := testcontainers.WithFiles(testcontainers.ContainerFile{ HostFilePath: htpasswdPath, ContainerFilePath: containerHtpasswdPath, FileMode: 0o644, - }) + })(req); err != nil { + return err + } - req.Env["REGISTRY_AUTH"] = "htpasswd" - req.Env["REGISTRY_AUTH_HTPASSWD_REALM"] = "Registry" - req.Env["REGISTRY_AUTH_HTPASSWD_PATH"] = containerHtpasswdPath - req.Env["REGISTRY_AUTH_HTPASSWD_PATH"] = containerHtpasswdPath - return nil + return testcontainers.WithEnv(map[string]string{ + "REGISTRY_AUTH": "htpasswd", + "REGISTRY_AUTH_HTPASSWD_REALM": "Registry", + "REGISTRY_AUTH_HTPASSWD_PATH": containerHtpasswdPath, + })(req) } } diff --git a/modules/registry/registry.go b/modules/registry/registry.go index d7b5e8f13d..76391e482a 100644 --- a/modules/registry/registry.go +++ b/modules/registry/registry.go @@ -273,36 +273,26 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize // Run creates an instance of the Registry container type func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RegistryContainer, error) { - req := testcontainers.ContainerRequest{ - Image: img, - ExposedPorts: []string{registryPort}, - Env: map[string]string{ + moduleOpts := []testcontainers.ContainerCustomizer{ + testcontainers.WithExposedPorts(registryPort), + testcontainers.WithEnv(map[string]string{ // convenient for testing "REGISTRY_STORAGE_DELETE_ENABLED": "true", - }, - WaitingFor: wait.ForHTTP("/"). - WithPort(registryPort). - WithStartupTimeout(10 * time.Second), + }), + testcontainers.WithWaitStrategy( + wait.ForHTTP("/"). + WithPort(registryPort). + WithStartupTimeout(10 * time.Second), + ), } - genericContainerReq := testcontainers.GenericContainerRequest{ - ContainerRequest: req, - Started: true, - } - - for _, opt := range opts { - if err := opt.Customize(&genericContainerReq); err != nil { - return nil, err - } - } - - container, err := testcontainers.GenericContainer(ctx, genericContainerReq) + container, err := testcontainers.Run(ctx, img, append(moduleOpts, opts...)...) var c *RegistryContainer if container != nil { c = &RegistryContainer{Container: container} } if err != nil { - return c, fmt.Errorf("generic container: %w", err) + return c, fmt.Errorf("run registry: %w", err) } address, err := c.Address(ctx)