mirror of https://github.com/apache/kafka.git
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 <mimaison@apache.org> --------- Signed-off-by: PoAn Yang <payang@apache.org>
This commit is contained in:
parent
8015c87390
commit
675552a724
|
@ -18,9 +18,6 @@
|
|||
import subprocess
|
||||
import tempfile
|
||||
import os
|
||||
from distutils.file_util import copy_file
|
||||
|
||||
from distutils.dir_util import copy_tree
|
||||
import shutil
|
||||
|
||||
def execute(command):
|
||||
|
@ -36,11 +33,11 @@ def get_input(message):
|
|||
def build_docker_image_runner(command, image_type, kafka_archive=None):
|
||||
temp_dir_path = tempfile.mkdtemp()
|
||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
copy_tree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}")
|
||||
copy_tree(f"{current_dir}/resources", f"{temp_dir_path}/{image_type}/resources")
|
||||
copy_file(f"{current_dir}/server.properties", f"{temp_dir_path}/{image_type}")
|
||||
shutil.copytree(f"{current_dir}/{image_type}", f"{temp_dir_path}/{image_type}", dirs_exist_ok=True)
|
||||
shutil.copytree(f"{current_dir}/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}")
|
||||
if kafka_archive:
|
||||
copy_file(kafka_archive, f"{temp_dir_path}/{image_type}/kafka.tgz")
|
||||
shutil.copy(kafka_archive, f"{temp_dir_path}/{image_type}/kafka.tgz")
|
||||
command = command.replace("$DOCKER_FILE", f"{temp_dir_path}/{image_type}/Dockerfile")
|
||||
command = command.replace("$DOCKER_DIR", f"{temp_dir_path}/{image_type}")
|
||||
try:
|
||||
|
|
|
@ -36,7 +36,6 @@ Usage:
|
|||
|
||||
from datetime import date
|
||||
import argparse
|
||||
from distutils.dir_util import copy_tree
|
||||
import shutil
|
||||
from test.docker_sanity_test import run_tests
|
||||
from common import execute, build_docker_image_runner
|
||||
|
@ -47,7 +46,7 @@ def run_docker_tests(image, tag, kafka_url, image_type):
|
|||
temp_dir_path = tempfile.mkdtemp()
|
||||
try:
|
||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
copy_tree(f"{current_dir}/test/fixtures", f"{temp_dir_path}/fixtures")
|
||||
shutil.copytree(f"{current_dir}/test/fixtures", f"{temp_dir_path}/fixtures", dirs_exist_ok=True)
|
||||
execute(["wget", "-nv", "-O", f"{temp_dir_path}/kafka.tgz", kafka_url])
|
||||
execute(["mkdir", f"{temp_dir_path}/fixtures/kafka"])
|
||||
execute(["tar", "xfz", f"{temp_dir_path}/kafka.tgz", "-C", f"{temp_dir_path}/fixtures/kafka", "--strip-components", "1"])
|
||||
|
|
|
@ -34,7 +34,6 @@ Usage:
|
|||
"""
|
||||
|
||||
import argparse
|
||||
from distutils.dir_util import copy_tree
|
||||
import shutil
|
||||
from common import execute
|
||||
from docker_build_test import run_docker_tests
|
||||
|
@ -46,10 +45,11 @@ 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()
|
||||
copy_tree(f"{current_dir}/docker_official_images/{kafka_version}/{image_type}",
|
||||
f"{temp_dir_path}/{image_type}")
|
||||
copy_tree(f"{current_dir}/docker_official_images/{kafka_version}/jvm/resources",
|
||||
f"{temp_dir_path}/{image_type}/resources")
|
||||
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}")
|
||||
|
|
|
@ -33,7 +33,6 @@ Usage:
|
|||
|
||||
from datetime import date
|
||||
import argparse
|
||||
from distutils.dir_util import copy_tree
|
||||
import os
|
||||
import shutil
|
||||
import re
|
||||
|
@ -61,12 +60,10 @@ if __name__ == '__main__':
|
|||
args = parser.parse_args()
|
||||
kafka_url = f"https://archive.apache.org/dist/kafka/{args.kafka_version}/kafka_2.13-{args.kafka_version}.tgz"
|
||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
new_dir = os.path.join(
|
||||
current_dir, f'docker_official_images', args.kafka_version)
|
||||
new_dir = os.path.join(current_dir, 'docker_official_images', args.kafka_version)
|
||||
if os.path.exists(new_dir):
|
||||
shutil.rmtree(new_dir)
|
||||
os.makedirs(new_dir)
|
||||
copy_tree(os.path.join(current_dir, args.image_type), os.path.join(new_dir, args.kafka_version, args.image_type))
|
||||
copy_tree(os.path.join(current_dir, 'resources'), os.path.join(new_dir, args.kafka_version, args.image_type, 'resources'))
|
||||
remove_args_and_hardcode_values(
|
||||
os.path.join(new_dir, args.kafka_version, args.image_type, 'Dockerfile'), args.kafka_version, kafka_url)
|
||||
shutil.copytree(os.path.join(current_dir, args.image_type), os.path.join(new_dir, args.image_type), dirs_exist_ok=True)
|
||||
shutil.copytree(os.path.join(current_dir, 'resources'), os.path.join(new_dir, args.image_type, 'resources'), dirs_exist_ok=True)
|
||||
remove_args_and_hardcode_values(os.path.join(new_dir, args.image_type, 'Dockerfile'), args.kafka_version, kafka_url)
|
||||
|
|
Loading…
Reference in New Issue