Skip to content
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

Kraftfile cmd not added as kernel argument #1614

Open
LucaSeri opened this issue Apr 28, 2024 · 5 comments · May be fixed by #1694
Open

Kraftfile cmd not added as kernel argument #1614

LucaSeri opened this issue Apr 28, 2024 · 5 comments · May be fixed by #1694
Assignees
Labels
kind/bug Something isn't working priority/medium Issue which is important, but KraftKit is usable without it also.

Comments

@LucaSeri
Copy link
Contributor

LucaSeri commented Apr 28, 2024

Describe the bug

When providing a cmd in the kraftfile, for an application running through the elfloader, the following error is generated:
[ 0.117956] ERR: [appelfloader] Program name missing (no argv[1]).

This is caused because the cmd is no longer passed as a kernel argument.

Steps to reproduce

spec: v0.6

runtime: base:latest

rootfs: ./Dockerfile

cmd: ["/server"]
$ kraft run

Expected behavior

The cmd should be added.

Which architectures were you using or does this bug affect?

No response

Which operating system were you using or does this bug affect?

No response

Relevant log output

qemu-system-x86_64 -append vfs.fstab=[ "initrd0:/:extract:::" ] env.vars=[ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] --  -cpu host,+x2apic,-pmu -daemonize -device virtio-net-pci,mac=02:b0:b0:21:8f:01,netdev=hostnet0 -device pvpanic -device sga -display none -enable-kvm -initrd .unikraft/build/initramfs-x86_64.cpio -kernel /tmp/kraft-run-4262159733/unikraft/bin/kernel -machine pc,accel=kvm -m size=64M -monitor unix:/home/kero/.local/share/kraftkit/runtime/c3aa2335-0a11-4bd1-ad81-17aecfdb20a0/qemu_mon.sock,server,nowait -name c3aa2335-0a11-4bd1-ad81-17aecfdb20a0 -netdev user,id=hostnet0,hostfwd=tcp::8080-:8080 -nographic -no-reboot -S -parallel none -pidfile /home/kero/.local/share/kraftkit/runtime/c3aa2335-0a11-4bd1-ad81-17aecfdb20a0/machine.pid -qmp unix:/home/kero/.local/share/kraftkit/runtime/c3aa2335-0a11-4bd1-ad81-17aecfdb20a0/qemu_control.sock,server,nowait -qmp unix:/home/kero/.local/share/kraftkit/runtime/c3aa2335-0a11-4bd1-ad81-17aecfdb20a0/qemu_events.sock,server,nowait -rtc base=utc -serial file:/home/kero/.local/share/kraftkit/runtime/c3aa2335-0a11-4bd1-ad81-17aecfdb20a0/machine.log -smp cpus=1,threads=1,sockets=1 -vga none
@LucaSeri LucaSeri added the kind/bug Something isn't working label Apr 28, 2024
@LucaSeri LucaSeri changed the title Kraftfile cmd not added as kernel argumen t Kraftfile cmd not added as kernel argument Apr 28, 2024
@LucaSeri
Copy link
Contributor Author

LucaSeri commented Apr 28, 2024

On further inspection, this seems to be overwritten when building the rootfs, here: https://github.com/unikraft/kraftkit/blob/staging/internal/cli/kraft/run/utils.go#L410
I am not sure what the interaction should be between:

  • Dockerfile's CMD
  • Kraftfile's cmd

In my case, I have a Dockerfile with no CMD:

FROM golang:1.21.3-bookworm AS build

WORKDIR /src

COPY ./server.go /src/server.go

RUN set -xe; \
    CGO_ENABLED=1 \
    go build \
      -buildmode=pie \
      -ldflags "-linkmode external -extldflags '-static-pie'" \
      -tags netgo \
      -o /server server.go \
    ;

FROM scratch

COPY --from=build /server /server
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/

@nderjung
Copy link
Member

Hi @LucaSeri, this is a recent addition, towards having better compatibility with Dockerfiles. The priority of arguments should be:

CLI > Kraftfile > Dockerfile

  1. If the user has supplied -a|--args flag, this takes the highest priority and everything else is ignored.
  2. If the user has not supplied the -a|--args flag, and the Kraftfile has a cmd entry, use this.
  3. If neither the -a|--args flag is supplied nor the Kraftfile has a cmd element, try to use the Dockerfile's CMD.

@LucaSeri
Copy link
Contributor Author

Thanks @nderjung. That all makes sense. Maybe this should be revisited since it seems the -a flag cannot directly replace the cmd field. The parser gives the following error:
expected param to be in the format 'libname.param=value' but got: '/server'

@Krechals
Copy link
Contributor

Krechals commented May 2, 2024

I've also looked a bit into this, because I had the same issues when running many applications from the catalog with kraft, including helloworld-c.

Looking at the codebase, it seems that the -a|--args flag is used for setting kernel arguments, while the cmd element in both Kraftfile and Dockerfile is used for application arguments.

I got a fix in #1622, but I'm not aware how to provide application arguments directly from the CLI (using kraft run).

@craciunoiuc craciunoiuc linked a pull request Jun 4, 2024 that will close this issue
4 tasks
@craciunoiuc craciunoiuc added the priority/medium Issue which is important, but KraftKit is usable without it also. label Aug 26, 2024
@craciunoiuc
Copy link
Member

does this still happen? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working priority/medium Issue which is important, but KraftKit is usable without it also.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants