Skip to content

feat: added option to persist auto-generated Dockerfile #17866

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

Merged
merged 16 commits into from
May 19, 2025

Conversation

AliLordLoss
Copy link
Contributor

@AliLordLoss AliLordLoss commented Apr 19, 2025

Fix for #12938

Adds persist_dockerfile and dockerfile_output_path parameters to the build_docker_image
step. This allows users to keep the auto-generated Dockerfile for inspection or reuse.

By default, the Dockerfile is still deleted after the build unless persist_dockerfile is set to True.

Closes #12938

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

@github-actions github-actions bot added the enhancement An improvement of an existing feature label Apr 21, 2025
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @AliLordLoss — this is shaping up nicely!

I have two small requests to help make this even better:

  1. In build_docker_image, could you add a log message when the generated Dockerfile is saved? It would be helpful to let users know they should update the dockerfile field in their configuration, since otherwise a new file will be generated on each run.
  2. Could you add a couple of tests to cover the new functionality?

Let me know if you have any questions or need help with either!

@AliLordLoss
Copy link
Contributor Author

Thanks for the PR, @AliLordLoss — this is shaping up nicely!

I have two small requests to help make this even better:

  1. In build_docker_image, could you add a log message when the generated Dockerfile is saved? It would be helpful to let users know they should update the dockerfile field in their configuration, since otherwise a new file will be generated on each run.
  2. Could you add a couple of tests to cover the new functionality?

Let me know if you have any questions or need help with either!

Hi there @desertaxle, I'll certainly try to address your requests.
Thanks for the guidance, I'll make sure to let you know if I had any sort of problem.

@AliLordLoss
Copy link
Contributor Author

@desertaxle I added some tests but they're failing, it seems like it's using the old version of the build_docker_image rather than the one with my modifications.
Should I modify a different test file? E.g. src/integrations/prefect-docker/tests/deployments/test_steps.py??? I tried doing it but couldn't even run the file, it complained about not being able to import prefect_docker.

@desertaxle
Copy link
Member

Yep, you should add tests to src/integrations/prefect-docker/tests/deployments/test_steps.py. You can install an editable version of prefect-docker by going into src/integrations/prefect-docker and running uv sync. After that, you can run the prefect-docker tests by running uv run pytest tests.

@@ -221,6 +238,18 @@ def build_docker_image(
with Path(temp_dockerfile).open("w") as f:
f.writelines(line + "\n" for line in lines)

if persist_dockerfile:
logger.info(
"Persisting auto-generated Dockerfile to disk. You can use `dockerfile_output_path` to specify the output path."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is closer to the log message I had in mind:

Suggested change
"Persisting auto-generated Dockerfile to disk. You can use `dockerfile_output_path` to specify the output path."
f"Persisting auto-generated Dockerfile to {dockerfile_output_path or 'Dockerfile.generated'}. Please update your 'dockerfile' value to use this Dockerfile for subsequent runs."

@AliLordLoss AliLordLoss requested a review from desertaxle April 29, 2025 14:45
@AliLordLoss AliLordLoss requested a review from desertaxle May 8, 2025 16:32
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AliLordLoss, I think you might have accidentally reverted your code changes instead of the changes to tests/cli/test_deploy.py 😅

@AliLordLoss
Copy link
Contributor Author

Hey @AliLordLoss, I think you might have accidentally reverted your code changes instead of the changes to tests/cli/test_deploy.py 😅

Yeah, sorry 😅
Fixed it

@AliLordLoss AliLordLoss requested a review from desertaxle May 18, 2025 09:03
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sticking with the @AliLordLoss! I have one more small nit, but once that's addressed, this will be good to merge!

AliLordLoss and others added 2 commits May 19, 2025 18:47
Co-authored-by: Alex Streed <desertaxle@users.noreply.github.com>
@AliLordLoss AliLordLoss requested a review from desertaxle May 19, 2025 15:18
@AliLordLoss
Copy link
Contributor Author

Thanks for sticking with the @AliLordLoss! I have one more small nit, but once that's addressed, this will be good to merge!

You're welcome! That's done as well.

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @AliLordLoss!

@desertaxle desertaxle merged commit 08aef50 into PrefectHQ:main May 19, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to save the Dockerfile created by build_docker_image deployment step
2 participants