Skip to content

Conversation

@shyim
Copy link
Collaborator

@shyim shyim commented May 25, 2025

Summary

This PR adds comprehensive Docker registry authentication support to testcontainers-php, allowing users to pull private images from registries like GitHub Container Registry, Docker Hub, and custom registries.

Changes

  • Added DockerAuthConfig class to handle authentication configuration
  • Support for DOCKER_AUTH_CONFIG environment variable
  • Support for reading from ~/.docker/config.json
  • Support for credential stores (osxkeychain, wincred, pass, etc.)
  • Automatic registry detection from image names
  • Updated pullImage() method to use authentication when available
  • Added comprehensive unit tests

Motivation

Currently, when pulling private Docker images, authentication must be hardcoded in the pullImage() method. This PR implements the same authentication mechanisms as the Docker CLI, making it seamless for users to work with private registries.

Usage Examples

Using DOCKER_AUTH_CONFIG environment variable

export DOCKER_AUTH_CONFIG='{
  "auths": {
    "ghcr.io": {
      "username": "username",
      "password": "pat_token"
    }
  }
}'

Using Docker config file

The library will automatically read from ~/.docker/config.json if DOCKER_AUTH_CONFIG is not set.

Using credential stores

{
  "auths": {
    "ghcr.io": {}
  },
  "credsStore": "osxkeychain"
}

Test plan

  • Unit tests for all authentication methods
  • PHPStan validation passes
  • Manual testing with private registries
  • CI/CD validation

🤖 Generated with Claude Code

- Add DockerAuthConfig class to handle authentication configuration
- Support DOCKER_AUTH_CONFIG environment variable
- Support reading from ~/.docker/config.json
- Support credential stores (osxkeychain, wincred, etc.)
- Automatically detect registry from image name
- Update pullImage() to use authentication when available
- Add comprehensive unit tests

This allows pulling private images from registries like ghcr.io,
Docker Hub, and custom registries by respecting the same authentication
mechanisms as the Docker CLI.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@shyim shyim marked this pull request as draft May 25, 2025 09:57
@shyim
Copy link
Collaborator Author

shyim commented May 25, 2025

I wanted to try out AI to get #34 fixed.
I will review later the changes 😅

- Replace manual json_last_error() checks with JSON_THROW_ON_ERROR
- Wrap json_decode calls in try-catch blocks
- Provide better error context with JsonException
- Maintain backward compatibility with error messages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@jorgsowa
Copy link

This PR works nicely with private registries 👍🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants