testcontainers / testcontainers/testcontainers-java

[Bug]: PrefixingImageNameSubstitutor does not work if docker.io explicitly used as a registry

Abierto
#7,240 3 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

type/bug
Lenguaje dominante
Java
Estrellas
8.7k
Forks
1.9k
Merge medio
2 d 17 h
PR fusionados (30 d)
9

Descripción

Module

Core

Testcontainers version

1.18.3

Using the latest Testcontainers version?

Yes

Host OS

Linux and MacOS

Host Arch

x86-64 and ARM

Docker version
Client:
 Cloud integration: v1.0.33
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:51:16 2023
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.20.1 (110738)
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:50:59 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
What happened?

I'm using the default prefixing image substitutor introduced with #3413.

Activated via .testcontainers.properties with hub.image.name.prefix=my.custom.registry/dockerhubproxy/

The configuration is applied and I can see that the image substitution is getting processed in general. The issue is that the logic to detect whether or not to perform image name substitution is as follows:

boolean isAHubImage = original.getRegistry().isEmpty();

(see PrefixingImageNameSubstitutor.java )

This only catches the case whereas no image registry was included (default registry) and then presumes that we meant DockerHub and thus would like to perform Image Name Substitution. If we have a docker registr stated explicitely such as docker.io/postgres:14 then image name substitution is not applied.

If the goal is to always perform image name substitution for DockerHub images then I would count this as a bug.

The check should rather be something like:

boolean isAHubImage = original.getRegistry().isEmpty() || "docker.io".equals(original.getRegistry());

or better yet move that check into the DockerImageName class itself.

Workaround: make sure you do not include docker.io/ when configuring image names. Unfortunately this means that the defaults applied by Quarkus Dev Services do not work with prefixing image name substitution.

Relevant log output
2023-06-26 10:09:10,398 INFO  [tc.doc.io/postgres:14] (build-58) Pulling docker image: docker.io/postgres:14. Please be patient; this may take some time but only needs to be done once.
2023-06-26 10:09:10,402 INFO  [org.tes.uti.RegistryAuthLocator] (build-58) Failure when attempting to lookup auth config. Please ignore if you don't have images in an authenticated registry. Details: (dockerImageName: docker.io/postgres:latest, configFile: /home/runner/.docker/config.json, configEnv: DOCKER_AUTH_CONFIG). Falling back to docker-java default behaviour. Exception message: Status 404: No config supplied. Checked in order: /home/runner/.docker/config.json (file not found), DOCKER_AUTH_CONFIG (not set)
2023-06-26 10:09:12,107 INFO  [tc.doc.io/postgres:14] (docker-java-stream--933788147) Starting to pull image
2023-06-26 10:09:12,227 INFO  [tc.doc.io/postgres:14] (docker-java-stream--933788147) Pulling image layers:  0 pending,  0 downloaded,  0 extracted, (0 bytes/0 bytes)


...


2023-06-26 10:09:21,122 INFO  [org.tes.uti.ImageNameSubstitutor] (build-58) Using my.custom.registry/dockerhubproxy/testcontainers/ryuk:0.4.0 as a substitute image for testcontainers/ryuk:0.4.0 (using image substitutor: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor'))
2023-06-26 10:09:21,124 INFO  [tc.my.cus.reg.4.0] (build-58) Pulling docker image: my.custom.registry/dockerhubproxy/testcontainers/ryuk:0.4.0. Please be patient; this may take some time but only needs to be done once.
2023-06-26 10:09:21,124 INFO  [org.tes.uti.RegistryAuthLocator] (build-58) Failure when attempting to lookup auth config. Please ignore if you don't have images in an authenticated registry. Details: (dockerImageName: my.custom.registry/dockerhubproxy/testcontainers/ryuk:latest, configFile: /home/runner/.docker/config.json, configEnv: DOCKER_AUTH_CONFIG). Falling back to docker-java default behaviour. Exception message: Status 404: No config supplied. Checked in order: /home/runner/.docker/config.json (file not found), DOCKER_AUTH_CONFIG (not set)
2023-06-26 10:09:23,870 INFO  [tc.my.cus.reg.4.0] (docker-java-stream--1767320720) Starting to pull image
2023-06-26 10:09:23,871 INFO  [tc.my.cus.reg.4.0] (docker-java-stream--1767320720) Pulling image layers:  0 pending,  0 downloaded,  0 extracted, (0 bytes/0 bytes)
Additional Information

No response

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con core/src/main/java/org/testcontainers/utility/PrefixingImageNameSubstitutor.java e inspecciona cómo DockerImageName expone su registro. Verifica el comportamiento existente de sustitución de imágenes y, después, añade cobertura para que una imagen de docker.io especificada explícitamente reciba el prefijo configurado, mientras que los registros que no sean de Hub no se vean afectados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
docker, java
Área
devops, tooling
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.