Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions modules/registry/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}
32 changes: 11 additions & 21 deletions modules/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading