Skip to content

Comments

c8d: Use the roundtripper during build#49178

Merged
thaJeztah merged 1 commit intomoby:masterfrom
rumpl:c8d-fix-tar-build
Jan 3, 2025
Merged

c8d: Use the roundtripper during build#49178
thaJeztah merged 1 commit intomoby:masterfrom
rumpl:c8d-fix-tar-build

Conversation

@rumpl
Copy link
Member

@rumpl rumpl commented Dec 30, 2024

- What I did
Added the roundtripper to the containerd worker source manager.

The roundtripper is responsible for giving back the build context when it comes from a tar directly. So we add it to the source manager of the containerd worker.

fixes #47717

- How I did it

- How to verify it

With the sample reproducer from #47717

You can also try this terraform:

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 3.0.2"
    }
  }
}

provider "docker" {
  host = "unix:///tmp/docker.sock"
}

resource "docker_image" "my-image" {
  name = "my-image:latest"

  build {
    context = "${path.cwd}"
  }
}

Output of the apply:

terraform apply
docker_image.my-image: Refreshing state... [id=sha256:09fe4d17ab2ba82f9e3edb4355216f312a36d58ecf2510271bb225faee0b6329my-image:latest]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # docker_image.my-image will be created
  + resource "docker_image" "my-image" {
      + id          = (known after apply)
      + image_id    = (known after apply)
      + name        = "my-image:latest"
      + repo_digest = (known after apply)

      + build {
          + cache_from     = []
          + context        = "/home/rumpl/tftest"
          + dockerfile     = "Dockerfile"
          + extra_hosts    = []
          + remove         = true
          + security_opt   = []
          + tag            = []
            # (11 unchanged attributes hidden)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

docker_image.my-image: Creating...
docker_image.my-image: Creation complete after 3s [id=sha256:76c0301c79d56873b8aebf2442bd93e78f53fb9b95700448497ef68b20136fdcmy-image:latest]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.docker -c local images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
my-image     latest    76c0301c79d5   11 seconds ago   6.57MB

- Description for the changelog

containerd image store: Fix passing a build context via tarball to the `/build` endpoint.

- A picture of a cute animal (not mandatory but encouraged)

The roundtripper is responsible for giving back the build context when
it comes from a tar directly. So we add it to the source manager of the
containerd worker.

Signed-off-by: Djordje Lukic <[email protected]>
CacheAccessor: bw.CacheManager(),
Transport: rt,
})
if err == nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I'm not returning an error here the same way the graph driver worker doesn't return an error

  • hs, err := http.NewSource(http.Opt{
    CacheAccessor: cm,
    Transport: opt.Transport,
    })
    if err == nil {
    sm.Register(hs)
    } else {
    log.G(context.TODO()).Warnf("Could not register builder http source: %s", err)
    }

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps that's worth a comment in the code for future reference?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like that "don't fail / don't return error" was added in ca3e3fc

I guess it somewhat makes sense to not prevent the daemon from starting, but haven't tried what it looks like when trying to build something that needs git and/or if BuildKit has some entitlement to indicate whether a builder can support git (or not).

Copy link
Member

Choose a reason for hiding this comment

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

So, it looks like that fix was intended for git, but now wondering if it was much too broad in scope as it also did the same for other type of sources which (I THINK) don't depend on any external dependency to be installed? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for digging in! Ok yeah that fix added the warning for the http source for some reason too... I can change c8d and GD cases and return an error for the http source

Copy link
Member

Choose a reason for hiding this comment

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

I'd be fine with keeping them the same for now, then (in a follow-up) fix it for both. Or at least; I haven't looked yet if there's possible reasons for this to fail (and if we're considering including this in 27.x, perhaps it's safer to "fail soft" for now, and to look more in depth if we can safely fail loud 😅

Curious though; should those other sources also be registered? (git.NewSource, local.NewSource) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The "funny" part is that http.NewSource never returns an error :D

Copy link
Member Author

Choose a reason for hiding this comment

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

Curious though; should those other sources also be registered? (git.NewSource, local.NewSource) ?

All of these are already added by the call to base.NewWorker a couple lines above. We only need to change the http one for the roundtripper to do its thing

Copy link
Member

Choose a reason for hiding this comment

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

The "funny" part is that http.NewSource never returns an error :D

LOL, yeah, in that case; hard failure would be good for sure! And possibly we should change that signature to not even pretend there may be an error.

All of these are already added by the call to base.NewWorker a couple lines above. We only need to change the http one for the roundtripper to do its thing

Ah, thanks!

@thaJeztah
Copy link
Member

Trying this with the reproducer script from #47717

Against docker 27.5.0-rc.1:

docker run -it --rm -v ./testbuilder/:/testbuilder -w /testbuilder -v /var/run/docker.sock:/var/run/docker.sock ubuntu

ls -l
total 9412
-rw-r--r-- 1 root root     431 Dec 31 10:19 context.tar
-rwxr-xr-x 1 root root 9629289 Dec 31 10:22 testbuilder
-rw-r--r-- 1 root root     686 Dec 31 10:21 testbuilder.go

DOCKER_API_VERSION=1.46 ./testbuilder
{"id":"moby.buildkit.trace","aux":"Cm8KR3NoYTI1NjpiNWE1NTg3ZDcxODg3ZDRlZjM3NGFhODIzMDNkYzEzODZlOTQzMDIwYmNmZWE1NWQ5OWNkYTRjMzI2MzViMTU3GiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQ="}
{"id":"moby.buildkit.trace","aux":"Cn0KR3NoYTI1NjpiNWE1NTg3ZDcxODg3ZDRlZjM3NGFhODIzMDNkYzEzODZlOTQzMDIwYmNmZWE1NWQ5OWNkYTRjMzI2MzViMTU3GiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQqDAiXlc+7BhCFnb+NAw=="}
{"id":"moby.buildkit.trace","aux":"CqcBCkdzaGEyNTY6YjVhNTU4N2Q3MTg4N2Q0ZWYzNzRhYTgyMzAzZGMxMzg2ZTk0MzAyMGJjZmVhNTVkOTljZGE0YzMyNjM1YjE1NxokW2ludGVybmFsXSBsb2FkIHJlbW90ZSBidWlsZCBjb250ZXh0KgwIl5XPuwYQhZ2/jQMyCwiYlc+7BhCumo4OOhtpbnZhbGlkIHJlc3BvbnNlIHN0YXR1cyA0MDM="}
{"errorDetail":{"message":"failed to read downloaded context: failed to load cache key: invalid response status 403"},"error":"failed to read downloaded context: failed to load cache key: invalid response status 403"}

Against a daemon built with this PR (running inside the dev-container), we're getting slightly further, but it's failing to pull the image, which may very well be the test-code here;

cd testbuilder
DOCKER_API_VERSION=1.46 ./testbuilder
{"id":"moby.buildkit.trace","aux":"Cm8KR3NoYTI1Njo0MjRmZmJmYTBiOTRhNjllYWYwYTdjNDA0MDBhYjZjMmQ2MjA0ODA3OTQ4NTcxYjBhY2UxMWI4NTIxYzE5YmNlGiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQ="}
{"id":"moby.buildkit.trace","aux":"CnwKR3NoYTI1Njo0MjRmZmJmYTBiOTRhNjllYWYwYTdjNDA0MDBhYjZjMmQ2MjA0ODA3OTQ4NTcxYjBhY2UxMWI4NTIxYzE5YmNlGiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQqCwiEl8+7BhDftMRa"}
{"id":"moby.buildkit.trace","aux":"CokBCkdzaGEyNTY6NDI0ZmZiZmEwYjk0YTY5ZWFmMGE3YzQwNDAwYWI2YzJkNjIwNDgwNzk0ODU3MWIwYWNlMTFiODUyMWMxOWJjZRokW2ludGVybmFsXSBsb2FkIHJlbW90ZSBidWlsZCBjb250ZXh0KgsIhJfPuwYQ37TEWjILCISXz7sGEKiH0mE="}
{"id":"moby.buildkit.trace","aux":"CokBCkdzaGEyNTY6NDI0ZmZiZmEwYjk0YTY5ZWFmMGE3YzQwNDAwYWI2YzJkNjIwNDgwNzk0ODU3MWIwYWNlMTFiODUyMWMxOWJjZRokW2ludG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XIuaW8vbGlicmFyeS9hbHBpbmU6bGF0ZXN0KgsIhJfPuwYQlpaPag=="}
{"id":"moby.buildkit.trace","aux":"CrYBCkdzaGEyNTY6NzBiNzQxNDZlMzE1ZWY2ODlmZjIxMzZlOWY4MjFiZmM1NTdiYzJiN2RkZmM3Njg1NTgwZjRhMGVlMWU3YTk3MBo8W2ludGVybmFsXSBsb2FkIG1ldGFkYXRhIGZvciBkb2NrZXIuaW8vbGlicmFyeS9hbHBpbmU6bGF0ZXN0KgsIhJfPuwYQlpaPajIMCISXz7sGEOK4hocDOhJubyBhY3RpdmUgc2Vzc2lvbnM="}
{"errorDetail":{"message":"alpine: failed to resolve source metadata for docker.io/library/alpine:latest: no active sessions"},"error":"alpine: failed to resolve source metadata for docker.io/library/alpine:latest: no active sessions"}

Daemon logs (ignore the "handling POST request" appearing as last log, that's an issue still to fix in master)

INFO[2024-12-31T10:48:25.220117167Z] API listen on /var/run/docker.sock
DEBU[2024-12-31T10:48:39.270768382Z] resolve exporter moby with map[name:docker.io/library/myimage:latest]
DEBU[2024-12-31T10:48:39.275765840Z] prepare snapshot                              key=op7hiqfufswzqcj1f4n8gvdev parent= snapshotter=overlayfs
DEBU[2024-12-31T10:48:39.280346007Z] get snapshot mounts                           key=op7hiqfufswzqcj1f4n8gvdev snapshotter=overlayfs
DEBU[2024-12-31T10:48:39.284275590Z] load cache for [internal] load remote build context with p75gv258gxyzquedv4uhxiix7::adhrf4f0ko2xqodnjp0ad3x8r
DEBU[2024-12-31T10:48:39.284910298Z] get snapshot mounts                           key=pk67roo9vyiuyd8yxug9kulfk snapshotter=overlayfs
DEBU[2024-12-31T10:48:39.286001757Z] load cache for copy /context / with p75gv258gxyzquedv4uhxiix7::scq16otlqd70cokjj35j8a45c
DEBU[2024-12-31T10:48:39.286287215Z] get snapshot mounts                           key=ppjh54gdud8o89ll091wluqmg snapshotter=overlayfs
DEBU[2024-12-31T10:48:39.287407465Z] checked for cached auth handler namespace     cached=false key="docker.io/library/alpine::pull" name=docker.io/library/alpine scope=pull
DEBU[2024-12-31T10:48:39.288671673Z] resolving                                     span="resolving docker.io/library/alpine:latest"
DEBU[2024-12-31T10:48:39.288696048Z] do request                                    request.header.accept="application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json, */*" request.header.user-agent=buildkit/v0.18 request.method=HEAD span="resolving docker.io/library/alpine:latest"
DEBU[2024-12-31T10:48:39.795193090Z] fetch response received                       response.header.content-length=157 response.header.content-type=application/json response.header.date="Tue, 31 Dec 2024 10:48:39 GMT" response.header.docker-distribution-api-version=registry/2.0 response.header.docker-ratelimit-source=94.210.180.92 response.header.strict-transport-security="max-age=31536000" response.header.www-authenticate="Bearer realm=\"https://auth.docker.io/token\",service=\"registry.docker.io\",scope=\"repository:library/alpine:pull\"" response.status="401 Unauthorized" span="resolving docker.io/library/alpine:latest"
DEBU[2024-12-31T10:48:39.795336590Z] Unauthorized                                  header="Bearer realm=\"https://auth.docker.io/token\",service=\"registry.docker.io\",scope=\"repository:library/alpine:pull\"" span="resolving docker.io/library/alpine:latest"
INFO[2024-12-31T10:48:39.795443257Z] trying next host                              error="no active sessions" span="resolving docker.io/library/alpine:latest"
DEBU[2024-12-31T10:48:39.800409549Z] (*service).Write started                      ref=history-ref_797526965-sCR_
DEBU[2024-12-31T10:48:39.810167924Z] (*service).Write started                      ref=history-ref_809416007-sDJg
WARN[2024-12-31T10:48:39.820853174Z] no trace recorder found, skipping             span="create history record"
DEBU[2024-12-31T10:48:39.822420049Z] handling POST request                         method=POST module=api request-url="/v1.46/build?rm=0&t=myimage%3Alatest&version=2" status=200 vars="map[version:1.46]"

If I pull the image first, it works;

docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
cb8611c9fe51: Pull complete
Digest: sha256:21dc6063fd678b478f57c0e13f47560d0ea4eeba26dfc947b2a4f81f686b9f45
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

DOCKER_API_VERSION=1.46 ./testbuilder
{"id":"moby.buildkit.trace","aux":"Cm8KR3NoYTI1Njo4ZDk4NzMwYjZkNzNmNDExNzVmNDMwYzA0NDNkNDY1ODcxMWFmMDdkMzNjODBjMzA5MTFlNTMzOTY3ZTZhYWQ3GiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQ="}
{"id":"moby.buildkit.trace","aux":"CnwKR3NoYTI1Njo4ZDk4NzMwYjZkNzNmNDExNzVmNDMwYzA0NDNkNDY1ODcxMWFmMDdkMzNjODBjMzA5MTFlNTMzOTY3ZTZhYWQ3GiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQqCwilmc+7BhD18PA+"}
{"id":"moby.buildkit.trace","aux":"CokBCkdzaGEyNTY6OGQ5ODczMGI2ZDczZjQxMTc1ZjQzMGMwNDQzZDQ2NTg3MTFhZjA3ZDMzYzgwYzMwOTExZTUzMzk2N2U2YWFkNxokW2ludGVybmFsXSBsb2FkIHJlbW90ZSBidWlsZCBjb250ZXh0KgsIpZnPuwYQ9fDwPjILCKWZz7sGEIGUi0M="}
{"id":"moby.buildkit.trace","aux":"CosBCkdzaGEyNTY6OGQ5ODczMGI2ZDczZjQxMTc1ZjQzMGMwNDQzZDQ2NTg3MTFhZjA3ZDMzYzgwYzMwOTExZTUzMzk2N2U2YWFkNxokW2ludGVybmFsXSBsb2FkIHJlbW90ZSBidWlsZCBjb250ZXh0IAEqCwilmc+7BhD2wJlDMgsIpZnPuwYQ+8abQw=="}
{"id":"moby.buildkit.trace","aux":"CqMBCkdzaGEyNTY6OWZhNWNlNjVjNTJlMTUwM2VlNDVhMWM5YzVlYzkxZWQyZjZkODMzYmFiMmQwYWQyMGIzZjc4YWU4ZThmOTZhZhJHc2hhMjU2OjhkOTg3MzBiNmQ3M2Y0MTE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a4a34fe6930783664cfd56c4650708aa168abae7ed4e38bc74b99836d0"}}

docker image  ls
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
myimage      latest    9b7edaa4a34f   6 seconds ago    12.8MB
alpine       latest    21dc6063fd67   3 weeks ago      12.8MB

@thaJeztah
Copy link
Member

Also tried the terraform example, and with that, pulling looks to be working (so definitely issue with the reproduction go code);

Before:

docker run -it --rm -v ./testbuilder/:/testbuilder -w /testbuilder -v /var/run/docker.sock:/var/run/docker.sock --entrypoint /bin/sh hashicorp/terraform:latest

terraform init
# ....

terraform apply -auto-approve

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # docker_image.my-image will be created
  + resource "docker_image" "my-image" {
      + id          = (known after apply)
      + image_id    = (known after apply)
      + name        = "my-image:latest"
      + repo_digest = (known after apply)

      + build {
          + cache_from     = []
          + context        = "/testbuilder"
          + dockerfile     = "Dockerfile"
          + extra_hosts    = []
          + remove         = true
          + security_opt   = []
          + tag            = []
            # (11 unchanged attributes hidden)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
docker_image.my-image: Creating...
╷
│ Error: failed to read downloaded context: failed to load cache key: invalid response status 403
│
│
│
│   with docker_image.my-image,
│   on main.tf line 14, in resource "docker_image" "my-image":
│   14: resource "docker_image" "my-image" {
│
╵

After:

docker run -it --rm -v ./testbuilder/:/testbuilder -w /testbuilder -v /var/run/docker.sock:/var/run/docker.sock --entrypoint /bin/sh hashicorp/terraform:latest

terraform init
# ....

terraform apply -auto-approve

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # docker_image.my-image will be created
  + resource "docker_image" "my-image" {
      + id          = (known after apply)
      + image_id    = (known after apply)
      + name        = "my-image:latest"
      + repo_digest = (known after apply)

      + build {
          + cache_from     = []
          + context        = "/testbuilder"
          + dockerfile     = "Dockerfile"
          + extra_hosts    = []
          + remove         = true
          + security_opt   = []
          + tag            = []
            # (11 unchanged attributes hidden)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
docker_image.my-image: Creating...
docker_image.my-image: Creation complete after 1s [id=sha256:31c6e14aad4d37002e20cf3a94e1659f081471b7807f5dfa99a4f372914ce407my-image:latest]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@rumpl
Copy link
Member Author

rumpl commented Dec 31, 2024

In the terraform example I think it's not using buildkit but the classic builder...

@rumpl
Copy link
Member Author

rumpl commented Dec 31, 2024

In the terraform example I think it's not using buildkit but the classic builder...

Scratch that, terraform is using buildkit

@rumpl
Copy link
Member Author

rumpl commented Dec 31, 2024

Okay so yeah, the code provided by @vvoland was missing a piece, when you call /build with Buildkit enabled you have to create a session and pass it, see:

https://github.com/kreuzwerker/terraform-provider-docker/blob/7155ab079c4d95cf21e8cb9946670a2ddf844f73/internal/provider/resource_docker_image_funcs.go#L358-L375

@thaJeztah
Copy link
Member

Ah, nice! Didn't actually realize that provider was written in Go (didn't go looking as well TBH 😅)

@thaJeztah
Copy link
Member

Bringing this in; I got an "lgtm" from @tonistiigi on Slack

@thaJeztah thaJeztah merged commit b7ae700 into moby:master Jan 3, 2025
184 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/builder Build containerd-integration Issues and PRs related to containerd integration kind/bugfix PR's that fix bugs process/cherry-pick/25.0 process/cherry-picked

Projects

Development

Successfully merging this pull request may close these issues.

containerd integration: Passing a build context via tarball to the /build endpoint is broken

2 participants