Commit b8b3c72 1 parent 908d245 commit b8b3c72 Copy full SHA for b8b3c72
File tree 2 files changed +52
-1
lines changed
src/python/pants/backend/docker/subsystems
2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -206,3 +206,39 @@ def test_generate_lockfile_without_python_backend() -> None:
206
206
"--resolve=dockerfile-parser" ,
207
207
]
208
208
).assert_success ()
209
+
210
+
211
+ def test_baseimage_dep_inference (rule_runner : RuleRunner ) -> None :
212
+ # We use a single run to grab all information, rather than parametrizing the test to save on
213
+ # rule invocations.
214
+ base_image_tags = dict (
215
+ BASE_IMAGE_1 = ":sibling" ,
216
+ BASE_IMAGE_2 = ":sibling@a=42,b=c" ,
217
+ BASE_IMAGE_3 = "else/where:weird#name@with=param" ,
218
+ BASE_IMAGE_4 = "//src/common:name@parametrized=foo-bar.1" ,
219
+ BASE_IMAGE_5 = "should/allow/default-target-name" ,
220
+ )
221
+
222
+ rule_runner .write_files (
223
+ {
224
+ "test/BUILD" : "docker_image()" ,
225
+ "test/Dockerfile" : "\n " .join (
226
+ dedent (
227
+ f"""\
228
+ ARG { arg } ="{ tag } "
229
+ FROM ${ arg }
230
+ """
231
+ )
232
+ for arg , tag in base_image_tags .items ()
233
+ )
234
+ + dedent (
235
+ """\
236
+ ARG DECOY="this is not a target address"
237
+ FROM $DECOY
238
+ """
239
+ ),
240
+ }
241
+ )
242
+ addr = Address ("test" )
243
+ info = rule_runner .request (DockerfileInfo , [DockerfileInfoRequest (addr )])
244
+ assert info .from_image_build_args .to_dict () == base_image_tags
Original file line number Diff line number Diff line change @@ -28,7 +28,22 @@ class ParsedDockerfileInfo:
28
28
29
29
_address_regexp = re .compile (
30
30
r"""
31
- (?://)?[^:# ]*:[^:#!@?/\= ]+(?:\#[^:#!@?= ]+)?$
31
+ # Optionally root:ed.
32
+ (?://)?
33
+ # Optional path.
34
+ [^:# ]*
35
+ # Optional target name.
36
+ (?::[^:#!@?/\= ]+)?
37
+ # Optional generated name.
38
+ (?:\#[^:#!@?= ]+)?
39
+ # Optional parametrizations.
40
+ (?:@
41
+ # key=value
42
+ [^=: ]+=[^,: ]*
43
+ # Optional additional `,key=value`s
44
+ (?:,[^=: ]+=[^,: ]*)*
45
+ )?
46
+ $
32
47
""" ,
33
48
re .VERBOSE ,
34
49
)
You can’t perform that action at this time.
0 commit comments