Skip to content

Commit 675552a

Browse files
KAFKA-19490: Remove usages of distutils in docker scripts (#20178)
The [distutils](https://docs.python.org/3.13/whatsnew/3.12.html#distutils) package is removed from Python 3.12. Change `distutils` usage to `shutil`. Reviewers: Mickael Maison <[email protected]> --------- Signed-off-by: PoAn Yang <[email protected]>
1 parent 8015c87 commit 675552a

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

docker/common.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
import subprocess
1919
import tempfile
2020
import os
21-
from distutils.file_util import copy_file
22-
23-
from distutils.dir_util import copy_tree
2421
import shutil
2522

2623
def execute(command):
@@ -36,11 +33,11 @@ def get_input(message):
3633
def build_docker_image_runner(command, image_type, kafka_archive=None):
3734
temp_dir_path = tempfile.mkdtemp()
3835
current_dir = os.path.dirname(os.path.realpath(__file__))
39-
copy_tree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}")
40-
copy_tree(f"{current_dir}/resources", f"{temp_dir_path}/{image_type}/resources")
41-
copy_file(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}")
36+
shutil.copytree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}", dirs_exist_ok=True)
37+
shutil.copytree(f"{current_dir}/resources", f"{temp_dir_path}/{image_type}/resources", dirs_exist_ok=True)
38+
shutil.copy(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}")
4239
if kafka_archive:
43-
copy_file(kafka_archive, f"{temp_dir_path}/{image_type}/kafka.tgz")
40+
shutil.copy(kafka_archive, f"{temp_dir_path}/{image_type}/kafka.tgz")
4441
command = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile")
4542
command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}")
4643
try:

docker/docker_build_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
from datetime import date
3838
import argparse
39-
from distutils.dir_util import copy_tree
4039
import shutil
4140
from test.docker_sanity_test import run_tests
4241
from common import execute, build_docker_image_runner
@@ -47,7 +46,7 @@ def run_docker_tests(image, tag, kafka_url, image_type):
4746
temp_dir_path = tempfile.mkdtemp()
4847
try:
4948
current_dir = os.path.dirname(os.path.realpath(__file__))
50-
copy_tree(f"{current_dir}/test/fixtures", f"{temp_dir_path}/fixtures")
49+
shutil.copytree(f"{current_dir}/test/fixtures", f"{temp_dir_path}/fixtures", dirs_exist_ok=True)
5150
execute(["wget", "-nv", "-O", f"{temp_dir_path}/kafka.tgz", kafka_url])
5251
execute(["mkdir", f"{temp_dir_path}/fixtures/kafka"])
5352
execute(["tar", "xfz", f"{temp_dir_path}/kafka.tgz", "-C", f"{temp_dir_path}/fixtures/kafka", "--strip-components", "1"])

docker/docker_official_image_build_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"""
3535

3636
import argparse
37-
from distutils.dir_util import copy_tree
3837
import shutil
3938
from common import execute
4039
from docker_build_test import run_docker_tests
@@ -46,10 +45,11 @@ def build_docker_official_image(image, tag, kafka_version, image_type):
4645
image = f'{image}:{tag}'
4746
current_dir = os.path.dirname(os.path.realpath(__file__))
4847
temp_dir_path = tempfile.mkdtemp()
49-
copy_tree(f"{current_dir}/docker_official_images/{kafka_version}/{image_type}",
50-
f"{temp_dir_path}/{image_type}")
51-
copy_tree(f"{current_dir}/docker_official_images/{kafka_version}/jvm/resources",
52-
f"{temp_dir_path}/{image_type}/resources")
48+
shutil.copytree(f"{current_dir}/docker_official_images/{kafka_version}/{image_type}",
49+
f"{temp_dir_path}/{image_type}", dirs_exist_ok=True)
50+
shutil.copytree(f"{current_dir}/docker_official_images/{kafka_version}/jvm/resources",
51+
f"{temp_dir_path}/{image_type}/resources", dirs_exist_ok=True)
52+
shutil.copy(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}")
5353
command = f"docker build -f $DOCKER_FILE -t {image} $DOCKER_DIR"
5454
command = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile")
5555
command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}")

docker/prepare_docker_official_image_source.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
from datetime import date
3535
import argparse
36-
from distutils.dir_util import copy_tree
3736
import os
3837
import shutil
3938
import re
@@ -61,12 +60,10 @@ def remove_args_and_hardcode_values(file_path, kafka_version, kafka_url):
6160
args = parser.parse_args()
6261
kafka_url = f"https://archive.apache.org/dist/kafka/{args.kafka_version}/kafka_2.13-{args.kafka_version}.tgz"
6362
current_dir = os.path.dirname(os.path.realpath(__file__))
64-
new_dir = os.path.join(
65-
current_dir, f'docker_official_images', args.kafka_version)
63+
new_dir = os.path.join(current_dir, 'docker_official_images', args.kafka_version)
6664
if os.path.exists(new_dir):
6765
shutil.rmtree(new_dir)
6866
os.makedirs(new_dir)
69-
copy_tree(os.path.join(current_dir, args.image_type), os.path.join(new_dir, args.kafka_version, args.image_type))
70-
copy_tree(os.path.join(current_dir, 'resources'), os.path.join(new_dir, args.kafka_version, args.image_type, 'resources'))
71-
remove_args_and_hardcode_values(
72-
os.path.join(new_dir, args.kafka_version, args.image_type, 'Dockerfile'), args.kafka_version, kafka_url)
67+
shutil.copytree(os.path.join(current_dir, args.image_type), os.path.join(new_dir, args.image_type), dirs_exist_ok=True)
68+
shutil.copytree(os.path.join(current_dir, 'resources'), os.path.join(new_dir, args.image_type, 'resources'), dirs_exist_ok=True)
69+
remove_args_and_hardcode_values(os.path.join(new_dir, args.image_type, 'Dockerfile'), args.kafka_version, kafka_url)

0 commit comments

Comments
 (0)