Skip to content

Commit eb5a67f

Browse files
authored
docker build: make sure venvs are owned by flytekit (#3299)
1 parent 025d9a9 commit eb5a67f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

flytekit/image_spec/default_builder.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
--mount=type=bind,target=uv.lock,src=uv.lock \
3030
--mount=type=bind,target=pyproject.toml,src=pyproject.toml \
3131
$PIP_SECRET_MOUNT \
32-
uv sync $PIP_INSTALL_ARGS
32+
uv sync $PIP_INSTALL_ARGS && \
33+
chown -R flytekit /root/.venv
3334
WORKDIR /
3435
3536
# Update PATH and UV_PYTHON to point to the venv created by uv sync
@@ -54,12 +55,12 @@
5455
--mount=type=bind,target=poetry.lock,src=poetry.lock \
5556
--mount=type=bind,target=pyproject.toml,src=pyproject.toml \
5657
$PIP_SECRET_MOUNT \
57-
poetry install $PIP_INSTALL_ARGS
58-
58+
poetry install $PIP_INSTALL_ARGS && \
59+
chown -R flytekit /root/.venv
5960
WORKDIR /
6061
6162
# Update PATH and UV_PYTHON to point to venv
62-
ENV PATH="/root/.venv/bin:$$PATH" \
63+
ENV PATH="/root/.venv/bin:$$PATH" \
6364
UV_PYTHON=/root/.venv/bin/python
6465
"""
6566
)
@@ -81,6 +82,7 @@
8182
$APT_PACKAGES
8283
""")
8384

85+
# make sure that micromamba python installation is owned by flytekit user
8486
MICROMAMBA_INSTALL_COMMAND_TEMPLATE = Template("""\
8587
RUN --mount=type=cache,sharing=locked,mode=0777,target=/opt/micromamba/pkgs,\
8688
id=micromamba \
@@ -91,7 +93,8 @@
9193
python=$PYTHON_VERSION $CONDA_PACKAGES \
9294
|| micromamba install -n runtime --root-prefix /opt/micromamba \
9395
-c conda-forge $CONDA_CHANNELS \
94-
python=$PYTHON_VERSION $CONDA_PACKAGES )
96+
python=$PYTHON_VERSION $CONDA_PACKAGES ) && \
97+
chown -R flytekit /opt/micromamba
9598
""")
9699

97100
DOCKER_FILE_TEMPLATE = Template("""\
@@ -108,6 +111,9 @@
108111
[ -f /etc/ssl/certs/ca-certificates.crt ] || \
109112
mkdir -p /etc/ssl/certs/ && cp /tmp/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
110113
114+
RUN id -u flytekit || useradd --create-home --shell /bin/bash flytekit
115+
RUN chown -R flytekit /root && chown -R flytekit /home
116+
111117
$INSTALL_PYTHON_TEMPLATE
112118
113119
# Configure user space
@@ -119,7 +125,7 @@
119125
SSL_CERT_DIR=/etc/ssl/certs \
120126
$ENV
121127
122-
$UV_PYTHON_INSTALL_COMMAND
128+
$PYTHON_INSTALL_COMMAND
123129
124130
# Adds nvidia just in case it exists
125131
ENV PATH="$$PATH:/usr/local/nvidia/bin:/usr/local/cuda/bin" \
@@ -134,9 +140,6 @@
134140
RUN --mount=type=cache,sharing=locked,mode=0777,target=/root/.cache/uv,id=uv \
135141
--mount=from=uv,source=/uv,target=/usr/bin/uv $RUN_COMMANDS
136142
137-
RUN id -u flytekit || useradd --create-home --shell /bin/bash flytekit
138-
RUN chown -R flytekit /root && chown -R flytekit /home
139-
140143
WORKDIR /root
141144
SHELL ["/bin/bash", "-c"]
142145
@@ -340,7 +343,7 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path):
340343
)
341344
raise ValueError(msg)
342345

343-
uv_python_install_command = prepare_python_install(image_spec, tmp_dir)
346+
python_install_command = prepare_python_install(image_spec, tmp_dir)
344347
env_dict = {"PYTHONPATH": "/root"}
345348

346349
if image_spec.env:
@@ -426,11 +429,11 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path):
426429
_f_img_id_env = f"{_F_IMG_ID}={image_spec.id}"
427430

428431
docker_content = DOCKER_FILE_TEMPLATE.substitute(
429-
UV_PYTHON_INSTALL_COMMAND=uv_python_install_command,
430-
APT_INSTALL_COMMAND=apt_install_command,
431432
INSTALL_PYTHON_TEMPLATE=python_install_template.template,
432433
EXTRA_PATH=python_install_template.extra_path,
433434
PYTHON_EXEC=python_install_template.python_exec,
435+
APT_INSTALL_COMMAND=apt_install_command,
436+
PYTHON_INSTALL_COMMAND=python_install_command,
434437
BASE_IMAGE=base_image,
435438
ENV=env,
436439
_F_IMG_ID_ENV=_f_img_id_env,

0 commit comments

Comments
 (0)