From dab6952655a5aa57eca710ffa989574c155983fc Mon Sep 17 00:00:00 2001 From: Ygal Blum Date: Wed, 10 May 2023 16:55:58 +0300 Subject: [PATCH] Add support for Containerfile in addition to Dockerfile Also fix autocomplete Signed-off-by: Ygal Blum --- skipper/cli.py | 5 ++++- skipper/data/skipper-complete.sh | 12 ++++++------ skipper/utils.py | 8 ++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/skipper/cli.py b/skipper/cli.py index 4a99906..c74a350 100644 --- a/skipper/cli.py +++ b/skipper/cli.py @@ -111,7 +111,7 @@ def build(ctx, images_to_build, container_context, cache): utils.logger.info('Building image: %s', image) if not os.path.exists(dockerfile): - utils.logger.warning('Dockerfile %s does not exist! Skipping...', dockerfile) + utils.logger.warning('File %s does not exist! Skipping...', dockerfile) continue fqdn_image = image + ':' + tag @@ -415,6 +415,9 @@ def runner_run(command): utils.logger.info("No build container tag was provided") docker_file = utils.image_to_dockerfile(image) + if docker_file is None: + sys.exit(f'Could not find any dockerfile for {image}') + utils.logger.info("Building image using docker file: %s", docker_file) if container_context is not None: build_context = container_context diff --git a/skipper/data/skipper-complete.sh b/skipper/data/skipper-complete.sh index db1bdbc..7960af2 100644 --- a/skipper/data/skipper-complete.sh +++ b/skipper/data/skipper-complete.sh @@ -88,9 +88,9 @@ __contains_word () { _get_images_from_dockerfiles() { - local dockerfiles=$( ls Dockerfile.* ) - for dockerfile in $dockerfiles; do - echo ${dockerfile##*.}; + local dockerfiles=$( find * -type f -regex "\(Docker\|Container\)file\..*" ) + for dockerfile in $dockerfiles; do + echo ${dockerfile##*.}; done } @@ -156,7 +156,7 @@ _skipper_completion() { if [[ $cur == -* ]]; then COMPREPLY=( $(compgen -W "${OPTS[RUN]}" -- $cur) ) else - if [[ $prev == -f ]]; then + if [[ $prev == -f ]]; then COMPREPLY=( $(compgen -f -X '!*[mM]akefile' -- $cur) ) else makefile=$(_get_makefile ${COMP_WORDS[*]}) @@ -172,12 +172,12 @@ _skipper_completion() { command sed -nf <(_make_target_extract_script $mode "$cur") ) ) fi fi - + else if [[ $cur == -* ]]; then COMPREPLY=( $(compgen -W "${OPTS[GLOBAL]}" -- $cur) ) else - COMPREPLY=( $(compgen -W "$COMMANDS" -- $cur) ) + COMPREPLY=( $(compgen -W "$COMMANDS" -- $cur) ) fi fi diff --git a/skipper/utils.py b/skipper/utils.py index 7ebc7c6..77866fe 100644 --- a/skipper/utils.py +++ b/skipper/utils.py @@ -142,11 +142,15 @@ def generate_fqdn_image(registry, namespace, image, tag='latest'): def image_to_dockerfile(image): - return 'Dockerfile.' + image + prefixes = ['Docker', 'Container'] + docker_files = [file for file in [prefix + "file." + image for prefix in prefixes] if os.path.exists(file)] + if len(docker_files) > 1: + logger.warning('Found more than one dockerfile for %s. Using %s', image, docker_files[0]) + return docker_files[0] if len(docker_files) else None def dockerfile_to_image(dockerfile): - return dockerfile.replace('Dockerfile.', '') + return dockerfile.split('.', 1)[-1] def is_tool(name):