55# All rights reserved.
66#############################################
77
8+ """
9+ Module to help build a docker image from its component pieces.
10+ """
11+
812from __future__ import annotations
913from abc import ABC , abstractmethod
1014import os
11- from typing import Awaitable , Callable , Iterable , Mapping , Union
15+ from typing import Iterable , Mapping
1216
13- from gdev .custom .pathlib import Path
17+ from gdev .custom .gaia_path import GaiaPath
1418from gdev .dependency import Dependency
1519from gdev .host import Host
1620from gdev .third_party .atools import memoize
17- from .cfg import GenAbcCfg
18- from .dockerfile import GenAbcDockerfile
21+ from gdev . cmd . gen . _abc .cfg import GenAbcCfg
22+ from gdev . cmd . gen . _abc .dockerfile import GenAbcDockerfile
1923
2024
2125# We require buildkit support for inline caching of multi-stage dockerfiles. It's also way faster
@@ -44,15 +48,6 @@ def dockerfile(self) -> GenAbcDockerfile:
4448 """
4549 raise NotImplementedError
4650
47- # TODO: Used?
48- @memoize
49- def __get_actual_git_hash (self ) -> str :
50- actual_git_hash = self ._get_actual_label_value ('GitHash' )
51-
52- self .log .debug (f'{ actual_git_hash = } ' )
53-
54- return actual_git_hash
55-
5651 @memoize
5752 def _get_actual_label_value (self , name : str ) -> str :
5853 """
@@ -72,18 +67,20 @@ def _get_actual_label_value(self, name: str) -> str:
7267 @memoize
7368 def _get_actual_label_value_by_name (self ) -> Mapping [str , str ]:
7469 """
75- Get the hash of an image with the actual label values that are called for by the configuration.
70+ Get the hash of an image with the actual label values that are called
71+ for by the configuration.
7672 """
7773 return {'GitHash' : self ._get_actual_label_value (name = 'GitHash' )}
7874
7975 @memoize
8076 def get_actual_label_value_by_name (self ) -> Mapping [str , str ]:
8177 """
82- Get the hash of an image with the actual label values that are called for by the configuration.
78+ Get the hash of an image with the actual label values that are called
79+ for by the configuration.
8380 """
8481
8582 actual_label_value_by_name = self ._get_actual_label_value_by_name ()
86- self .log .debug (f' { actual_label_value_by_name = } ' )
83+ self .log .debug (' actual_label_value_by_name = %s' , actual_label_value_by_name )
8784 return actual_label_value_by_name
8885
8986 @memoize
@@ -102,7 +99,7 @@ def inner(dockerfile: GenAbcDockerfile) -> Iterable[str]:
10299
103100 base_build_names = tuple (inner (self .dockerfile ))
104101
105- self .log .debug (f' { base_build_names = } ' )
102+ self .log .debug (' base_build_names = %s' , base_build_names )
106103
107104 return base_build_names
108105
@@ -119,7 +116,7 @@ def get_sha(self) -> str:
119116 else :
120117 sha = ''
121118
122- self .log .debug (f' { sha = } ' )
119+ self .log .debug (' sha = %s' , sha )
123120
124121 return sha
125122
@@ -131,44 +128,18 @@ def get_tag(self) -> str:
131128
132129 tag = f'{ self .dockerfile .get_name ()} :latest'
133130
134- self .log .debug (f' { tag = } ' )
131+ self .log .debug (' tag = %s' , tag )
135132
136133 return tag
137134
138- # TODO unused?
139- @memoize
140- def __get_uncommitted (self ) -> str :
141- seen_dockerfiles = set ()
142-
143- def inner (dockerfile : GenAbcDockerfile ) -> Iterable [Path ]:
144- paths = set ()
145- if dockerfile not in seen_dockerfiles :
146- seen_dockerfiles .add (dockerfile )
147- paths .add ( Path .repo () / Path (dockerfile .options .target ))
148- for input_dockerfile in dockerfile .get_input_dockerfiles ():
149- paths |= inner (input_dockerfile )
150- return paths
151-
152- uncommitted = '\n ' .join (
153- Host .execute_and_get_lines_sync (
154- f'git status --short ' + ' ' .join (
155- f'{ path .parent } ' for path in inner (self .dockerfile )
156- )
157- )
158- )
159-
160- self .log .debug (f'{ uncommitted = } ' )
161-
162- return uncommitted
163-
164135 @memoize
165136 def __get_wanted_git_hash (self ) -> str :
166137 """
167138 Request that GIT provides information about the SHA of the HEAD node.
168139 """
169140 wanted_git_hash = Host .execute_and_get_line_sync ('git rev-parse HEAD' )
170141
171- self .log .debug (f' { wanted_git_hash = } ' )
142+ self .log .debug (' wanted_git_hash = %s' , wanted_git_hash )
172143
173144 return wanted_git_hash
174145
@@ -185,7 +156,7 @@ def get_wanted_label_value_by_name(self) -> Mapping[str, str]:
185156 """
186157 wanted_label_value_by_name = self ._get_wanted_label_value_by_name ()
187158
188- self .log .debug (f' { wanted_label_value_by_name = } ' )
159+ self .log .debug (' wanted_label_value_by_name = %s' , wanted_label_value_by_name )
189160
190161 return wanted_label_value_by_name
191162
@@ -203,8 +174,7 @@ def main(self) -> None:
203174 for base_build_name in self .__get_base_build_names ()])
204175 cached_images = f"--cache-from { cached_images } "
205176
206- # TODO query remotely for cached build sources.
207- self .log .info (f'Creating image "{ self .get_tag ()} "' )
177+ self .log .info ('Creating image "%s"' , self .get_tag ())
208178 Host .execute_sync (
209179 f'docker buildx build'
210180 f' -f { self .dockerfile .path } '
@@ -229,10 +199,13 @@ def main(self) -> None:
229199
230200 f' { cached_images } '
231201
232- f' { Path .repo ()} '
202+ f' { GaiaPath .repo ()} '
233203 )
234- Host .execute_sync (f 'docker image prune -f' )
204+ Host .execute_sync ('docker image prune -f' )
235205
206+ # pylint: disable=import-outside-toplevel
207+ #
208+ # Required to resolve cyclical dependency issues.
236209 @memoize
237210 def cli_entrypoint (self ) -> None :
238211 """
@@ -242,7 +215,8 @@ def cli_entrypoint(self) -> None:
242215 if not self .options .mixins :
243216 build = self
244217 else :
245- from . ._custom .build import GenCustomBuild
218+ from gdev . cmd . gen ._custom .build import GenCustomBuild
246219 build = GenCustomBuild (options = self .options , base_build = self )
247220
248221 build .run ()
222+ # pylint: enable=import-outside-toplevel
0 commit comments