Skip to content

Commit f85a066

Browse files
authored
Support nested image spec (#3284)
Signed-off-by: Akinori Mitani <akinori@artera.ai>
1 parent 147c405 commit f85a066

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

flytekit/image_spec/default_builder.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@
8686
id=micromamba \
8787
--mount=from=micromamba,source=/usr/bin/micromamba,target=/usr/bin/micromamba \
8888
micromamba config set use_lockfiles False && \
89-
micromamba create -n runtime --root-prefix /opt/micromamba \
89+
( micromamba create -n runtime --root-prefix /opt/micromamba \
9090
-c conda-forge $CONDA_CHANNELS \
91-
python=$PYTHON_VERSION $CONDA_PACKAGES
91+
python=$PYTHON_VERSION $CONDA_PACKAGES \
92+
|| micromamba install -n runtime --root-prefix /opt/micromamba \
93+
-c conda-forge $CONDA_CHANNELS \
94+
python=$PYTHON_VERSION $CONDA_PACKAGES )
9295
""")
9396

9497
DOCKER_FILE_TEMPLATE = Template("""\
@@ -98,14 +101,15 @@
98101
99102
FROM $BASE_IMAGE
100103
104+
WORKDIR /
101105
USER root
102106
$APT_INSTALL_COMMAND
103107
RUN --mount=from=micromamba,source=/etc/ssl/certs/ca-certificates.crt,target=/tmp/ca-certificates.crt \
104108
[ -f /etc/ssl/certs/ca-certificates.crt ] || \
105109
mkdir -p /etc/ssl/certs/ && cp /tmp/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
106110
107111
RUN id -u flytekit || useradd --create-home --shell /bin/bash flytekit
108-
RUN chown -R flytekit /root && chown -R flytekit /home
112+
RUN chown flytekit /root && chown -R flytekit /home
109113
110114
$INSTALL_PYTHON_TEMPLATE
111115

tests/flytekit/unit/core/image_spec/test_image_spec.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,29 @@ def test_image_spec(mock_image_spec_builder, monkeypatch):
9393
assert image_spec.commands == ["echo hello"]
9494

9595

96+
@pytest.mark.skipif(
97+
os.environ.get("_FLYTEKIT_TEST_IMAGE_BUILD_ENGINE", "0") == "0",
98+
reason="Set _FLYTEKIT_TEST_IMAGE_BUILD_ENGINE=1 to run this test",
99+
)
100+
def test_nested_build(monkeypatch):
101+
monkeypatch.setenv("FLYTE_PUSH_IMAGE_SPEC", "0")
102+
base_image = ImageSpec(
103+
name="base",
104+
packages=["torch"],
105+
python_version="3.11"
106+
)
107+
108+
image_spec = ImageSpec(
109+
name="final",
110+
packages=["pandas"],
111+
python_version="3.11",
112+
base_image=base_image,
113+
)
114+
assert image_spec._is_force_push is False
115+
116+
ImageBuildEngine.build(image_spec)
117+
118+
96119
def test_image_spec_engine_priority():
97120
new_image_name = "fqn.xyz/flytekit"
98121
mock_image_builder_10 = Mock()

0 commit comments

Comments
 (0)