fix(builder): Allow custom dockerfile names when building#322
fix(builder): Allow custom dockerfile names when building#322craciunoiuc wants to merge 1 commit into
Conversation
c271649 to
6b04c57
Compare
|
This shouldn't be merged as is, it should use the kraftfile |
|
correct |
6b04c57 to
689c4aa
Compare
6be6327 to
f0080e3
Compare
f0080e3 to
5aa4479
Compare
There was a problem hiding this comment.
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.Dockerfileand 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.
0f1f7c0 to
5bdc9d2
Compare
5bdc9d2 to
6cc644d
Compare
| 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) |
There was a problem hiding this comment.
👀 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Lemme know if fine now
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>
6cc644d to
428b2d5
Compare
|
Test node dead, needs rerunning |
| 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, |
There was a problem hiding this comment.
not needed, but will do
| 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 == "" { |
There was a problem hiding this comment.
not needed, but will do
Previously, the name was cut from the path, so it used the default 'Dockerfile' name breaking functionality.
Depends on: unikraft-cloud/x#253Merged
Closes: TOOL-855
TODOs left:* Bump the library after merging* Update the golden files for tests when they start behaving