2424
2525# We require buildkit support for inline caching of multi-stage dockerfiles. It's also way faster
2626# and the terminal output is relatively sane.
27- os .environ [' DOCKER_BUILDKIT' ] = '1'
28- os .environ [' DOCKER_CLI_EXPERIMENTAL' ] = ' enabled'
27+ os .environ [" DOCKER_BUILDKIT" ] = "1"
28+ os .environ [" DOCKER_CLI_EXPERIMENTAL" ] = " enabled"
2929
3030
3131class GenAbcBuild (Dependency , ABC ):
@@ -53,12 +53,14 @@ def _get_actual_label_value(self, name: str) -> str:
5353 """
5454 Request that docker provide information about the label value for the current image.
5555 """
56- if (line := Host .execute_and_get_line_sync (
57- f'docker image inspect'
56+ if (
57+ line := Host .execute_and_get_line_sync (
58+ f"docker image inspect"
5859 f' --format="{{{{.Config.Labels.{ name } }}}}"'
59- f' { self .get_tag ()} '
60- )) == '"<no value>"' :
61- value = ''
60+ f" { self .get_tag ()} "
61+ )
62+ ) == '"<no value>"' :
63+ value = ""
6264 else :
6365 value = line .strip ('"' )
6466
@@ -70,7 +72,7 @@ def _get_actual_label_value_by_name(self) -> Mapping[str, str]:
7072 Get the hash of an image with the actual label values that are called
7173 for by the configuration.
7274 """
73- return {' GitHash' : self ._get_actual_label_value (name = ' GitHash' )}
75+ return {" GitHash" : self ._get_actual_label_value (name = " GitHash" )}
7476
7577 @memoize
7678 def get_actual_label_value_by_name (self ) -> Mapping [str , str ]:
@@ -80,13 +82,14 @@ def get_actual_label_value_by_name(self) -> Mapping[str, str]:
8082 """
8183
8284 actual_label_value_by_name = self ._get_actual_label_value_by_name ()
83- self .log .debug (' actual_label_value_by_name = %s' , actual_label_value_by_name )
85+ self .log .debug (" actual_label_value_by_name = %s" , actual_label_value_by_name )
8486 return actual_label_value_by_name
8587
8688 @memoize
8789 def __get_base_build_names (self ) -> Iterable [str ]:
8890
8991 seen_dockerfiles = set ()
92+
9093 def inner (dockerfile : GenAbcDockerfile ) -> Iterable [str ]:
9194 build_names = []
9295 if dockerfile not in seen_dockerfiles :
@@ -99,7 +102,7 @@ def inner(dockerfile: GenAbcDockerfile) -> Iterable[str]:
99102
100103 base_build_names = tuple (inner (self .dockerfile ))
101104
102- self .log .debug (' base_build_names = %s' , base_build_names )
105+ self .log .debug (" base_build_names = %s" , base_build_names )
103106
104107 return base_build_names
105108
@@ -110,13 +113,13 @@ def get_sha(self) -> str:
110113 """
111114
112115 if lines := Host .execute_and_get_lines_sync (
113- f' docker image ls -q --no-trunc { self .get_tag ()} '
116+ f" docker image ls -q --no-trunc { self .get_tag ()} "
114117 ):
115118 sha = next (iter (lines ))
116119 else :
117- sha = ''
120+ sha = ""
118121
119- self .log .debug (' sha = %s' , sha )
122+ self .log .debug (" sha = %s" , sha )
120123
121124 return sha
122125
@@ -126,9 +129,9 @@ def get_tag(self) -> str:
126129 Construct a tag from the name of the dockerfile.
127130 """
128131
129- tag = f' { self .dockerfile .get_name ()} :latest'
132+ tag = f" { self .dockerfile .get_name ()} :latest"
130133
131- self .log .debug (' tag = %s' , tag )
134+ self .log .debug (" tag = %s" , tag )
132135
133136 return tag
134137
@@ -137,17 +140,17 @@ def __get_wanted_git_hash(self) -> str:
137140 """
138141 Request that GIT provides information about the SHA of the HEAD node.
139142 """
140- wanted_git_hash = Host .execute_and_get_line_sync (' git rev-parse HEAD' )
143+ wanted_git_hash = Host .execute_and_get_line_sync (" git rev-parse HEAD" )
141144
142- self .log .debug (' wanted_git_hash = %s' , wanted_git_hash )
145+ self .log .debug (" wanted_git_hash = %s" , wanted_git_hash )
143146
144147 return wanted_git_hash
145148
146149 def _get_wanted_label_value_by_name (self ) -> Mapping [str , str ]:
147150 """
148151 Get the hash of the image with the label values that are called for by the configuration.
149152 """
150- return {' GitHash' : self .__get_wanted_git_hash ()}
153+ return {" GitHash" : self .__get_wanted_git_hash ()}
151154
152155 @memoize
153156 def get_wanted_label_value_by_name (self ) -> Mapping [str , str ]:
@@ -156,7 +159,7 @@ def get_wanted_label_value_by_name(self) -> Mapping[str, str]:
156159 """
157160 wanted_label_value_by_name = self ._get_wanted_label_value_by_name ()
158161
159- self .log .debug (' wanted_label_value_by_name = %s' , wanted_label_value_by_name )
162+ self .log .debug (" wanted_label_value_by_name = %s" , wanted_label_value_by_name )
160163
161164 return wanted_label_value_by_name
162165
@@ -169,39 +172,35 @@ def main(self) -> None:
169172
170173 cached_images = ""
171174 if self .options .registry :
172- cached_images = ',' .join (
173- [f'{ self .options .registry } /{ base_build_name } :latest'
174- for base_build_name in self .__get_base_build_names ()])
175+ cached_images = "," .join (
176+ [
177+ f"{ self .options .registry } /{ base_build_name } :latest"
178+ for base_build_name in self .__get_base_build_names ()
179+ ]
180+ )
175181 cached_images = f"--cache-from { cached_images } "
176182
177183 self .log .info ('Creating image "%s"' , self .get_tag ())
178184 Host .execute_sync (
179- f'docker buildx build'
180- f' -f { self .dockerfile .path } '
181- f' -t { self .get_tag ()} '
182-
183- f'''{ '' .join ([
185+ f"docker buildx build"
186+ f" -f { self .dockerfile .path } "
187+ f" -t { self .get_tag ()} "
188+ f"""{ '' .join ([
184189 f' --label { name } ="{ value } "'
185190 for name , value
186191 in (self .get_wanted_label_value_by_name ()).items ()
187- ])} '''
188-
192+ ])} """
189193 # Keep metadata about layers so that they can be used as a cache source.
190- f' --build-arg BUILDKIT_INLINE_CACHE=1'
191-
192- f' --platform linux/{ self .options .platform } '
193-
194+ f" --build-arg BUILDKIT_INLINE_CACHE=1"
195+ f" --platform linux/{ self .options .platform } "
194196 # Required to run production.
195- f' --shm-size 1gb'
196-
197+ f" --shm-size 1gb"
197198 # Allow cloning repos with ssh.
198- f' --ssh default'
199-
200- f' { cached_images } '
201-
202- f' { GaiaPath .repo ()} '
199+ f" --ssh default"
200+ f" { cached_images } "
201+ f" { GaiaPath .repo ()} "
203202 )
204- Host .execute_sync (' docker image prune -f' )
203+ Host .execute_sync (" docker image prune -f" )
205204
206205 # pylint: disable=import-outside-toplevel
207206 #
@@ -216,7 +215,9 @@ def cli_entrypoint(self) -> None:
216215 build = self
217216 else :
218217 from gdev .cmd .gen ._custom .build import GenCustomBuild
218+
219219 build = GenCustomBuild (options = self .options , base_build = self )
220220
221221 build .run ()
222+
222223 # pylint: enable=import-outside-toplevel
0 commit comments