Skip to content

Commit

Permalink
Adds extra-index-url to default image builder (#2636)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas J. Fan <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
  • Loading branch information
thomasjpfan and pingsutw authored Aug 1, 2024
1 parent df94e1c commit ea6fa0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions flytekit/image_spec/default_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,21 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path):
requirements_uv_path = tmp_dir / "requirements_uv.txt"
requirements_uv_path.write_text("\n".join(uv_requirements))

pip_extra = f"--index-url {image_spec.pip_index}" if image_spec.pip_index else ""
uv_python_install_command = UV_PYTHON_INSTALL_COMMAND_TEMPLATE.substitute(PIP_EXTRA=pip_extra)
pip_extra_args = ""

if image_spec.pip_index:
pip_extra_args += f"--index-url {image_spec.pip_index}"
if image_spec.pip_extra_index_url:
extra_urls = [f"--extra-index-url {url}" for url in image_spec.pip_extra_index_url]
pip_extra_args += " ".join(extra_urls)

uv_python_install_command = UV_PYTHON_INSTALL_COMMAND_TEMPLATE.substitute(PIP_EXTRA=pip_extra_args)

if pip_requirements:
requirements_uv_path = tmp_dir / "requirements_pip.txt"
requirements_uv_path.write_text(os.linesep.join(pip_requirements))

pip_python_install_command = PIP_PYTHON_INSTALL_COMMAND_TEMPLATE.substitute(PIP_EXTRA=pip_extra)
pip_python_install_command = PIP_PYTHON_INSTALL_COMMAND_TEMPLATE.substitute(PIP_EXTRA=pip_extra_args)
else:
pip_python_install_command = ""

Expand Down
2 changes: 2 additions & 0 deletions tests/flytekit/unit/core/image_spec/test_default_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_create_docker_context(tmp_path):
source_root=os.fspath(source_root),
commands=["mkdir my_dir"],
entrypoint=["/bin/bash"],
pip_extra_index_url=["https://extra-url.com"]
)

create_docker_context(image_spec, docker_context_path)
Expand All @@ -42,6 +43,7 @@ def test_create_docker_context(tmp_path):
assert "scipy==1.13.0 numpy" in dockerfile_content
assert "python=3.12" in dockerfile_content
assert "--requirement requirements_uv.txt" in dockerfile_content
assert "--extra-index-url" in dockerfile_content
assert "COPY --chown=flytekit ./src /root" in dockerfile_content
assert "RUN mkdir my_dir" in dockerfile_content
assert "ENTRYPOINT [\"/bin/bash\"]" in dockerfile_content
Expand Down

0 comments on commit ea6fa0d

Please sign in to comment.