Skip to content

Panic in containerConfigFromError when running "buildx debug build" #3822

@invidian

Description

@invidian

Contributing guidelines

I've found a bug and checked that ...

  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

containerConfigFromError panics with buildx debug instead of handling error gracefully.

Expected behaviour

Error should be handled gracefully as when running regular docker buildx build:

cat <<EOF > spec.yml
# syntax=ghcr.io/project-dalec/dalec/frontend:0.20

name: go-md2man
version: 2.0.3
revision: 1
packager: Dalec Example
vendor: Dalec Example
license: MIT
description: A tool to convert markdown into man pages (roff).
website: https://github.com/cpuguy83/go-md2man


sources:
  src:
    generate:
      - gomod: {}
    git:
      url: https://github.com/cpuguy83/go-md2man.git
      commit: v2.0.3
  patch:
    context: {}
    includes:
      - patch

patches:
  src:
    - source: patch
      path: patch

dependencies:
  build:
    golang:

build:
  env:
    CGO_ENABLED: "0"
  steps:
    - command: |
        cd src
        go build -o go-md2man .

artifacts:
  binaries:
    src/go-md2man:

image:
  entrypoint: go-md2man
  cmd: --help

tests:
  - name: Check bin
    files:
      /usr/bin/go-md2man:
        permissions: 0o755
EOF
BUILDX_EXPERIMENTAL=1 docker buildx build --target azlinux3/container --progress plain -f ./spec.yml .
#0 building with "default" instance using docker driver

#1 [internal] load build definition from spec.yml
#1 transferring dockerfile: 868B done
#1 DONE 0.1s

#2 resolve image config for docker-image://ghcr.io/project-dalec/dalec/frontend:0.20
#2 DONE 0.2s

#3 docker-image://ghcr.io/project-dalec/dalec/frontend:0.20@sha256:60be1bad349ae49aeea971c0e46edee0c9f7926e4d62066e4e981c45289f6e10
#3 resolve ghcr.io/project-dalec/dalec/frontend:0.20@sha256:60be1bad349ae49aeea971c0e46edee0c9f7926e4d62066e4e981c45289f6e10 0.0s done
#3 CACHED

#4 resolve image config for docker-image://mcr.microsoft.com/azurelinux/base/core:3.0
#4 DONE 0.1s

#4 resolve image config for docker-image://mcr.microsoft.com/azurelinux/base/core:3.0
#4 DONE 0.2s

#5 [internal] load .dockerignore
#5 transferring context: 2B done
#5 DONE 0.0s

#4 resolve image config for docker-image://mcr.microsoft.com/azurelinux/base/core:3.0
#4 DONE 0.3s

#6 Generate RPM spec
#6 DONE 0.4s

#7 Prepare worker image
#7 resolve mcr.microsoft.com/azurelinux/base/core:3.0 0.2s done
#7 sha256:5546a28a785aeec63c8bd58a7dafb93b463e13f23d4fd7582a86d73722a6fb33 31.72MB / 31.72MB 8.0s done
#7 extracting sha256:5546a28a785aeec63c8bd58a7dafb93b463e13f23d4fd7582a86d73722a6fb33 0.9s done
#7 DONE 1.1s

#8 Prepare worker image
#8 CACHED

#9 Install RPMs
#9 CACHED

#10 Installing dependencies for go-md2man
#10 CACHED

#11 Fetch go module dependencies for source: src
#11 CACHED

#12 Create RPM buildroot
#12 CACHED

#13 Create RPM buildroot
#13 CACHED

#14 Prepare source: patch
#14 transferring context: 2B done
#14 DONE 0.0s

#15 Prepare source: patch
#15 CACHED

#16 Generate RPM spec
#16 CACHED

#17 Installing dependencies for go-md2man
#17 CACHED

#18 Build RPM
#18 CACHED

#19 Prepare source: src
#19 CACHED

#20 Generate RPM spec
#20 CACHED

#21 Add gomod sources
#21 ERROR: failed to calculate checksum of ref 4febh84oguow935h4r0q6gvf6::u79xwq39vocldssdtjcmysk2v: "/patch/patch": not found

#22 Prepare source: src
#22 CANCELED

#23 Generate RPM spec
#23 CANCELED

#24 Prepare worker image
#24 CANCELED
------
 > Add gomod sources:
------
spec.yml:15
--------------------
  14 |       src:
  15 | >>>     generate:
  16 | >>>       - gomod: {}
  17 | >>>     git:
  18 |           url: https://github.com/cpuguy83/go-md2man.git
--------------------
spec.yml:21
--------------------
  19 |           commit: v2.0.3
  20 |       patch:
  21 | >>>     context: {}
  22 |         includes:
  23 |           - patch
--------------------
spec.yml:27
--------------------
  25 |     patches:
  26 |       src:
  27 | >>>     - source: patch
  28 |           path: patch
  29 |
--------------------
ERROR: failed to build: failed to solve: failed to compute cache key: failed to calculate checksum of ref 4febh84oguow935h4r0q6gvf6::u79xwq39vocldssdtjcmysk2v: "/patch/patch": not found

Actual behaviour

Panic occurred for me, which should likely be handled gracefully:

ERROR: failed to compute cache key: failed to calculate checksum of ref 4febh84oguow935h4r0q6gvf6::c7p1abvstt1gr9kevmifumu84: "/keda-2.18-patch/specs/kedacore/patches/2.18.0/foo.patch": not found
[+] Building 0.0s (0/0)                                                                                                                                                                                                                          docker:default
Launching interactive container. Press Ctrl-a-c to switch to monitor console
Interactive container was restarted with process "kjo1s0bpzajd5i67wglgzwz44". Press Ctrl-a-c to switch to the new container
panic: runtime error: index out of range [0] with length 0

goroutine 218 [running]:
github.com/docker/buildx/build.containerConfigFromError(0x324409e0870, 0x32440bb6090)
	github.com/docker/buildx/build/result.go:225 +0x305
github.com/docker/buildx/build.(*ResultHandle).getContainerConfig(0x32440968cc0, 0x32440bb6090)
	github.com/docker/buildx/build/result.go:126 +0x216
github.com/docker/buildx/build.(*ResultHandle).NewContainer(0x32440968cc0, {0x55d01d4bb668, 0x324409553b0}, 0x10?)
	github.com/docker/buildx/build/result.go:76 +0x5c
github.com/docker/buildx/build.NewContainer.func1.1({0x55d01d4bb5f8, 0x55d01d764fa0}, 0x32440968cc0, 0x32440bb6090, 0x324405f5260)
	github.com/docker/buildx/build/invoke.go:82 +0x15a
github.com/docker/buildx/build.NewContainer.func1()
	github.com/docker/buildx/build/invoke.go:104 +0x30
created by github.com/docker/buildx/build.NewContainer in goroutine 248
	github.com/docker/buildx/build/invoke.go:77 +0x10c

This looks like buildx debug bug, not dalec bug, since it does not occur when running regular buildx build, which properly errors out.

Buildx version

github.com/docker/buildx 0.33.0 f7897eb

Docker info


Builders list

$ docker buildx ls
NAME/NODE     DRIVER/ENDPOINT   STATUS    BUILDKIT   PLATFORMS
default*      docker
 \_ default    \_ default       running   v0.29.0    linux/amd64 (+3), linux/arm64, linux/arm (+2), linux/ppc64le, (6 more)

Configuration

cat <<EOF > spec.yml
# syntax=ghcr.io/project-dalec/dalec/frontend:0.20

name: go-md2man
version: 2.0.3
revision: 1
packager: Dalec Example
vendor: Dalec Example
license: MIT
description: A tool to convert markdown into man pages (roff).
website: https://github.com/cpuguy83/go-md2man


sources:
  src:
    generate:
      - gomod: {}
    git:
      url: https://github.com/cpuguy83/go-md2man.git
      commit: v2.0.3
  patch:
    context: {}
    includes:
      - patch

patches:
  src:
    - source: patch
      path: patch

dependencies:
  build:
    golang:

build:
  env:
    CGO_ENABLED: "0"
  steps:
    - command: |
        cd src
        go build -o go-md2man .

artifacts:
  binaries:
    src/go-md2man:

image:
  entrypoint: go-md2man
  cmd: --help

tests:
  - name: Check bin
    files:
      /usr/bin/go-md2man:
        permissions: 0o755
EOF
BUILDX_EXPERIMENTAL=1 docker buildx debug --on=error build --target azlinux3/container -f ./spec.yml .

Build logs


Additional info

I'll open a PR with proposed fix soon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions