MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / build_image

Method build_image

codeclash/arenas/arena.py:122–159  ·  view source on GitHub ↗

Build a Docker image for the game using the Dockerfile in the codebase. If running in AWS, pull the image from the AWS Docker registry instead.

(self)

Source from the content-addressed store, hash-verified

120 def game_id(self) -> str:
121 return self._metadata["game_id"]
122
123 @property
124 def image_name(self) -> str:
125 return f"codeclash/{self.name.lower()}"
126
127 def build_image(self):
128 """
129 Build a Docker image for the game using the Dockerfile in the codebase.
130 If running in AWS, pull the image from the AWS Docker registry instead.
131 """
132 if is_running_in_aws_batch():
133 pull_game_container_aws_ecr(game_name=self.name, image_name=self.image_name, logger=self.logger)
134
135 # Hold the lock across check-and-build so concurrent pairs don't race: the first thread
136 # builds while the rest wait, then find the image already present and skip.
137 with CodeArena._build_lock:
138 self.logger.debug(f"Checking if container {self.image_name} exists")
139 result = subprocess.run(
140 f"docker images -q {self.image_name}",
141 shell=True,
142 capture_output=True,
143 text=True,
144 )
145 if result.stdout.strip():
146 self.logger.debug(f"Container {self.image_name} exists")
147 return
148
149 self.logger.info(
150 f"Building Docker image {self.image_name}. This may take 1-5 minutes and only work on Linux for some games."
151 )
152
153 # NOTE: Assuming Dockerfile is declared in same directory as the arena.
154 arena_file = Path(inspect.getfile(self.__class__))
155 folder_path = arena_file.parent
156 result = subprocess.run(
157 f"docker build --no-cache -t {self.image_name} -f {folder_path}/{self.name}.Dockerfile .",
158 shell=True,
159 capture_output=True,
160 text=True,
161 )
162 if result.returncode == 0:

Callers 1

get_environmentMethod · 0.95

Calls 3

is_running_in_aws_batchFunction · 0.90
runMethod · 0.45

Tested by

no test coverage detected