Skip to content

Commit

Permalink
docker-c: allow local image
Browse files Browse the repository at this point in the history
  • Loading branch information
magicnat committed Jan 21, 2022
1 parent e0d3fa0 commit be40141
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion seedemu/compiler/Docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@
alias st=set_title
"""

DockerCompilerFileTemplates['local_image'] = """\
{imageName}:
build:
context: {dirName}
image: {imageName}
"""

class DockerImage(object):
"""!
@brief The DockerImage class.
Expand All @@ -204,20 +211,28 @@ class DockerImage(object):

__software: Set[str]
__name: str
__local: bool
__dirName: str

def __init__(self, name: str, software: List[str]) -> None:
def __init__(self, name: str, software: List[str], local: bool = False, dirName: str = None) -> None:
"""!
@brief create a new docker image.
@param name name of the image. Can be name of a local image, image on
dockerhub, or image in private repo.
@param software set of software pre-installed in the image, so the
docker compiler can skip them when compiling.
@param local (optional) set this image as a local image. A local image
is built ocally instead of pulled from the docker hub. Default to False.
@param dirName (optional) directory name of the local image (when local
is True). Default to None. None means use the name of the image.
"""
super().__init__()

self.__name = name
self.__software = set()
self.__local = local
self.__dirName = dirName if dirName != None else name

for soft in software:
self.__software.add(soft)
Expand All @@ -238,6 +253,21 @@ def getSoftware(self) -> Set[str]:
"""
return self.__software

def getDirName(self) -> str:
"""!
@brief returns the directory name of this image.
@return directory name.
"""
return self.__dirName

def isLocal(self) -> bool:
"""!
@brief returns True if this image is local.
@return True if this image is local.
"""
return self.__local

DefaultImages: List[DockerImage] = []

Expand Down Expand Up @@ -900,6 +930,13 @@ def _makeDummies(self) -> str:
def _doCompile(self, emulator: Emulator):
registry = emulator.getRegistry()

for (image, ) in self.__images.values():
if image.getName() not in self._used_images or not image.isLocal(): continue
self.__services += DockerCompilerFileTemplates['local_image'].format(
imageName = image.getName(),
dirName = image.getDirName()
)

self._groupSoftware(emulator)

for ((scope, type, name), obj) in registry.getAll().items():
Expand Down

0 comments on commit be40141

Please sign in to comment.