-
Notifications
You must be signed in to change notification settings - Fork 302
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
adjust COPY behavior for files and directories to match desired struc… #3047
Conversation
…ture Signed-off-by: Samhita Alla <aallasamhita@gmail.com>
Signed-off-by: Samhita Alla <aallasamhita@gmail.com>
Code Review Agent Run #83a536Actionable Suggestions - 1
Review Details
|
Changelist by BitoThis pull request implements the following key changes.
|
copy_commands.append(f"COPY --chown=flytekit {src_path.as_posix()} /root/{src_path.name}/") | ||
else: | ||
shutil.copy(src_path, dst_path) | ||
copy_commands.append(f"COPY --chown=flytekit {src_path.as_posix()} /root/{src_path.parent.as_posix()}/") | ||
copy_commands.append(f"COPY --chown=flytekit {src_path.as_posix()} /root/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider consolidating the COPY
commands to use a consistent destination path /root/
for both files and directories. Currently, directories are copied to /root/{name}/
while files are copied to /root/
, which could lead to confusion.
Code suggestion
Check the AI-generated fix before applying
- copy_commands.append(f"COPY --chown=flytekit {src_path.as_posix()} /root/{src_path.name}/")
- copy_commands.append(f"COPY --chown=flytekit {src_path.as_posix()} /root/")
+ copy_commands.append(f"COPY --chown=flytekit {src_path.as_posix()} /root/")
+ copy_commands.append(f"COPY --chown=flytekit {src_path.as_posix()} /root/")
Code Review Run #83a536
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3047 +/- ##
===========================================
+ Coverage 47.23% 82.79% +35.55%
===========================================
Files 202 3 -199
Lines 21355 186 -21169
Branches 2744 0 -2744
===========================================
- Hits 10088 154 -9934
+ Misses 10776 32 -10744
+ Partials 491 0 -491 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Samhita Alla <aallasamhita@gmail.com>
Code Review Agent Run #27f2b7Actionable Suggestions - 0Review Details
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure about doing this. For example, this would work locally but not remotely if the structure is not preserved:
MY_LOCAL_FILE = "my_dir/data/my_file.txt"
image = ImageSpec(
copy=[MY_LOCAL_FILE]
)
@task(container_image=image)
def look_at_file() -> str:
with open(MY_LOCAL_FILE, "r") as f:
return f.read()
The other issue is with files with the same name, but in different directories:
image = ImageSpec(
copy=["dir1/data/my_file.txt", "dir2/my_file.txt"]
)
@thomasjpfan we don't really need to preserve the path for files as the user usually expects the files to be available in the working directory. but i understand your concerns. how about we let the user specify the destination path? i can modify the code accordingly. the file will be copied to /root, so the path must be: i also think we shouldn't set |
I'm okay with this, but I want to keep support for
I just tried this: from flytekit import ImageSpec, task
MY_FILE = "hello.txt"
image = ImageSpec(copy=[MY_FILE], registry="localhost:30000")
@task(container_image=image)
def read() -> str:
with open(MY_FILE) as f:
return f.read() where
For the image builder, it hard codes the workdir as |
hmm.. could be because the working directory is set to root by default.
since image spec doesn't support setting a custom workdir, i agree that we need to default to i’ll close this issue for now. i think specifying destination paths is something we can plan for down the road. |
Tracking issue
Why are the changes needed?
This update modifies the COPY logic to ensure files and directories are copied directly to /root/ without preserving the entire source path structure.
What changes were proposed in this pull request?
Generated COPY commands:
How was this patch tested?
Setup process
Screenshots
Check all the applicable boxes
Related PRs
Docs link
Summary by Bito
This PR optimizes Docker image building by simplifying COPY command behavior in the image specification builder. The changes streamline how files are copied directly to the /root/ directory, eliminating unnecessary path nesting and ensuring a cleaner directory structure. The modification prevents full source path preservation, making Docker images more maintainable. A security concern was identified regarding potential path traversal issues in the implementation.Unit tests added: False
Estimated effort to review (1-5, lower is better): 1