From 9d31623167b675245b9236b0534285724ee82464 Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Tue, 14 Jan 2025 10:51:36 +0200 Subject: [PATCH 1/5] fix(initrd): Remove prepended arguments from dockerfile cmd By default Docker prepends '/bin/sh -c' to the entrypoint if specified, which would make it break. Signed-off-by: Cezar Craciunoiu --- initrd/dockerfile.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/initrd/dockerfile.go b/initrd/dockerfile.go index 489749ebf..0cae522c5 100644 --- a/initrd/dockerfile.go +++ b/initrd/dockerfile.go @@ -504,6 +504,13 @@ func (initrd *dockerfile) Build(ctx context.Context) (string, error) { ) initrd.env = img.Metadata.Config.Config.Env + // Remove the shell command if it is the first argument + // TODO(craciunoiuc): Remove this once shell scripts are supported[1] + // [1]: https://github.com/unikraft/unikraft/pull/1386 + if len(initrd.args) >= 2 && initrd.args[0] == "/bin/sh" && initrd.args[1] == "-c" { + initrd.args = initrd.args[2:] + } + if err := tempgen.Cleanup(); err != nil { return "", fmt.Errorf("could not cleanup temp dir generator: %w", err) } From 76cac9b4582c99055fb8bb5e59fbf0339d25bd91 Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Tue, 14 Jan 2025 10:53:13 +0200 Subject: [PATCH 2/5] fix(internal|github-action): Ensure dockerfile args have more priority Because the runtime is the target, the fallback command would overwrite the command provided in Docker, defeating its purpose. Signed-off-by: Cezar Craciunoiu --- internal/cli/kraft/pkg/packager_kraftfile_runtime.go | 4 ++-- tools/github-action/pack.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/cli/kraft/pkg/packager_kraftfile_runtime.go b/internal/cli/kraft/pkg/packager_kraftfile_runtime.go index a070847c9..24b80e2cd 100644 --- a/internal/cli/kraft/pkg/packager_kraftfile_runtime.go +++ b/internal/cli/kraft/pkg/packager_kraftfile_runtime.go @@ -335,10 +335,10 @@ func (p *packagerKraftfileRuntime) Pack(ctx context.Context, opts *PkgOptions, a if len(opts.Args) == 0 { if len(opts.Project.Command()) > 0 { opts.Args = opts.Project.Command() - } else if len(targ.Command()) > 0 { - opts.Args = targ.Command() } else if cmds != nil { opts.Args = cmds + } else if len(targ.Command()) > 0 { + opts.Args = targ.Command() } } diff --git a/tools/github-action/pack.go b/tools/github-action/pack.go index 1303778ff..8fcc32e79 100644 --- a/tools/github-action/pack.go +++ b/tools/github-action/pack.go @@ -459,10 +459,10 @@ func (opts *GithubAction) packRuntime(ctx context.Context, output string, format if len(opts.Args) == 0 { if len(opts.project.Command()) > 0 { opts.Args = opts.project.Command() - } else if len(targ.Command()) > 0 { - opts.Args = targ.Command() } else if cmds != nil { opts.Args = cmds + } else if len(targ.Command()) > 0 { + opts.Args = targ.Command() } } From 662588eea5fa3a8841b0dee6881fb81341badd42 Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Tue, 14 Jan 2025 10:55:40 +0200 Subject: [PATCH 3/5] fix(cloud): Correct example on how to provide arguments Signed-off-by: Cezar Craciunoiu --- internal/cli/kraft/cloud/deploy/deploy.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/cli/kraft/cloud/deploy/deploy.go b/internal/cli/kraft/cloud/deploy/deploy.go index cdf921487..16c8ea6ce 100644 --- a/internal/cli/kraft/cloud/deploy/deploy.go +++ b/internal/cli/kraft/cloud/deploy/deploy.go @@ -106,9 +106,12 @@ func NewCmd() *cobra.Command { # Supply arguments to the instance of the existing image $ kraft cloud --metro fra0 deploy -p 443:8080 caddy:latest -- /bin/server --debug - # Supply arguments to the instance of the project (overriding the cmd): + # Supply arguments to the instance of the project (appending to the cmd): $ kraft cloud --metro fra0 deploy -p 443:8080 . -- /bin/server --debug + # Supply arguments to the instance of the project (overwriting the cmd): + $ kraft cloud --metro fra0 deploy -p 443:8080 --entrypoint "/bin/server --debug" . + # Immediately start following the log tail $ kraft cloud --metro fra0 deploy -p 443:8080 -f caddy:latest `), From d724ded0ec92f79bb7f23f5eb7222976056a03d8 Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Tue, 14 Jan 2025 11:36:40 +0200 Subject: [PATCH 4/5] fix(github-action): Change args type to string GitHub actions don't support arrays as argument so the type conversion turned it into an empty array. Signed-off-by: Cezar Craciunoiu --- tools/github-action/execute.go | 9 +++++++-- tools/github-action/main.go | 20 ++++++++++--------- tools/github-action/pack.go | 35 ++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/tools/github-action/execute.go b/tools/github-action/execute.go index 36e7bc982..15137a741 100644 --- a/tools/github-action/execute.go +++ b/tools/github-action/execute.go @@ -12,6 +12,7 @@ import ( "os" "time" + "github.com/mattn/go-shellwords" "github.com/rancher/wrangler/pkg/signals" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -61,11 +62,15 @@ func (opts *GithubAction) execute(ctx context.Context) error { targetName = opts.target.Platform().Name() + "/" + opts.target.Architecture().Name() } + args, err := shellwords.Parse(opts.Args) + if err != nil { + return err + } + machine.Spec.Kernel = "project://" + opts.project.Name() + ":" + targetName machine.Spec.Architecture = opts.target.Architecture().Name() machine.Spec.Platform = opts.target.Platform().Name() - machine.Spec.ApplicationArgs = opts.Args - + machine.Spec.ApplicationArgs = args machine.Status.KernelPath = opts.target.Kernel() if _, err := os.Stat(machine.Status.KernelPath); err != nil && os.IsNotExist(err) { diff --git a/tools/github-action/main.go b/tools/github-action/main.go index c22011a22..82d96ca9d 100644 --- a/tools/github-action/main.go +++ b/tools/github-action/main.go @@ -52,14 +52,14 @@ type GithubAction struct { Timeout uint64 `long:"timeout" env:"INPUT_TIMEOUT" usage:"Timeout for the unikernel"` // Packaging flags - Args []string `long:"args" env:"INPUT_ARGS" usage:"Arguments to pass to the unikernel"` - Rootfs string `long:"rootfs" env:"INPUT_ROOTFS" usage:"Include a rootfs at path"` - Memory string `long:"memory" env:"INPUT_MEMORY" usage:"Set the memory size"` - Name string `long:"name" env:"INPUT_NAME" usage:"Set the name of the output"` - Output string `long:"output" env:"INPUT_OUTPUT" usage:"Set the output path"` - Push bool `long:"push" env:"INPUT_PUSH" usage:"Push the output"` - Strategy string `long:"strategy" env:"INPUT_STRATEGY" usage:"Merge strategy to use when packaging"` - Dbg bool `long:"dbg" env:"INPUT_DBG" usage:"Use the debug kernel"` + Args string `long:"args" env:"INPUT_ARGS" usage:"Arguments to pass to the unikernel"` + Rootfs string `long:"rootfs" env:"INPUT_ROOTFS" usage:"Include a rootfs at path"` + Memory string `long:"memory" env:"INPUT_MEMORY" usage:"Set the memory size"` + Name string `long:"name" env:"INPUT_NAME" usage:"Set the name of the output"` + Output string `long:"output" env:"INPUT_OUTPUT" usage:"Set the output path"` + Push bool `long:"push" env:"INPUT_PUSH" usage:"Push the output"` + Strategy string `long:"strategy" env:"INPUT_STRATEGY" usage:"Merge strategy to use when packaging"` + Dbg bool `long:"dbg" env:"INPUT_DBG" usage:"Use the debug kernel"` // Internal attributes project app.Application @@ -255,7 +255,7 @@ func (opts *GithubAction) Run(ctx context.Context, args []string) (err error) { opts.Target, ) - if len(targets) != 1 { + if len(targets) > 1 { // TODO(nderjung): We should support building multiple targets in the // future, but for now we disable this ability. This is largely to do with // package management afterwards which does not yet support multi-target @@ -264,6 +264,8 @@ func (opts *GithubAction) Run(ctx context.Context, args []string) (err error) { // unikernel after a successful build via this action, multiple targets // would also fail at this step. return fmt.Errorf("cannot build more than one target using action") + } else if len(targets) == 0 { + return fmt.Errorf("no targets found") } opts.target = targets[0] diff --git a/tools/github-action/pack.go b/tools/github-action/pack.go index 8fcc32e79..ec1bd1d7e 100644 --- a/tools/github-action/pack.go +++ b/tools/github-action/pack.go @@ -193,19 +193,23 @@ func (opts *GithubAction) packUnikraft(ctx context.Context, output string, forma } } + var cmdShellArgs []string + // If no arguments have been specified, use the ones which are default and // that have been included in the package. if len(opts.Args) == 0 { if len(opts.project.Command()) > 0 { - opts.Args = opts.project.Command() + cmdShellArgs = opts.project.Command() } else if len(opts.target.Command()) > 0 { - opts.Args = opts.target.Command() + cmdShellArgs = opts.target.Command() } - } - cmdShellArgs, err := shellwords.Parse(strings.Join(opts.Args, " ")) - if err != nil { - return err + cmdShellArgs, err = shellwords.Parse(strings.Join(cmdShellArgs, " ")) + if err != nil { + return err + } + } else { + cmdShellArgs = strings.Split(opts.Args, " ") } popts := []packmanager.PackOption{ @@ -454,27 +458,29 @@ func (opts *GithubAction) packRuntime(ctx context.Context, output string, format return fmt.Errorf("could not build rootfs: %w", err) } + args := []string{} + // If no arguments have been specified, use the ones which are default and // that have been included in the package. if len(opts.Args) == 0 { if len(opts.project.Command()) > 0 { - opts.Args = opts.project.Command() + args = opts.project.Command() } else if cmds != nil { - opts.Args = cmds + args = cmds } else if len(targ.Command()) > 0 { - opts.Args = targ.Command() + args = targ.Command() } - } - args := []string{} - // Only parse arguments if they have been provided. - if len(opts.Args) > 0 { - args, err = shellwords.Parse(fmt.Sprintf("'%s'", strings.Join(opts.Args, "' '"))) + args, err = shellwords.Parse(fmt.Sprintf("'%s'", strings.Join(args, "' '"))) if err != nil { return err } + } else { + args = strings.Split(opts.Args, " ") } + fmt.Println("Packaging args:", args) + labels := opts.project.Labels() var popts []packmanager.PackOption @@ -507,6 +513,7 @@ func (opts *GithubAction) packRuntime(ctx context.Context, output string, format } if opts.Push { + fmt.Println("Pushing") return packaged[0].Push(ctx) } From 5bec354f7a567b081d46d0deb80d5306758a956c Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Tue, 14 Jan 2025 11:38:51 +0200 Subject: [PATCH 5/5] fix(action): Move memory argument Memory is only used as part of the execution step. Signed-off-by: Cezar Craciunoiu --- action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 44024b064..765e30ab4 100644 --- a/action.yml +++ b/action.yml @@ -78,6 +78,9 @@ inputs: description: If to run the unikernel. required: false default: "false" + memory: + description: Set the memory size. String of format "1M"/"1G"/"1K" + required: false timeout: description: Timeout for the unikernel. required: false @@ -88,9 +91,6 @@ inputs: args: description: Arguments to pass to the unikernel. required: false - memory: - description: Set the memory size. String of format "1M"/"1G"/"1K" - required: false name: description: Set the name of the output. required: true