Skip to content

Bake with remote docker-bake.hcl does not resolve custom target contexts #1738

@milas

Description

@milas

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

If you've got a target with a context defined, when baking the target remotely, the context does not have the Git context prepended.

Interestingly it actually is resolved correctly to find the Dockerfile (from the remote), so it'll actually fail on the first COPY.

Expected behaviour

  • COPY commands reference files from the context in the Git remote

Possibly output like this:

$ docker buildx bake 'https://example.com/myrepo.git' foo --print
{
  "target": {
    "foo": {
      "context": "https://example.com/myrepo.git:bar",
      "dockerfile": "Dockerfile"
    }
  }
}

Actual behaviour

  • COPY tries to copy from local path
$ docker buildx bake 'https://example.com/myrepo.git' foo --print
{
  "target": {
    "foo": {
      "context": "bar",
      "dockerfile": "Dockerfile"
    }
  }
}

Buildx version

github.com/docker/buildx 0.10.4 c513d34

Docker info

Client:
 Context:    pinkypie
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  0.10.4
    Path:     /usr/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.17.2
    Path:     /home/milas/.docker/cli-plugins/docker-compose

Server:
 Containers: 2
  Running: 0
  Paused: 0
  Stopped: 2
 Images: 24
 Server Version: 23.0.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: true
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1fbd70374134b891f97ce19c70b6e50c7b9f4e0d.m
 runc version: 
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.24-1-MANJARO
 Operating System: Manjaro Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 24
 Total Memory: 62.72GiB
 Name: pinkypie
 ID: LMGH:VDPN:Y2ZA:WRZA:ZQXA:U66B:KX3K:KY7C:SPFT:RX6Q:YV7M:DUN2
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: milas
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Builders list

NAME/NODE                   DRIVER/ENDPOINT                            STATUS   BUILDKIT    PLATFORMS
default                     docker
default                   default                                    running  23.0.3      linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386
pinkypie *                  docker
pinkypie                  pinkypie                                   running  23.0.3      linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386

Configuration

Here's a hypothetical example to make it easy to follow:

https://example.com/myrepo.git

myrepo/
├── docker-bake.hcl
└── bar/
    ├── Dockerfile
    └── super-cool.txt

docker-bake.hcl

target foo {
  context = "./bar"
}

./bar/Dockerfile

FROM scratch

COPY super-cool.txt /

Attempt to build... 💥

docker buildx bake \
  'https://example.com/myrepo.git' \
  foo

This will end up with an error such as

ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref moby::zhw5urpf8sto3shv0hjhbnpcj: "/super-cool.txt": not found

Build logs

No response

Additional info

Here's my real-world case that's a bit messier 🙃 :

docker buildx bake --print \
  'https://github.com/milas/rock5-toolchain.git#rknn' \
  yolov8-model-rknn

Notice that the context is rknn on the target!

This actually works if you override the context:

docker buildx bake --print \
  --set='*.context=https://github.com/milas/rock5-toolchain.git#rknn:rknn' \
  'https://github.com/milas/rock5-toolchain.git#rknn' \
  yolov8-model-rknn

(fyi that target takes a bit and has some big layers so wouldn't necessarily bother building it)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions