Implementation:Apache Kafka Build Docker Image Runner
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Release_Engineering, Containerization |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
Concrete tool for building and testing Docker images provided by the Kafka Docker module.
Description
The build_docker_image_runner function from common.py prepares a temporary build context by copying Dockerfiles, resources, and optionally the Kafka archive. It replaces placeholders in the docker command template and executes the build. The run_docker_tests function from docker_build_test.py orchestrates the complete build-and-test cycle.
Usage
Use docker_build_test.py as a CLI tool for local testing, or import build_docker_image_runner for custom build workflows.
Code Reference
Source Location
- Repository: Apache Kafka
- File: docker/common.py (L33-48), docker/docker_build_test.py (L45-62)
Signature
def build_docker_image_runner(command, image_type, kafka_archive=None):
"""
Builds a Docker image using a command template.
Creates temp directory, copies Dockerfile and resources,
replaces $DOCKER_FILE and $DOCKER_DIR placeholders.
"""
def run_docker_tests(image, tag, kafka_url, image_type):
"""
Tests a Docker image by downloading Kafka, extracting,
and running the test suite.
Produces HTML report at docker/test/report_{image_type}.html
"""
Import
from common import build_docker_image_runner
# CLI: python docker_build_test.py image_name -u kafka_url
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| command | str | Yes | Docker build command template with $DOCKER_FILE and $DOCKER_DIR placeholders |
| image_type | str | Yes | "jvm" or "native" |
| kafka_archive | str | No | Local path to Kafka archive (optional) |
| image | str | Yes (for tests) | Docker image name |
| tag | str | Yes (for tests) | Image tag |
| kafka_url | str | Yes (for tests) | URL to download Kafka binary |
Outputs
| Name | Type | Description |
|---|---|---|
| Docker image | image | Built Docker image |
| Test report | file | HTML report at docker/test/report_{image_type}.html |
Usage Examples
Build and Test Locally
# Build and test JVM image
python docker/docker_build_test.py kafka-test \
-u https://downloads.apache.org/kafka/3.7.0/kafka_2.13-3.7.0.tgz
# Build only
python docker/docker_build_test.py kafka-test -b \
-a /path/to/kafka.tgz
# Test only (image already built)
python docker/docker_build_test.py kafka-test -t \
-u https://downloads.apache.org/kafka/3.7.0/kafka_2.13-3.7.0.tgz
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment