Skip to content

Commit

Permalink
Add support for the dockerfile as file-like object
Browse files Browse the repository at this point in the history
Signed-off-by: lachmanfrantisek <[email protected]>
  • Loading branch information
lachmanfrantisek committed Apr 16, 2018
1 parent b77caa4 commit dd18945
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions colin/core/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

import enum
import io
import logging
import os

Expand Down Expand Up @@ -57,17 +58,22 @@ def _get_target_instance(target, logging_level):
"""
Get the Container/Image instance for the given name.
(Container is the first choice.)
or DockerfileParser instance if the target is path.
or DockerfileParser instance if the target is path or file-like object.
:param target: str or instance of Image/Container
:return: Container/Image
:param target: str
or instance of Image/Container
or file-like object as Dockerfile
:return: Target object
"""
logger.debug("Finding target '{}'.".format(target))

if isinstance(target, (Image, Container)):
logger.debug("Target is a conu object.")
return target
if os.path.exists(target):
if isinstance(target, io.IOBase):
logger.debug("Target is a dockerfile loaded from the file-like object.")
return DockerfileParser(fileobj=target)
if os.path.isfile(target):
logger.debug("Target is a dockerfile.")
return DockerfileParser(fileobj=open(target))

Expand Down

0 comments on commit dd18945

Please sign in to comment.