Skip to content

fix(builder): Allow custom dockerfile names when building#322

Open
craciunoiuc wants to merge 1 commit into
stagingfrom
craciunoiuc/use-exact-dockerfile-name
Open

fix(builder): Allow custom dockerfile names when building#322
craciunoiuc wants to merge 1 commit into
stagingfrom
craciunoiuc/use-exact-dockerfile-name

Conversation

@craciunoiuc
Copy link
Copy Markdown
Member

@craciunoiuc craciunoiuc commented May 12, 2026

Previously, the name was cut from the path, so it used the default 'Dockerfile' name breaking functionality.

Depends on: unikraft-cloud/x#253
Merged

Closes: TOOL-855

TODOs left:
* Bump the library after merging
* Update the golden files for tests when they start behaving

@craciunoiuc craciunoiuc requested a review from jedevc May 12, 2026 12:16
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/use-exact-dockerfile-name branch from c271649 to 6b04c57 Compare May 12, 2026 12:42
@jedevc
Copy link
Copy Markdown
Member

jedevc commented May 14, 2026

This shouldn't be merged as is, it should use the kraftfile dockerfile property.

@craciunoiuc
Copy link
Copy Markdown
Member Author

correct

@craciunoiuc craciunoiuc marked this pull request as draft May 14, 2026 09:23
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/use-exact-dockerfile-name branch from 6b04c57 to 689c4aa Compare May 14, 2026 16:03
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/use-exact-dockerfile-name branch 2 times, most recently from 6be6327 to f0080e3 Compare May 22, 2026 11:03
@craciunoiuc craciunoiuc requested a review from Copilot May 22, 2026 11:04
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/use-exact-dockerfile-name branch from f0080e3 to 5aa4479 Compare May 22, 2026 11:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the build pipeline to support building rootfs images from Dockerfiles with non-default filenames by introducing an explicit Rootfs.Dockerfile field, wiring it through Kraftfile parsing, and passing the correct BuildKit frontend attributes for Dockerfile selection.

Changes:

  • Add FSOpts.Dockerfile and plumb it from Kraftfile (rootfs.source.dockerfile) into builder options.
  • Update BuildKit LocalDirs/frontend attrs so the Dockerfile frontend can be pointed at a custom filename.
  • Add integration/E2E test coverage for building with a custom Dockerfile name and bump unikraft.com/x/kraftfile.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/builder/rootfs.go Adjusts Dockerfile build context wiring to BuildKit; updates dockerfile-path validation/error messages.
internal/builder/rootfs_test.go Adds integration test for custom Dockerfile filename builds.
internal/builder/kraftfile.go Adapts to new kraftfile FSSource shape and propagates dockerfile to BuildOpts.
internal/builder/kraftfile_test.go Updates tests for new kraftfile source structure and adds dockerfile-field cases.
internal/builder/build.go Extends FSOpts with a Dockerfile field.
cmd/unikraft/integration/build_test.go Adds end-to-end test for rootfs.source.dockerfile in Kraftfile.
go.mod / go.sum Bumps unikraft.com/x/kraftfile dependency and updates sums.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/builder/rootfs.go
Comment thread internal/builder/rootfs.go
Comment thread internal/builder/rootfs.go
Comment thread internal/builder/kraftfile.go Outdated
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/use-exact-dockerfile-name branch 2 times, most recently from 0f1f7c0 to 5bdc9d2 Compare May 22, 2026 11:42
@craciunoiuc craciunoiuc marked this pull request as ready for review May 22, 2026 11:43
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/use-exact-dockerfile-name branch from 5bdc9d2 to 6cc644d Compare May 25, 2026 12:06
Comment thread internal/builder/kraftfile_test.go
Comment thread internal/builder/rootfs.go Outdated
localDirs["dockerfile"] = filepath.Join(opts.Rootfs.Path, filepath.Dir(opts.Rootfs.Dockerfile))
attrs["filename"] = filepath.Base(opts.Rootfs.Dockerfile)
} else {
localDirs["context"] = filepath.Dir(opts.Rootfs.Path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👀 Wait why are we changing the context to be the dir here? That's a change from before.

IMO, the source field in the file should now ideally never contain a path to a Dockerfile. We could have a check somewhere that if the path passed is a file, then take the parent directory as the directory, and take the filename as the "filename".

Essentially source: app/foo.Dockerfile (with no dockerfile set) would set context + dockerfile to app/ and would set filename to foo.Dockerfile.

This is worth a little test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, I think it's doing just that no? Your comment is on the else case so where dockerfile is empty, but we're in the dockerfile rootfs build.

This means that source points to a Dockerfile and was set to into the path by the library.

This means that the context and the dockerfile fields are correctly extracted.

What is missing is the filename being set to filepath.Base(opts.Rootfs.Path). I will edit.

Now for the tests: basically all the existing tests that build dockerfiles fall in this branch so we have tests. I'll add one more that sets a different Dockerfile name to test that also.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Lemme know if fine now

Comment thread internal/builder/kraftfile_test.go Outdated
Previously, the name was cut from the path, so it used the default
'Dockerfile' name breaking functionality.

This is fixed in the `x/kraftfile` bump.

The dockerfile needs to be in a subfolder in the context.

Signed-off-by: Cezar Craciunoiu <cezar@unikraft.io>
@craciunoiuc craciunoiuc force-pushed the craciunoiuc/use-exact-dockerfile-name branch from 6cc644d to 428b2d5 Compare May 26, 2026 15:04
@craciunoiuc craciunoiuc requested a review from Copilot May 26, 2026 15:07
@craciunoiuc
Copy link
Copy Markdown
Member Author

Test node dead, needs rerunning

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Comment thread internal/builder/rootfs.go
Comment thread internal/builder/rootfs.go
Comment thread internal/builder/rootfs.go
Comment on lines 57 to +63
for _, rom := range kf.Roms {
romPath := filepath.Join(dir, rom.Source)
romPath := filepath.Join(dir, rom.Source.Path)
romFormat := cmp.Or(rom.Format, kraftfile.FsTypeErofs)
romOpt := FSOpts{
Path: romPath,
Format: romFormat,
Type: rom.Type,
Type: rom.Source.Type,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not needed, but will do

Comment on lines 78 to +85
if kf.Rootfs != nil {
opts.Rootfs.Path = filepath.Join(dir, kf.Rootfs.Source)
opts.Rootfs.Path = filepath.Join(dir, kf.Rootfs.Source.Path)
opts.Rootfs.Format = kf.Rootfs.Format
opts.Rootfs.Type = kf.Rootfs.Type
if opts.Rootfs.Type == "" {
opts.Rootfs.Type = kf.Rootfs.Source.Type
opts.Rootfs.Dockerfile = kf.Rootfs.Source.Dockerfile
if opts.Rootfs.Dockerfile != "" && opts.Rootfs.Type == "" {
opts.Rootfs.Type = kraftfile.SourceTypeDockerfile
} else if opts.Rootfs.Type == "" {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not needed, but will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants