Skip to content

feat: add support for DockerfileInline #4305

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tushar5526
Copy link
Contributor

@tushar5526 tushar5526 commented Jun 4, 2025

Fixes #4108

As nerdctl currently uses "nerdctl build" to build the service images, write the inline file to a temporary file and use "-f" to specify the temporary dockerfile.

TODO: Add tests if the approach looks fine.

@tushar5526 tushar5526 marked this pull request as draft June 4, 2025 21:01
@tushar5526
Copy link
Contributor Author

I was a bit confused about where to place this logic: writing the inline file to a temporary path and then modifying the build command to build using that file.

It seems like Build object on Service is something that is meant to be reusable, so I placed the logic of temporary file generation at the time of parsing the service and generating the Build config.

@tushar5526
Copy link
Contributor Author

@apostasie, can I get a cursory review of the approach?

@apostasie
Copy link
Contributor

Hey @tushar5526
Looks fine to me.

You do need to make sure that dockerfile and dockerfileinline cannot be specified together though:
https://docs.docker.com/reference/compose-file/build/

@tushar5526
Copy link
Contributor Author

It looks like composecli package "github.com/compose-spec/compose-go/v2/cli" is already doing that job for me.

@tushar5526 tushar5526 marked this pull request as ready for review June 22, 2025 13:13
@tushar5526 tushar5526 force-pushed the add-support-for-dockerfileinline branch from 055fe8e to 8880063 Compare June 22, 2025 13:16
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Please squash and sign off the commits.
(make sure that the Signed-off-by: NAME <EMAIL> line with your real name is included in the commit message)

@tushar5526 tushar5526 force-pushed the add-support-for-dockerfileinline branch from 8880063 to 5651e76 Compare June 27, 2025 15:20
@tushar5526
Copy link
Contributor Author

Done, thanks!

@AkihiroSuda
Copy link
Member

CI is failing
https://github.com/containerd/nerdctl/actions/runs/15929816575/job/44936014200?pr=4305

FAIL - has whitespace errors. See git show --check 5651e76d85e12092b65f3e35b8994d2244e35698.

@tushar5526 tushar5526 force-pushed the add-support-for-dockerfileinline branch from 5651e76 to 976b5ca Compare July 11, 2025 18:24
@tushar5526
Copy link
Contributor Author

I think its good to go now.

@tushar5526 tushar5526 requested a review from AkihiroSuda July 12, 2025 13:39
@AkihiroSuda AkihiroSuda added this to the v2.1.4 milestone Jul 12, 2025
}
b.BuildArgs = append(b.BuildArgs, "-f="+tmpFile.Name())
}

Copy link
Member

Choose a reason for hiding this comment

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

The tmp file has to be removed on completion of the build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, at the moment, it does not clear it up. We are creating this file at the "service parser" phase, the actual build command just gets back the modified BuildArgs. I will take a look and see if I can clear up the tmp file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like I can store the dockerfile_inline value in the Build struct, and then during the build phase, I can create the temporary file, use it for the build, and then clear it up.

type Build struct {
	Force     bool     // force build even if already present
	BuildArgs []string // {"-t", "example.com/foo", "--target", "foo", "/path/to/ctx"}
	// something like follows
	DockerfileInline string
       // TODO: call BuildKit API directly without executing `nerdctl build`
}

Do you have any objections to putting it there?

Copy link
Member

Choose a reason for hiding this comment

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

No objection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tushar5526 tushar5526 force-pushed the add-support-for-dockerfileinline branch 2 times, most recently from 199d1be to cd54169 Compare July 24, 2025 17:38
As nerdctl currently uses "nerdctl build" to build the service
images, write the inline file to a temporary file and use "-f"
to specify the temporary dockerfile.

Signed-off-by: Tushar Gupta <[email protected]>
@tushar5526 tushar5526 force-pushed the add-support-for-dockerfileinline branch from cd54169 to fe8ffa5 Compare July 24, 2025 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nerdctl compose does not support dockerfile_inline
3 participants