Skip to content

Commit

Permalink
Add support for Containerfile in addition to Dockerfile
Browse files Browse the repository at this point in the history
Also fix autocomplete

Signed-off-by: Ygal Blum <[email protected]>
  • Loading branch information
ygalblum committed May 11, 2023
1 parent d878414 commit dab6952
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 4 additions & 1 deletion skipper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions skipper/data/skipper-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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[*]})
Expand All @@ -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

Expand Down
8 changes: 6 additions & 2 deletions skipper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit dab6952

Please sign in to comment.