Skip to content

[nerdctl build] Set default output type=image - #3604

Draft
TinaMor wants to merge 1 commit into
containerd:mainfrom
TinaMor:tinamor/fix-build-with-tty
Draft

TinaMor wants to merge 1 commit into
containerd:mainfrom
TinaMor:tinamor/fix-build-with-tty

Conversation

@TinaMor

@TinaMor TinaMor commented Oct 28, 2024 •

Copy link
Copy Markdown
Contributor

PR Description

Linked Issue: containerd/nerdctl#3629

This PR resolves #3629 for nerdctl build command when passed with:

  1. --progress auto, --progress tty, or --progress flag is not specified (which then defaults to --progress auto)
  2. --output flag is not specified

Example:

nerdctl build -t <TAG> --file .\Dockerfile .

Background

The issue occurs because the build progress output and the tarball are both sent to stdout on WIndows.

Solution

output = "type=docker"

When a user does not specify the --output flag, we default it to use type=image instead of type=docker because the image is actually uploaded to containerd image store. According to buildctl documentation, type=image is the native type for containerd.

Additional tasks

  • Only use the default image name when user has not specified one

Not included in this PR

  1. When default type=oci
    output = "type=oci"
  2. type=docker
    Currenly fails with archive/tar: invalid tar header moby/buildkit/issues/5528

References

  1. buildctl output: containerd image store

@TinaMor
TinaMor force-pushed the tinamor/fix-build-with-tty branch 4 times, most recently from 2d18366 to 01db27a Compare October 29, 2024 14:23
@TinaMor TinaMor changed the title Separate TTY and tar output in nerdctl build with tty Fix Windows tar parsing error by separating tty and tar outputs in buildctl Oct 29, 2024
@TinaMor TinaMor changed the title Fix Windows tar parsing error by separating tty and tar outputs in buildctl [Windows] Fix nerdctl build tar parsing error Oct 29, 2024
@TBBle

TBBle commented Nov 1, 2024 •

Copy link
Copy Markdown
Contributor

I need to work through this later, but I'm unclear how the current code works on non-Windows. How do those platforms distinguish a tar file from log output on stdout?

They shouldn't be passing through a termInal on the way, the terminal is where nerdctl's stdio is connected, so I don't understand what's different on Windows.

@apostasie

apostasie commented Nov 1, 2024 •

Copy link
Copy Markdown
Contributor

Hey @TBBle
I’ll have a look later today.
Curious too.

@AkihiroSuda AkihiroSuda added the area/ci e.g., CI failure label Nov 1, 2024
@TinaMor

TinaMor commented Nov 5, 2024

Copy link
Copy Markdown
Contributor Author

@TBBle, @apostasie

Still investigating the issue. This is a temp fix and the PR is WIP (may and may not be the final solution).
Currrently trying to understand the following:

  1. What is the performance impact of this fix if using a larger image eg mcr.microsoft.com/windows/servercore:ltsc2022 vs mcr.microsoft.com/windows/nanoserver:ltsc2022
  2. Is it the Windows terminal?
  3. Why are the build output and tarball all going to the same location on Windows alone?
  4. How does it work for progress=plain?

@apostasie

Copy link
Copy Markdown
Contributor

Deeply confused about this.

Why are the build output and tarball all going to the same location on Windows alone?

This does not make any sense.
I am squinting at nerdctl source and cannot figure it out.

Now suspecting buildctl might be the problem.

@apostasie

Copy link
Copy Markdown
Contributor

buildctl "output" goes to stderr.

Is it the case on windows?

foo="$(buildctl --addr=unix:///run/user/501/buildkit/buildkitd.sock build --progress=auto --frontend=dockerfile.v0 --local=context=/tmp/ --output=type=docker --local=dockerfile=/tmp --opt=filename=Dockerfile)"

or

buildctl --addr=unix:///run/user/501/buildkit/buildkitd.sock build --progress=auto --frontend=dockerfile.v0 --local=context=/tmp/ --output=type=docker --local=dockerfile=/tmp --opt=filename=Dockerfile >/dev/null

@TinaMor
TinaMor force-pushed the tinamor/fix-build-with-tty branch from 01db27a to 1e7bbf4 Compare November 6, 2024 15:24
@TinaMor TinaMor changed the title [Windows] Fix nerdctl build tar parsing error [nerdctl build] Set default output type=image Nov 6, 2024
@TinaMor
TinaMor force-pushed the tinamor/fix-build-with-tty branch from 1e7bbf4 to 80dc420 Compare November 13, 2024 13:54
Comment thread pkg/cmd/builder/build.go
output = "type=docker"
// https://github.com/moby/buildkit?tab=readme-ov-file#output
// type=image is the native type for containerd
output = "type=image"

@TinaMor TinaMor Nov 13, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Default to type=image instead of type=docker. See #3604 (comment)

cc @profnandaa

Comment thread pkg/cmd/builder/build.go
if r.N == 0 {
// Avoid confusing "unrecognized image format"
return errors.New("no image was built")
return fmt.Errorf("no image was built: %w", err)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Make the error more descriptive by adding the actual error

Comment thread pkg/cmd/builder/build.go Resolved
@TinaMor TinaMor closed this Nov 13, 2024
@TinaMor TinaMor reopened this Nov 13, 2024
@TinaMor
TinaMor force-pushed the tinamor/fix-build-with-tty branch 2 times, most recently from 14392ff to f4728b4 Compare November 13, 2024 16:16
@TBBle

TBBle commented Nov 14, 2024

Copy link
Copy Markdown
Contributor

When a user does not specify the --output flag, we default it to use type=image instead of type=docker because the image is actually uploaded to containerd image store. According to buildctl documentation, type=image is the native type for containerd.

Does this introduce a requirement that buildkit is configured to use the containerd worker? Or is that already a requirement for using nerdctl build for other reasons?

Expected: test.Expects(0, nil, test.Equals("nerdctl-build-test-string\n")),
},
{
Description: "Successfully build with output docker, name cannot be used",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@apostasie I've removed this test for now. I may be missing something. What is this testing?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missed this ^, sorry.

I believe this test does confirm that when you build with no output, you then cannot use the image.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do too find the description hard to grok.

@TinaMor

TinaMor commented Nov 19, 2024 •

Copy link
Copy Markdown
Contributor Author

Does this introduce a requirement that buildkit is configured to use the containerd worker? Or is that already a requirement for using nerdctl build for other reasons?

@TBBle In Windows, containerd-worker is the default. There is ongoing work to support oci-worker on Windows. On Linux environments, [oci-worker is the default].(https://github.com/moby/buildkit/blob/5cd5a63de5d37512c24f20085607509b749df762/README.md#linux-setup)

Additionally, with the shift from docker to containerd, we then should switch to using type=image instead of type=docker as the default, for both Windows and Linux.

References:

  1. What is the difference between oci workers and containerd workers?
  2. Docker vs. Containerd: Understanding the Shift in Kubernetes

@AkihiroSuda @jsturtevant What do you think?

@AkihiroSuda

Copy link
Copy Markdown
Member

The OCI worker still has to be supported

@TinaMor

TinaMor commented Mar 3, 2025

Copy link
Copy Markdown
Contributor Author

Using OCI-Worker on Linux (Ubuntu 22.04.5 LTS):

  • nerdctl build

    > sudo _output/nerdctl build -t test --file .Tina/Dockerfile --progress=tty .
    [+] Building 0.4s (6/6) FINISHED
    => [internal] load build definition from Dockerfile                                                                                                          0.0s
    => => transferring dockerfile: 73B                                                                                                                           0.0s
    => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                              0.3s
    => [internal] load .dockerignore                                                                                                                             0.0s
    => => transferring context: 114B                                                                                                                             0.0s
    => [1/2] FROM docker.io/library/ubuntu:latest@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782                                        0.0s
    => => resolve docker.io/library/ubuntu:latest@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782                                        0.0s
    => CACHED [2/2] RUN echo "hello"                                                                                                                             0.0s
    => exporting to image                                                                                                                                        0.0s
    => => exporting layers                                                                                                                                       0.0s
    => => exporting manifest sha256:7a8fd489fc272f99ab5d58aa442eaffb8de7b6b69f21f63e7c7c938212e18bb1                                                             0.0s
    => => exporting config sha256:affa9dd31348e6a1f65a5004dcff6f498d384672b68045219da73414a60d6128                                                               
  • Dockerfile

    FROM ubuntu:latest
    RUN echo "hello"
  • buildkitd.toml config:

    > cat /etc/buildkit/buildkitd.toml
    
    [worker.oci]
    enabled = true
    
    [worker.containerd]
    enabled = false
  • nerdctl info

    > sudo nerdctl info
    
    Client:
    Namespace:     default
    Debug Mode:    false
    
    Server:
    Server Version: 1.7.25
    Storage Driver: overlayfs
    Logging Driver: json-file
    Cgroup Driver: systemd
    Cgroup Version: 2
    Plugins:
    Log:     fluentd journald json-file none syslog
    Storage: native overlayfs
    Security Options:
    apparmor
    seccomp
    Profile: builtin
    cgroupns
    Kernel Version:   5.15.0-131-generic
    Operating System: Ubuntu 22.04.5 LTS
    OSType:           linux
    Architecture:     x86_64
    CPUs:             8
    Total Memory:     13.59GiB
    Name:             ubuntu2204
    ID:               XXXXXXXXXXXXXXXXXXXXX

    - Use default image name only when user has not specified one

Signed-off-by: Christine Murimi <[email protected]>
@TinaMor
TinaMor force-pushed the tinamor/fix-build-with-tty branch from 6811330 to dec2718 Compare March 3, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci e.g., CI failure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: no image was built

4 participants