Skip to content

Commit

Permalink
Supply exegol container name when hostname is overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
Dramelac committed Oct 12, 2023
1 parent 289d753 commit f80e7e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions exegol/model/ExegolContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def __init__(self, docker_container: Container, model: Optional[ExegolContainerT
super().__init__(docker_container.name,
config=ContainerConfig(docker_container),
image=ExegolImage(name=image_name, docker_image=docker_image),
hostname=docker_container.attrs.get('Config', {}).get('Hostname'))
hostname=docker_container.attrs.get('Config', {}).get('Hostname'),
new_container=False)
self.image.syncContainerData(docker_container)
# At this stage, the container image object has an unknown status because no synchronization with a registry has been done.
# This could be done afterwards (with container.image.autoLoad()) if necessary because it takes time.
Expand All @@ -52,7 +53,8 @@ def __init__(self, docker_container: Container, model: Optional[ExegolContainerT
config=ContainerConfig(docker_container),
# Rebuild config from docker object to update workspace path
image=model.image,
hostname=model.hostname)
hostname=model.hostname,
new_container=False)
self.__new_container = True
self.image.syncStatus()

Expand Down
8 changes: 5 additions & 3 deletions exegol/model/ExegolContainerTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ExegolContainerTemplate:
"""Exegol template class used to create a new container"""

def __init__(self, name: Optional[str], config: ContainerConfig, image: ExegolImage, hostname: Optional[str] = None):
def __init__(self, name: Optional[str], config: ContainerConfig, image: ExegolImage, hostname: Optional[str] = None, new_container: bool = True):
if name is None:
name = Prompt.ask("[bold blue][?][/bold blue] Enter the name of your new exegol container", default="default")
assert name is not None
Expand All @@ -20,12 +20,14 @@ def __init__(self, name: Optional[str], config: ContainerConfig, image: ExegolIm
name = name.lower()
self.container_name: str = name if name.startswith("exegol-") else f'exegol-{name}'
self.name: str = name.replace('exegol-', '')
self.image: ExegolImage = image
self.config: ContainerConfig = config
if hostname:
self.hostname: str = hostname
if new_container:
self.config.addEnv("EXEGOL_NAME", self.container_name)
else:
self.hostname = self.container_name
self.image: ExegolImage = image
self.config: ContainerConfig = config

def __str__(self):
"""Default object text formatter, debug only"""
Expand Down

0 comments on commit f80e7e2

Please sign in to comment.