kafka_neu-1778570057504.zip-extract/kafka-4.2.0-src/docker/prepare_docker_official_image_source.py

Path
kafka_neu-1778570057504.zip-extract/kafka-4.2.0-src/docker/prepare_docker_official_image_source.py
Status
scanned
Type
file
Name
prepare_docker_official_image_source.py
Extension
.py
Programming language
Python
Mime type
text/x-script.python
File type
Python script, ASCII text executable
Tag

      
    
Rootfs path

      
    
Size
3473 (3.4 KB)
MD5
9d0226db03b5010344b9506063e9a676
SHA1
e50d2da53832da13e2c090feacbc3d38ae6c5bf5
SHA256
f5d3f4888915aace29103b35a8e91f3c66728605193b26b614de578efbb59043
SHA512

      
    
SHA1_git
bbc539b5c4c54c280f49f78a16dcb5c848cfb0c2
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
prepare_docker_official_image_source.py | 3.4 KB |

#!/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 prepare the hardcoded source folder for the docker official image This script is used to prepare the source folder for the docker official image Usage: prepare_docker_official_image_source.py --help Get detailed description of each option Example command:- prepare_docker_official_image_source.py --image-type <image_type> --kafka-version <kafka_version> This command will build a directory with the name as <kafka_version> housing the hardcoded static Dockerfile and scripts for the docker official image, <image_type> as image type (jvm by default), <kafka_version> for the kafka version for which the image is being built. """ from datetime import date import argparse import os import shutil import re def remove_args_and_hardcode_values(file_path, kafka_version, kafka_url): with open(file_path, 'r') as file: filedata = file.read() filedata = filedata.replace("ARG kafka_url", f"ENV kafka_url {kafka_url}") filedata = filedata.replace( "ARG build_date", f"ENV build_date {str(date.today())}") original_comment = re.compile(r"# Get kafka from https://archive.apache.org/dist/kafka and pass the url through build arguments") updated_comment = f"# Get Kafka from https://archive.apache.org/dist/kafka, url passed as env var, for version {kafka_version}" filedata = original_comment.sub(updated_comment, filedata) with open(file_path, 'w') as file: file.write(filedata) if __name__ == '__main__': parser = argparse.ArgumentParser() 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") 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, 'docker_official_images', args.kafka_version) if os.path.exists(new_dir): shutil.rmtree(new_dir) os.makedirs(new_dir) 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)
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
23.29
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 10 10
https://archive.apache.org/dist/kafka 47 47
https://archive.apache.org/dist/kafka/%7Bargs.kafka_version%7D/kafka_2.13-%7Bargs.kafka_version%7D.tgz 61 61