Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker commands in ImageSpec #2676

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
662f15e
feat: add docker commands in ImageSpec
mao3267 Aug 9, 2024
4f670dc
use private-key (#2645)
Future-Outlier Aug 2, 2024
b4e7ece
Don't call remote when --help in remote-X (#2642)
wild-endeavor Aug 2, 2024
a22792f
Bump grpc receive message size (#2640)
wild-endeavor Aug 3, 2024
fbba823
Raise an exception when filters' value isn't a list. (#2576)
arbaobao Aug 5, 2024
b946674
Update error message for TypeTransformerFailedError (#2648)
wayner0628 Aug 5, 2024
ffc030e
[Error Message] Dataclasses Mismatched Type (#2650)
Future-Outlier Aug 6, 2024
ac8563d
Added warning for command list and shell true (#2653)
pryce-turner Aug 6, 2024
b59346a
In `FlyteRemote.upload_file`, pass the file object directly rather th…
redartera Aug 6, 2024
f11f397
Modify test_array_node.py to support running in python 3.8 (#2652)
eapolinario Aug 6, 2024
901fe4f
Handle common cases of mutable default arguments explicitly (#2651)
eapolinario Aug 6, 2024
9e0dbf5
Allow a hash method to be present for numpy arrays (#2649)
demmerichs Aug 6, 2024
140b58f
return exceptions when gathering (#2657)
wild-endeavor Aug 7, 2024
78a6219
Correct FlyteFile docstring (#2658)
ppiegaze Aug 8, 2024
8d229d9
Remove pip cache after install (#2662)
thomasjpfan Aug 8, 2024
59b5932
Adds validation to image_spec for list of strings (#2655)
thomasjpfan Aug 8, 2024
be3b145
Make elastic timeout configurable for HorovovJob. (#2631)
supercharleszhu Aug 8, 2024
9ea6b23
Fix overriding of loader_args task resolver in papermill plugin (#2660)
eapolinario Aug 8, 2024
e83c240
Catch all exceptions when rendering python dependencies (#2664)
thomasjpfan Aug 8, 2024
b3dbc08
Don't check the retrun statement for reference_launch_plan (#2665)
pingsutw Aug 8, 2024
72319a2
Bump flyteidl to 1.13.1 (#2666)
mao3267 Aug 9, 2024
5a72f98
Merge branch 'master' of https://github.com/mao3267/flytekit into add…
mao3267 Aug 11, 2024
8446503
fix: raise exception for docker commands in envd builder
mao3267 Aug 13, 2024
0a85ccc
test: add unit tests for docker commands
mao3267 Aug 13, 2024
f18c283
fix: modify error message
mao3267 Aug 16, 2024
f073069
test: raise exception for docker commands in envd builder
mao3267 Aug 16, 2024
f2c3679
test: ImageSpec with docker commands
mao3267 Aug 16, 2024
767ef0f
Merge branch 'master' of https://github.com/mao3267/flytekit into add…
mao3267 Aug 16, 2024
cca874b
fix: add docker commands to parameters_str_list
mao3267 Aug 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions flytekit/image_spec/default_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

$COPY_COMMAND_RUNTIME
RUN $RUN_COMMANDS
$DOCKER_COMMANDS

WORKDIR /root
SHELL ["/bin/bash", "-c"]
Expand Down Expand Up @@ -210,6 +211,11 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path):
else:
run_commands = ""

if image_spec.docker_commands:
pingsutw marked this conversation as resolved.
Show resolved Hide resolved
docker_commands = "\n".join(image_spec.docker_commands)
else:
docker_commands = ""

docker_content = DOCKER_FILE_TEMPLATE.substitute(
PYTHON_VERSION=python_version,
UV_PYTHON_INSTALL_COMMAND=uv_python_install_command,
Expand All @@ -221,6 +227,7 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path):
COPY_COMMAND_RUNTIME=copy_command_runtime,
ENTRYPOINT=entrypoint,
RUN_COMMANDS=run_commands,
DOCKER_COMMANDS=docker_commands,
)

dockerfile_path = tmp_dir / "Dockerfile"
Expand Down Expand Up @@ -249,6 +256,7 @@ class DefaultImageBuilder(ImageSpecBuilder):
"pip_index",
# "registry_config",
"commands",
"docker_commands",
}

def build_image(self, image_spec: ImageSpec) -> str:
Expand Down
18 changes: 18 additions & 0 deletions flytekit/image_spec/image_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ImageSpec:
commands: Command to run during the building process
tag_format: Custom string format for image tag. The ImageSpec hash passed in as `spec_hash`. For example,
to add a "dev" suffix to the image tag, set `tag_format="{spec_hash}-dev"`
docker_commands: List of docker commands to run during the building process
"""

name: str = "flytekit"
Expand All @@ -72,6 +73,7 @@ class ImageSpec:
entrypoint: Optional[List[str]] = None
commands: Optional[List[str]] = None
tag_format: Optional[str] = None
docker_commands: Optional[List[str]] = None
pingsutw marked this conversation as resolved.
Show resolved Hide resolved

def __post_init__(self):
self.name = self.name.lower()
Expand All @@ -87,6 +89,7 @@ def __post_init__(self):
"pip_extra_index_url",
"entrypoint",
"commands",
"docker_commands",
]
for parameter in parameters_str_list:
attr = getattr(self, parameter)
Expand Down Expand Up @@ -227,6 +230,21 @@ def with_apt_packages(self, apt_packages: Union[str, List[str]]) -> "ImageSpec":

return new_image_spec

def with_docker_commands(self, docker_commands: Union[str, List[str]]) -> "ImageSpec":
"""
Builder that returns a new image spec with additional list of docker commands that will be executed during the building process.
"""
new_image_spec = copy.deepcopy(self)
if new_image_spec.docker_commands is None:
new_image_spec.docker_commands = []

if isinstance(docker_commands, List):
new_image_spec.docker_commands.extend(docker_commands)
else:
new_image_spec.docker_commands.append(docker_commands)

return new_image_spec

def force_push(self) -> "ImageSpec":
"""
Builder that returns a new image spec with force push enabled.
Expand Down
3 changes: 3 additions & 0 deletions plugins/flytekit-envd/flytekitplugins/envd/image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class EnvdImageSpecBuilder(ImageSpecBuilder):
def build_image(self, image_spec: ImageSpec):
cfg_path = create_envd_config(image_spec)

if image_spec.docker_commands:
raise ValueError("Docker commands are not supported in envd builder.")

if image_spec.registry_config:
bootstrap_command = f"envd bootstrap --registry-config {image_spec.registry_config}"
execute_command(bootstrap_command)
Expand Down
9 changes: 9 additions & 0 deletions plugins/flytekit-envd/tests/test_image_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,12 @@ def build():
)

assert contents == expected_contents

def test_image_spec_with_envd_builder_exception():
image_spec = ImageSpec(
name="envd_image",
builder="envd",
docker_commands=["RUN ls"],
)
with pytest.raises(ValueError):
ImageBuildEngine.build(image_spec)
8 changes: 6 additions & 2 deletions tests/flytekit/unit/core/image_spec/test_default_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ 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"]
pip_extra_index_url=["https://extra-url.com"],
docker_commands=["RUN git clone https://github.com/flyteorg/flytekit.git", "COPY . /root"],
)

create_docker_context(image_spec, docker_context_path)
Expand All @@ -49,6 +50,8 @@ def test_create_docker_context(tmp_path):
assert "RUN mkdir my_dir" in dockerfile_content
assert "ENTRYPOINT [\"/bin/bash\"]" in dockerfile_content
assert "mkdir -p $HOME" in dockerfile_content
assert "RUN git clone https://github.com/flyteorg/flytekit.git" in dockerfile_content
assert "COPY . /root" in dockerfile_content

requirements_path = docker_context_path / "requirements_uv.txt"
assert requirements_path.exists()
Expand Down Expand Up @@ -171,12 +174,13 @@ def test_build(tmp_path):
name="FLYTEKIT",
python_version="3.12",
env={"MY_ENV": "MY_VALUE"},
apt_packages=["curl"],
apt_packages=["curl", "git"],
conda_packages=["scipy==1.13.0", "numpy"],
packages=["pandas==2.2.1"],
requirements=os.fspath(other_requirements_path),
source_root=os.fspath(source_root),
commands=["mkdir my_dir"],
docker_commands=["RUN git clone https://github.com/flyteorg/flytekit.git", "COPY . /root"],
)

builder = DefaultImageBuilder()
Expand Down
3 changes: 3 additions & 0 deletions tests/flytekit/unit/core/image_spec/test_image_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ def test_image_spec(mock_image_spec_builder):
requirements=REQUIREMENT_FILE,
registry_config=REGISTRY_CONFIG_FILE,
entrypoint=["/bin/bash"],
docker_commands=["RUN ls"],
)
assert image_spec._is_force_push is False

image_spec = image_spec.with_commands("echo hello")
image_spec = image_spec.with_packages("numpy")
image_spec = image_spec.with_apt_packages("wget")
image_spec = image_spec.with_docker_commands(["RUN echo hello"])
image_spec = image_spec.force_push()

assert image_spec.python_version == "3.8"
Expand All @@ -52,6 +54,7 @@ def test_image_spec(mock_image_spec_builder):
assert image_spec.commands == ["echo hello"]
assert image_spec._is_force_push is True
assert image_spec.entrypoint == ["/bin/bash"]
assert image_spec.docker_commands == ["RUN ls", "RUN echo hello"]

tag = calculate_hash_from_image_spec(image_spec)
assert "=" != tag[-1]
Expand Down
Loading