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..94ea4b4 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.warn(f'Found more than one dockerfile for {image}. Using {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):