Skip to content

Add ACR Cache support for Kafka Connect TestContainers e2e tests#49318

Open
xinlian12 wants to merge 1 commit into
Azure:mainfrom
xinlian12:kafka-connect-acr-cache-testcontainers
Open

Add ACR Cache support for Kafka Connect TestContainers e2e tests#49318
xinlian12 wants to merge 1 commit into
Azure:mainfrom
xinlian12:kafka-connect-acr-cache-testcontainers

Conversation

@xinlian12
Copy link
Copy Markdown
Member

Problem

Kafka Connect e2e tests use TestContainers to pull Docker images from Docker Hub. This causes intermittent CI failures due to Docker Hub rate limiting and connectivity timeouts (e.g., testcontainers/ryuk:0.12.0 pull timeout in build 6372004).

The MCR mirror/retag approach (microsoft/mcr PRs #3419, #3440) is deprecated since September 2025.

Solution

Use ACR Cache (Azure Container Registry Artifact Cache) to transparently proxy and cache Docker Hub images.

Changes

  1. Pipeline template (cosmos-sdk-client.yml):

    • Added TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX stage variable (empty default) and env var passthrough to test execution
    • Added conditional docker login PreStep for container registry authentication (only runs when configured)
  2. Setup documentation (test-acr-cache-setup.md):

    • ACR Cache rule creation commands for all 5 required images
    • Pipeline variable configuration guide
    • Local development instructions

Images requiring ACR Cache rules

Image Version Used By
testcontainers/ryuk 0.12.0 TestContainers (resource cleanup sidecar)
alpine 3.17 TestContainers (Docker health check)
confluentinc/cp-kafka 7.6.0 Kafka broker
confluentinc/cp-schema-registry 7.6.0 Schema Registry
confluentinc/cp-kafka-connect 7.6.0 Kafka Connect

How it works

TestContainers' built-in PrefixingImageNameSubstitutor reads the TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX env var and prepends it to all Docker Hub image references. For example, with prefix myacr.azurecr.io/:

  • testcontainers/ryuk:0.12.0myacr.azurecr.io/testcontainers/ryuk:0.12.0
  • confluentinc/cp-kafka:7.6.0myacr.azurecr.io/confluentinc/cp-kafka:7.6.0

ACR Cache transparently proxies these requests to Docker Hub and caches the result.

Activation (infrastructure setup needed)

To activate, the ops team needs to:

  1. Create ACR Cache rules (see test-acr-cache-setup.md)
  2. Set pipeline variables:
    • TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX: <acr>.azurecr.io/
    • TESTCONTAINERS_DOCKER_REGISTRY_URL: <acr>.azurecr.io (if anonymous pull is disabled)
    • TESTCONTAINERS_DOCKER_REGISTRY_USERNAME / TESTCONTAINERS_DOCKER_REGISTRY_PASSWORD (if auth needed)

Backward compatibility

When TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX is empty (default), images pull from Docker Hub as before. No Java code changes are needed.

Kafka Connect e2e tests use TestContainers to spin up Kafka, Schema Registry,
and Kafka Connect containers. All images are pulled from Docker Hub, which
causes intermittent CI failures due to rate limiting (e.g., testcontainers/ryuk
pull timeout in build 6372004).

This change adds support for routing Docker Hub pulls through an Azure Container
Registry (ACR) Cache by:

1. Adding TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX env var support to the Cosmos
   emulator test pipeline stage. When set (e.g., 'myacr.azurecr.io/'), all
   TestContainers Docker Hub image pulls are redirected through the ACR Cache.

2. Adding a conditional docker login PreStep that authenticates with the
   container registry when TESTCONTAINERS_DOCKER_REGISTRY_URL is configured.

3. Adding setup documentation (test-acr-cache-setup.md) with ACR Cache rule
   creation commands for all 5 required images:
   - testcontainers/ryuk:0.12.0
   - alpine:3.17
   - confluentinc/cp-kafka:7.6.0
   - confluentinc/cp-schema-registry:7.6.0
   - confluentinc/cp-kafka-connect:7.6.0

The change is backward-compatible: when TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX
is empty (default), images pull from Docker Hub as before.

To activate, set the following pipeline variables:
- TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX: '<acr-name>.azurecr.io/'
- TESTCONTAINERS_DOCKER_REGISTRY_URL: '<acr-name>.azurecr.io' (if auth needed)
- TESTCONTAINERS_DOCKER_REGISTRY_USERNAME: '<username>' (if auth needed)
- TESTCONTAINERS_DOCKER_REGISTRY_PASSWORD: '<password>' (if auth needed)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@xinlian12 xinlian12 requested a review from raych1 as a code owner May 29, 2026 21:50
Copilot AI review requested due to automatic review settings May 29, 2026 21:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds ACR Cache configuration support for Kafka Connect TestContainers-based e2e tests to reduce Docker Hub rate-limit and connectivity failures in CI.

Changes:

  • Adds pipeline plumbing for TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX.
  • Adds optional container registry login before Cosmos emulator tests.
  • Adds setup documentation for ACR Cache rules and local/pipeline configuration.
Show a summary per file
File Description
eng/pipelines/templates/stages/cosmos-sdk-client.yml Adds TestContainers image-prefix environment wiring and optional Docker registry login prestep.
sdk/cosmos/azure-cosmos-kafka-connect/test-acr-cache-setup.md Documents ACR Cache setup, required image rules, pipeline variables, and verification steps.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment on lines +81 to +82
--source-repo docker.io/library/alpine \
--target-repo library/alpine
$registryPassword = "$(TESTCONTAINERS_DOCKER_REGISTRY_PASSWORD)"
if ($registryUrl -and $registryUrl -ne '$(TESTCONTAINERS_DOCKER_REGISTRY_URL)') {
Write-Host "Logging in to container registry: $registryUrl"
docker login $registryUrl -u $registryUsername -p $registryPassword
Comment on lines +78 to +82
# TestContainers ACR Cache configuration:
# Set TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX to redirect Docker Hub pulls through an ACR Cache
# (e.g., 'myacr.azurecr.io/'). When empty, images pull directly from Docker Hub.
- name: TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX
value: ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants