Skip to content

Commit 3745ccc

Browse files
committed
support colon paths
1 parent ce3037d commit 3745ccc

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

hyperbrowser/client/managers/sandboxes/dockerfile_analysis.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import re
1212
import shlex
1313
from typing import Dict, List, Optional, Tuple
14-
from urllib.parse import urlsplit
1514

1615

1716
_KNOWN_INSTRUCTIONS = frozenset(
@@ -291,8 +290,4 @@ def _is_official_dockerfile_frontend(reference: str) -> bool:
291290
def _is_remote_add_source(source: str) -> bool:
292291
if _SCP_GIT_SOURCE_PATTERN.match(source):
293292
return True
294-
try:
295-
parsed = urlsplit(source)
296-
except ValueError:
297-
return False
298-
return bool(parsed.scheme and parsed.scheme.lower() != "file")
293+
return source.startswith(("http://", "https://", "git://", "ssh://"))

tests/fixtures/docker_context_parity.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@
8585
{
8686
"name": "add-arbitrary-uri-scheme",
8787
"dockerfile": "FROM scratch\nADD oci-layout://example/image /image/\n",
88-
"goSourceGroups": [],
88+
"goSourceGroups": [["oci-layout://example/image"]],
89+
"goFallback": "",
90+
"pythonExpectation": "exact"
91+
},
92+
{
93+
"name": "add-colon-paths-are-local",
94+
"dockerfile": "FROM scratch\nADD assets:latest /asset/\nADD http:archive /archive/\n",
95+
"goSourceGroups": [["assets:latest"], ["http:archive"]],
8996
"goFallback": "",
9097
"pythonExpectation": "exact"
9198
},

tests/test_dockerfile_analysis.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@
6464
),
6565
pytest.param(
6666
"""\
67+
FROM scratch
68+
ADD assets:latest /colon/
69+
ADD http:archive.tar /http-colon/
70+
ADD oci-layout://example/image /unsupported-scheme/
71+
""",
72+
[
73+
["assets:latest"],
74+
["http:archive.tar"],
75+
["oci-layout://example/image"],
76+
],
77+
"",
78+
id="add-colon-paths-and-unsupported-schemes-are-local",
79+
),
80+
pytest.param(
81+
"""\
6782
FROM scratch AS generated
6883
RUN --mount=type=bind,source=src,target=/src true
6984
RUN --mount=source=vendor,target=/vendor true

tests/test_sandbox_image_build_helpers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,25 @@ def test_remote_dockerfile_context_is_deterministic_and_sparse(tmp_path):
282282
second.cleanup()
283283

284284

285+
def test_remote_dockerfile_context_includes_colon_named_add_sources(tmp_path):
286+
(tmp_path / "Dockerfile").write_text(
287+
"FROM scratch\nADD assets:latest /assets/\nADD http:archive /archive/\n"
288+
)
289+
(tmp_path / "assets:latest").write_text("asset\n")
290+
(tmp_path / "http:archive").write_text("archive\n")
291+
292+
packaged = image_build.package_docker_build_context_manifest(tmp_path)
293+
try:
294+
assert packaged.manifest.context_mode == "sparse"
295+
archived_names = set()
296+
for artifact in packaged.bundles.values():
297+
with tarfile.open(artifact.path, "r:gz") as archive:
298+
archived_names.update(name.rstrip("/") for name in archive.getnames())
299+
assert {"assets:latest", "http:archive"} <= archived_names
300+
finally:
301+
packaged.cleanup()
302+
303+
285304
def test_remote_dockerfile_context_falls_back_for_variable_source(tmp_path):
286305
(tmp_path / "Dockerfile").write_text("FROM scratch\nCOPY $SOURCE /app/\n")
287306
(tmp_path / "payload.txt").write_text("payload\n")

0 commit comments

Comments
 (0)