Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ tidy: ## Tidy import Go modules.

.PHONY: fmt
fmt: ## Format all files according to linting preferences.
$(GOCILINT) format
$(GOCILINT) fmt

.PHONY: lint
lint: ## Lint all files according to linting preferences.
Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ require (
github.com/anchore/go-logger v0.0.0-20220728155337-03b66a5207d8 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/becheran/wildmatch-go v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down Expand Up @@ -203,13 +205,15 @@ require (
github.com/in-toto/attestation v1.1.2 // indirect
github.com/in-toto/in-toto-golang v0.10.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.18.5 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/lufia/plan9stats v0.0.0-20230110061619-bbe2e5e100de // indirect
github.com/magiconair/properties v1.8.10 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.21 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand Down Expand Up @@ -246,6 +250,7 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rootless-containers/rootlesskit/v2 v2.3.6 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
github.com/sasha-s/go-deadlock v0.3.5 // indirect
github.com/scylladb/go-set v1.0.3-0.20200225121959-cc7b2070d91e // indirect
Expand All @@ -270,6 +275,7 @@ require (
github.com/vishvananda/netns v0.0.5 // indirect
github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d // indirect
github.com/wagoodman/go-progress v0.0.0-20260303201901-10176f79b2c0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
Expand Down Expand Up @@ -306,8 +312,10 @@ require (
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
mvdan.cc/sh/v3 v3.12.0 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
unikraft.com/x/kraftfile v0.0.0-20260427093726-3fccc9bca88d // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o=
github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/becheran/wildmatch-go v1.0.0 h1:mE3dGGkTmpKtT4Z+88t8RStG40yN9T+kFEGj2PZFSzA=
github.com/becheran/wildmatch-go v1.0.0/go.mod h1:gbMvj0NtVdJ15Mg/mH9uxk2R1QCistMyU7d9KFzroX4=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand All @@ -150,6 +152,7 @@ github.com/briandowns/spinner v1.23.2 h1:Zc6ecUnI+YzLmJniCfDNaMbW0Wid1d5+qcTq4L2
github.com/briandowns/spinner v1.23.2/go.mod h1:LaZeM4wm2Ywy6vO571mvhQNRcWfRUnXOs0RcKV0wYKM=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
Expand Down Expand Up @@ -774,6 +777,8 @@ github.com/in-toto/in-toto-golang v0.10.0/go.mod h1:wjT4RiyFlLWCmLUJjwB8oZcjaq7H
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
github.com/j-keck/arping v1.0.2/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
Expand Down Expand Up @@ -840,6 +845,7 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
Expand Down Expand Up @@ -1093,6 +1099,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
github.com/sasha-s/go-deadlock v0.3.5 h1:tNCOEEDG6tBqrNDOX35j/7hL5FcFViG6awUGROb2NsU=
Expand Down Expand Up @@ -1257,6 +1265,8 @@ github.com/wagoodman/go-progress v0.0.0-20260303201901-10176f79b2c0 h1:EHsPe0Q0A
github.com/wagoodman/go-progress v0.0.0-20260303201901-10176f79b2c0/go.mod h1:g/D9uEUFp5YLyciwCpVsSOZOm56hfv4rzGJod6MlqIM=
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
Expand Down Expand Up @@ -1784,6 +1794,8 @@ k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 h1:SjGebBtkBqHFOli+05xYbK8YF1Dzkbzn+gDM4X9T4Ck=
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
mvdan.cc/sh/v3 v3.12.0 h1:ejKUR7ONP5bb+UGHGEG/k9V5+pRVIyD+LsZz7o8KHrI=
mvdan.cc/sh/v3 v3.12.0/go.mod h1:Se6Cj17eYSn+sNooLZiEUnNNmNxg0imoYlTu4CyaGyg=
oras.land/oras-go/v2 v2.6.0 h1:X4ELRsiGkrbeox69+9tzTu492FMUu7zJQW6eJU+I2oc=
oras.land/oras-go/v2 v2.6.0/go.mod h1:magiQDfG6H1O9APp+rOsvCPcW1GD2MM7vgnKY0Y+u1o=
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
Expand Down Expand Up @@ -1811,5 +1823,7 @@ sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
unikraft.com/cloud/sdk v0.0.0-20260409121557-1159639ea4e0 h1:ubn0DJHMIEStyubwa1Pi5r6kgQ8lSCtSPyU7kom2bEY=
unikraft.com/cloud/sdk v0.0.0-20260409121557-1159639ea4e0/go.mod h1:k4SxfgQFvFmUrBPVIMlU1eYPId9lCkO9/6J9o1sL08s=
unikraft.com/x/kraftfile v0.0.0-20260427093726-3fccc9bca88d h1:btmDzQqVgwN4lHyK4JjJkKxh5Nse9WaL5dUJ/Dl6NgQ=
unikraft.com/x/kraftfile v0.0.0-20260427093726-3fccc9bca88d/go.mod h1:OYaIMOzV1IpbZCe2J3SuC5jvT4tAfR0XG9uOPPD+p50=
xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight v0.0.0-20240729172045-026c9fa29716 h1:y52AcO4BZop/FrR523z47VCLFViGmMJqY21uL+FxXXI=
xenbits.xenproject.org/git-http/xen.git/tools/golang/xenlight v0.0.0-20240729172045-026c9fa29716/go.mod h1:tbZ4iMnk8RWkXPxTiCGdAw3hCOa3feShlf3sBh50uIc=
4 changes: 3 additions & 1 deletion initrd/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"kraftkit.sh/fs/cpio"
"kraftkit.sh/fs/erofs"
"kraftkit.sh/fsutils"

kraftfilev07 "unikraft.com/x/kraftfile"
)

type file struct {
Expand Down Expand Up @@ -96,7 +98,7 @@ reevaluateFsType:

// detectFsType attempts to convert from the 'unknown' filesystem type to one
// of the known types like 'cpio'/'erofs'/'file'.
func detectFsType(source string) FsType {
func detectFsType(source string) kraftfilev07.FsType {
switch {
case fsutils.IsErofsFile(source):
return FsTypeErofs
Expand Down
29 changes: 12 additions & 17 deletions initrd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package initrd
import (
"fmt"

kraftfilev07 "unikraft.com/x/kraftfile"

"kraftkit.sh/config"
)

Expand All @@ -24,7 +26,7 @@ type InitrdOptions struct {
buildSecrets map[string]InitrdBuildSecret
cacheDir string
compress bool
fsType FsType
fsType kraftfilev07.FsType
keepOwners bool
output string
rootfsPath string
Expand Down Expand Up @@ -126,7 +128,7 @@ func WithOutput(output string) InitrdOption {
}

// WithOutputType sets the output type of the resulting root filesystem.
func WithOutputType(fsType FsType) InitrdOption {
func WithOutputType(fsType kraftfilev07.FsType) InitrdOption {
return func(opts *InitrdOptions) error {
if fsType == "" {
return nil
Expand Down Expand Up @@ -194,25 +196,18 @@ func WithAuths(auths map[string]config.AuthConfig) InitrdOption {
}
}

type FsType string

// extended types on the top of kraftfilev07 defined FsTypes
const (
FsTypeCpio = FsType("cpio")
FsTypeErofs = FsType("erofs")
FsTypeFile = FsType("file")
FsTypeUnknown = FsType("unknown")
)
FsTypeFile = kraftfilev07.FsType("file")
FsTypeUnknown = kraftfilev07.FsType("unknown")

var _ fmt.Stringer = (*FsType)(nil)

// String implements fmt.Stringer
func (fsType FsType) String() string {
return string(fsType)
}
FsTypeCpio = kraftfilev07.FsTypeCpio
FsTypeErofs = kraftfilev07.FsTypeErofs
)
Comment thread
ijaidev marked this conversation as resolved.

// FsTypes returns the list of possible fsTypes.
func FsTypes() []FsType {
return []FsType{
func FsTypes() []kraftfilev07.FsType {
return []kraftfilev07.FsType{
FsTypeCpio,
FsTypeErofs,
FsTypeFile,
Expand Down
41 changes: 28 additions & 13 deletions initrd/rootfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"path/filepath"
"strings"

kraftfilev07 "unikraft.com/x/kraftfile"

"kraftkit.sh/config"
"kraftkit.sh/log"
"kraftkit.sh/tui/processtree"
Expand Down Expand Up @@ -82,39 +84,49 @@ func BuildRootfs(ctx context.Context, opts ...InitrdOption) (Initrd, []string, [
return ramfs, cmds, envs, nil
}

// BuildRoms generates ROM filesystems based on the provided ROM paths.
func BuildRoms(ctx context.Context, workdir string, roms []string, compress, keepOwners bool, arch string, fsType FsType) ([]string, error) {
if len(roms) == 0 || fsType == "" {
return roms, nil
// BuildRoms generates ROM filesystems based on the provided ROM FS (kraftfilev07.FS).
func BuildRoms(ctx context.Context, workdir string, roms []kraftfilev07.FS, compress, keepOwners bool, arch string, defaultFsType kraftfilev07.FsType) ([]kraftfilev07.FS, error) {
if len(roms) == 0 {
return nil, nil
}

var processes []*processtree.ProcessTreeItem
builtRoms := make([]string, len(roms))
builtRoms := make([]kraftfilev07.FS, len(roms))
for i, rom := range roms {
fsType := rom.Format
if fsType == "" {
fsType = defaultFsType
}

if fsType == "" {
builtRoms[i] = rom
continue
}

// Check if the ROM is a directory; if it's a file, skip building and use as-is
romPath := rom
if !filepath.IsAbs(rom) {
romPath = filepath.Join(workdir, rom)
romPath := rom.Source
if !filepath.IsAbs(rom.Source) {
romPath = filepath.Join(workdir, rom.Source)
}

info, err := os.Stat(romPath)
if err != nil {
return nil, fmt.Errorf("could not stat ROM path '%s': %w", rom, err)
return nil, fmt.Errorf("could not stat ROM path '%s': %w", rom.Source, err)
}

// If it's a regular file, don't try to build it as a filesystem
if !info.IsDir() && !strings.Contains(strings.ToLower(info.Name()), "dockerfile") {
// File ROMs must be aligned to page size
const pageSize = 4096
if info.Size()%pageSize != 0 {
return nil, fmt.Errorf("ROM file '%s' size (%d bytes) is not aligned to page size (%d bytes)", rom, info.Size(), pageSize)
return nil, fmt.Errorf("ROM file '%s' size (%d bytes) is not aligned to page size (%d bytes)", rom.Source, info.Size(), pageSize)
}
builtRoms[i] = rom
continue
}

ramfs, err := New(ctx,
rom,
rom.Source,
WithWorkdir(workdir),
WithOutput(filepath.Join(
workdir,
Expand All @@ -132,7 +144,7 @@ func BuildRoms(ctx context.Context, workdir string, roms []string, compress, kee
WithOutputType(fsType),
)
if err != nil {
return nil, fmt.Errorf("could not initialize ROM builder for '%s': %w", rom, err)
return nil, fmt.Errorf("could not initialize ROM builder for '%s': %w", rom.Source, err)
}

processes = append(processes,
Expand All @@ -145,7 +157,10 @@ func BuildRoms(ctx context.Context, workdir string, roms []string, compress, kee
return err
}

builtRoms[i] = builtRom
builtRoms[i] = kraftfilev07.FS{
Source: builtRom,
Format: fsType,
}
return nil
},
),
Expand Down
21 changes: 15 additions & 6 deletions internal/cli/kraft/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"kraftkit.sh/unikraft"
"kraftkit.sh/unikraft/app"
"kraftkit.sh/unikraft/target"

kraftfilev07 "unikraft.com/x/kraftfile"
)

var ErrContextNotBuildable = fmt.Errorf("could not determine what or how to build from the given context")
Expand Down Expand Up @@ -57,7 +59,7 @@ type BuildOptions struct {
PrintStats bool `long:"print-stats" usage:"Print build statistics"`
Project app.Application `noattribute:"true"`
Rootfs string `long:"rootfs" usage:"Specify a path to use as root file system (can be volume or initramfs)"`
RootfsType initrd.FsType `noattribute:"true"`
RootfsType kraftfilev07.FsType `noattribute:"true"`
KeepFileOwners bool `local:"true" long:"keep-file-owners" usage:"Keep file owners (user:group) in the rootfs (false sets 'root:root')"`
SaveBuildLog string `long:"build-log" usage:"Use the specified file to save the output from the build"`
Target *target.Target `noattribute:"true"`
Expand Down Expand Up @@ -128,8 +130,7 @@ func Build(ctx context.Context, opts *BuildOptions, args ...string) error {
initrd.WithWorkdir(opts.Workdir),
initrd.WithKeepOwners(opts.KeepFileOwners),
initrd.WithOutput(filepath.Join(
opts.Workdir,
unikraft.BuildDir,
buildOutputDir(opts.Project, opts.Workdir),
fmt.Sprintf(initrd.DefaultInitramfsArchFileName, (*opts.Target).Architecture(), opts.RootfsType),
)),
initrd.WithOutputType(opts.RootfsType),
Expand Down Expand Up @@ -205,7 +206,7 @@ func NewCmd() *cobra.Command {
}

cmd.Flags().Var(
cmdfactory.NewEnumFlag[initrd.FsType](
cmdfactory.NewEnumFlag[kraftfilev07.FsType](
initrd.FsTypes(),
initrd.FsTypeCpio,
),
Expand All @@ -225,7 +226,7 @@ func (opts *BuildOptions) Pre(cmd *cobra.Command, args []string) error {
cmd.SetContext(ctx)

if cmd.Flag("rootfs-type").Changed && cmd.Flag("rootfs-type").Value.String() != "" {
opts.RootfsType = initrd.FsType(cmd.Flag("rootfs-type").Value.String())
opts.RootfsType = kraftfilev07.FsType(cmd.Flag("rootfs-type").Value.String())
}

if opts.Rootfs != "" && !filepath.IsAbs(opts.Rootfs) && !strings.Contains(opts.Rootfs, "://") {
Expand Down Expand Up @@ -263,7 +264,7 @@ func (opts *BuildOptions) Run(ctx context.Context, args []string) error {
if ok {
standardName, err := target.KernelName(*tc)
if err == nil {
standardPath := filepath.Join(opts.Workdir, unikraft.BuildDir, standardName)
standardPath := filepath.Join(buildOutputDir(opts.Project, opts.Workdir), standardName)
desiredPath := t.Kernel()

// If they are different, it means either --kernel was used or 'output'
Expand Down Expand Up @@ -360,6 +361,14 @@ func (opts *BuildOptions) Run(ctx context.Context, args []string) error {
return nil
}

func buildOutputDir(project app.Application, workdir string) string {
if project != nil && project.OutDir() != "" {
return project.OutDir()
}

return filepath.Join(workdir, unikraft.BuildDir)
}

func moveFile(src, dst string) error {
// Ensure the destination directory exists.
if err := os.MkdirAll(filepath.Dir(dst), 0o755); err != nil {
Expand Down
Loading
Loading