testcontainers / testcontainers/testcontainers-java

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

Aperta
#7,240 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

type/bug
Lingua principale
Java
Stelle
8.7k
Fork
1.9k
Merge medio
2g 17h
PR unite (30g)
9

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da core/src/main/java/org/testcontainers/utility/PrefixingImageNameSubstitutor.java e analizza come DockerImageName espone il proprio registro. Verifica il comportamento esistente della sostituzione delle immagini, quindi aggiungi una copertura di test affinché un’immagine docker.io specificata esplicitamente riceva il prefisso configurato, mentre i registri non-Hub rimangano invariati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
docker, java
Ambito
devops, tooling
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.