testcontainers / testcontainers/testcontainers-java

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

オープン
#7,240 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

type/bug
主要言語
Java
スター
8.7k
フォーク
1.9k
平均マージ
2日 17時間
マージ済み PR(30日)
9

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

core/src/main/java/org/testcontainers/utility/PrefixingImageNameSubstitutor.java から始め、DockerImageName がレジストリをどのように公開しているかを確認してください。既存のイメージ置換の動作を検証し、そのうえで、明示的に指定された docker.io イメージに設定済みのプレフィックスが付与され、Hub 以外のレジストリには影響しないことを確認するテストを追加してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
docker, java
領域
devops, tooling
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。