-
Notifications
You must be signed in to change notification settings - Fork 496
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 support for dockerfile_inline #1116
base: main
Are you sure you want to change the base?
Conversation
e2c928b
to
f2492f6
Compare
Fixes containers#864 Signed-off-by: Zeglius <[email protected]>
f2492f6
to
da10fdf
Compare
|
||
args = container_to_build_args(c, cnt, args, lambda path: True) | ||
|
||
import os |
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.
Should be imported at the top of the file.
podman_compose.py
Outdated
dockerfile.close() | ||
dockerfile = dockerfile.name | ||
# Dont override the temporary dockerfile | ||
if dockerfile_inline is None: |
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.
Should just be else
podman_compose.py
Outdated
dockerfile.write(dockerfile_inline.encode()) | ||
dockerfile.close() | ||
dockerfile = dockerfile.name | ||
# Dont override the temporary dockerfile |
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.
Obvious comment, not necessary.
podman_compose.py
Outdated
# Error if both `dockerfile_inline` and `dockerfile` are set | ||
if dockerfile and dockerfile_inline: | ||
raise OSError("dockerfile_inline and dockerfile can't be used simultaneously") | ||
# Create a temporary dockerfile |
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.
Obvious comment, not necessary.
if dockerfile and dockerfile_inline: | ||
raise OSError("dockerfile_inline and dockerfile can't be used simultaneously") | ||
# Create a temporary dockerfile | ||
dockerfile = tempfile.NamedTemporaryFile(delete=False, suffix=".containerfile") |
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.
Current code does not remove the temporary file, does it? I think this is primary deficiency of the current approach. Not sure how to best solve it right now.
One solution would be to introduce a list of cleanup functions that need to be called before podman-compose exits. Then pass this list to container_to_build_args
which would append an appropriate os.remove call to that list. And then after podman build
completes, remove the file in e.g. finally
.
Remove temporary dockerfile generated when using dockerfile_inline field
podman_compose.py
Outdated
dockerfile = dockerfile.name | ||
def cleanup_temp_dockfile(): | ||
os.remove(dockerfile) if os.path.exists(dockerfile) else None | ||
list.append(kwargs["cleanup_callbacks"], cleanup_temp_dockfile) |
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.
Why not:
if cleanup_callbacks is not None:
cleanup_callbacks.append(cleanup_temp_dockfile)
podman_compose.py
Outdated
dockerfile.close() | ||
dockerfile = dockerfile.name | ||
def cleanup_temp_dockfile(): | ||
os.remove(dockerfile) if os.path.exists(dockerfile) else None |
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.
Since return value is not used, normal if
is more readable:
if os.path.exists(dockerfile):
os.remove(dockerfile)
podman_compose.py
Outdated
@@ -2471,27 +2472,41 @@ async def compose_push(compose, args): | |||
await compose.podman.run([], "push", [cnt["image"]]) | |||
|
|||
|
|||
def container_to_build_args(compose, cnt, args, path_exists): | |||
def container_to_build_args(compose, cnt, args, path_exists, **kwargs): |
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.
Better have cleanup_callbacks=None explicitly
Serious issues have been fixes, stylistic issues is the only thing left. Thank you for looking into this feature. |
…ed to None Signed-off-by: Zeglius <[email protected]>
Signed-off-by: Zeglius <[email protected]>
Signed-off-by: Zeglius <[email protected]>
Fixes #864
We dump the contents of
service.*.build.dockerfile_inline
in a temporary file, which gets fed to the-f
flag.Also raises errors whenever both
dockerfile_inline
anddockerfile
are set, just like docker does, see https://docs.docker.com/reference/compose-file/build/#dockerfile_inline