Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
kafka/docker/docker_official_image_build_test.py at trunk · apache/kafka · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
apache
kafka
Repository navigation
Code
Pull requests
674
(674)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
trunk
Breadcrumbs
kafka
/
docker
/
docker_official_image_build_test.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
87 lines (77 loc) · 4.28 KB
trunk
Breadcrumbs
kafka
/
docker
/
docker_official_image_build_test.py
Copy path
Top
File metadata and controls
Code
Blame
87 lines (77 loc) · 4.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Python script to build and test a docker image
This script is used to generate a test report
Usage:
docker_official_image_build_test.py --help
Get detailed description of each option
Example command:-
docker_official_image_build_test.py <image_name> --image-tag <image_tag> --image-type <image_type> --kafka-version <kafka_version>
This command will build an image with <image_name> as image name, <image_tag> as image_tag (it will be latest by default),
<image_type> as image type (jvm by default), <kafka_version> for the kafka version for which the image is being built, and
run tests on the image.
-b can be passed as additional argument if you just want to build the image.
-t can be passed if you just want to run tests on the image.
"""
import
argparse
import
shutil
from
common
import
execute
from
docker_build_test
import
run_docker_tests
import
tempfile
import
os
def
build_docker_official_image
(
image
,
tag
,
kafka_version
,
image_type
):
image
=
f'
{
image
}
:
{
tag
}
'
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
temp_dir_path
=
tempfile
.
mkdtemp
()
shutil
.
copytree
(
f"
{
current_dir
}
/docker_official_images/
{
kafka_version
}
/
{
image_type
}
"
,
f"
{
temp_dir_path
}
/
{
image_type
}
"
,
dirs_exist_ok
=
True
)
shutil
.
copytree
(
f"
{
current_dir
}
/docker_official_images/
{
kafka_version
}
/jvm/resources"
,
f"
{
temp_dir_path
}
/
{
image_type
}
/resources"
,
dirs_exist_ok
=
True
)
shutil
.
copy
(
f"
{
current_dir
}
/server.properties"
,
f"
{
temp_dir_path
}
/
{
image_type
}
"
)
command
=
f"docker build -f $DOCKER_FILE -t
{
image
}
$DOCKER_DIR"
command
=
command
.
replace
(
"$DOCKER_FILE"
,
f"
{
temp_dir_path
}
/
{
image_type
}
/Dockerfile"
)
command
=
command
.
replace
(
"$DOCKER_DIR"
,
f"
{
temp_dir_path
}
/
{
image_type
}
"
)
try
:
execute
(
command
.
split
())
except
:
raise
SystemError
(
"Docker Image Build failed"
)
finally
:
shutil
.
rmtree
(
temp_dir_path
)
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"image"
,
help
=
"Image name that you want to keep for the Docker image"
)
parser
.
add_argument
(
"--image-tag"
,
"-tag"
,
default
=
"latest"
,
dest
=
"tag"
,
help
=
"Image tag that you want to add to the image"
)
parser
.
add_argument
(
"--image-type"
,
"-type"
,
choices
=
[
"jvm"
],
default
=
"jvm"
,
dest
=
"image_type"
,
help
=
"Image type you want to build"
)
parser
.
add_argument
(
"--kafka-version"
,
"-v"
,
dest
=
"kafka_version"
,
help
=
"Kafka version for which the source for docker official image is to be built"
)
parser
.
add_argument
(
"--build"
,
"-b"
,
action
=
"store_true"
,
dest
=
"build_only"
,
default
=
False
,
help
=
"Only build the image, don't run tests"
)
parser
.
add_argument
(
"--test"
,
"-t"
,
action
=
"store_true"
,
dest
=
"test_only"
,
default
=
False
,
help
=
"Only run the tests, don't build the image"
)
args
=
parser
.
parse_args
()
kafka_url
=
f"https://archive.apache.org/dist/kafka/
{
args
.
kafka_version
}
/kafka_2.13-
{
args
.
kafka_version
}
.tgz"
if
args
.
build_only
or
not
(
args
.
build_only
or
args
.
test_only
):
if
args
.
kafka_version
:
build_docker_official_image
(
args
.
image
,
args
.
tag
,
args
.
kafka_version
,
args
.
image_type
)
else
:
raise
ValueError
(
"--kafka-version is required argument for jvm docker official image image"
)
if
args
.
test_only
or
not
(
args
.
build_only
or
args
.
test_only
):
run_docker_tests
(
args
.
image
,
args
.
tag
,
kafka_url
,
None
,
args
.
image_type
)
You can’t perform that action at this time.