3
# Licensed to the Apache Software Foundation (ASF) under one or more
4
# contributor license agreements. See the NOTICE file distributed with
5
# this work for additional information regarding copyright ownership.
6
# The ASF licenses this file to You under the Apache License, Version 2.0
7
# (the "License"); you may not use this file except in compliance with
8
# the License. You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
19
Python script to prepare the hardcoded source folder for the docker official image
20
This script is used to prepare the source folder for the docker official image
23
prepare_docker_official_image_source.py --help
24
Get detailed description of each option
27
prepare_docker_official_image_source.py --image-type <image_type> --kafka-version <kafka_version>
29
This command will build a directory with the name as <kafka_version> housing the hardcoded static Dockerfile and scripts for
30
the docker official image, <image_type> as image type (jvm by default), <kafka_version> for the kafka version for which the
34
from datetime import date
36
from distutils.dir_util import copy_tree
42
def remove_args_and_hardcode_values(file_path, kafka_version, kafka_url):
43
with open(file_path, 'r') as file:
44
filedata = file.read()
45
filedata = filedata.replace("ARG kafka_url", f"ENV kafka_url {kafka_url}")
46
filedata = filedata.replace(
47
"ARG build_date", f"ENV build_date {str(date.today())}")
48
original_comment = re.compile(r"# Get kafka from https://archive.apache.org/dist/kafka and pass the url through build arguments")
49
updated_comment = f"# Get Kafka from https://archive.apache.org/dist/kafka, url passed as env var, for version {kafka_version}"
50
filedata = original_comment.sub(updated_comment, filedata)
51
with open(file_path, 'w') as file:
55
if __name__ == '__main__':
56
parser = argparse.ArgumentParser()
57
parser.add_argument("--image-type", "-type", choices=[
58
"jvm"], default="jvm", dest="image_type", help="Image type you want to build")
59
parser.add_argument("--kafka-version", "-v", dest="kafka_version",
60
help="Kafka version for which the source for docker official image is to be built")
61
args = parser.parse_args()
62
kafka_url = f"https://archive.apache.org/dist/kafka/{args.kafka_version}/kafka_2.13-{args.kafka_version}.tgz"
63
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)
66
if os.path.exists(new_dir):
67
shutil.rmtree(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)