-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
buildinfo: named input contexts support #2654
Conversation
First example based on https://github.com/docker/buildx/blob/master/docs/reference/buildx_bake.md#pinning-alpine-image # Dockerfile
FROM alpine
RUN echo "Hello world" # docker-bake.hcl
target "app" {
contexts = {
alpine = "docker-image://alpine:3.13"
}
} $ docker buildx bake --metadata-file metadata.json --set *.args.foo=bar --set *.args.bar=foo app
$ cat metadata.json {
"containerimage.buildinfo": {
"frontend": "dockerfile.v0",
"attrs": {
"build-arg:bar": "foo",
"build-arg:foo": "bar",
"context:alpine": "docker-image://alpine:3.13",
"filename": "Dockerfile"
},
"sources": [
{
"type": "docker-image",
"ref": "docker.io/library/alpine:3.13",
"pin": "sha256:026f721af4cf2843e07bba648e158fb35ecc876d822130633cc49f707f0fc88c"
}
]
}
} |
Second example https://github.com/docker/buildx/blob/master/docs/reference/buildx_bake.md#using-a-secondary-source-directory # Dockerfile
FROM scratch AS src
FROM busybox
COPY --from=src . /src
RUN ls -al /src # docker-bake.hcl
target "app" {
contexts = {
src = "../ctx-src"
}
} $ docker buildx bake --metadata-file metadata.json --set *.args.foo=bar --set *.args.bar=foo app
$ cat metadata.json {
"containerimage.buildinfo": {
"frontend": "dockerfile.v0",
"attrs": {
"build-arg:bar": "foo",
"build-arg:foo": "bar",
"context:src": "local:src",
"filename": "Dockerfile"
},
"sources": [
{
"type": "docker-image",
"ref": "busybox",
"alias": "docker.io/library/busybox@sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb",
"pin": "sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb"
}
]
}
} |
# baseapp.Dockerfile
FROM busybox
WORKDIR /src # Dockerfile
FROM baseapp
RUN echo "Hello world" # docker-bake.hcl
target "base" {
dockerfile = "baseapp.Dockerfile"
}
target "app" {
contexts = {
baseapp = "target:base"
}
} $ docker buildx bake --metadata-file metadata.json --set *.args.foo=bar --set *.args.bar=foo app
$ cat metadata.json {
"app": {
"containerimage.buildinfo": {
"frontend": "dockerfile.v0",
"attrs": {
"build-arg:bar": "foo",
"build-arg:foo": "bar",
"context:baseapp": "input:0-base",
"filename": "Dockerfile"
}
}
},
"base": {
"containerimage.buildinfo": {
"frontend": "dockerfile.v0",
"attrs": {
"build-arg:bar": "foo",
"build-arg:foo": "bar",
"filename": "baseapp.Dockerfile"
},
"sources": [
{
"type": "docker-image",
"ref": "busybox",
"alias": "docker.io/library/busybox@sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb",
"pin": "sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb"
}
]
}
}
} I can see this attr is filtered out:
Should we merge |
This comment was marked as outdated.
This comment was marked as outdated.
69b2dda
to
cb6f74c
Compare
@tonistiigi Last commit adds FROM busybox
RUN echo "Hello World" > /hello Build this image and push to the registry: $ docker buildx build --metadata-file metadata.json --platform linux/amd64,linux/arm64 --tag crazymax/busybox:buildinfo --push . Build info in image config should look like this: $ docker pull crazymax/busybox:buildinfo
$ docker image save crazymax/busybox:buildinfo | tar -ax --exclude 'manifest.json' --wildcards '*.json' -O | jq -r '."moby.buildkit.buildinfo.v1"' | base64 --decode | jq {
"frontend": "dockerfile.v0",
"sources": [
{
"type": "docker-image",
"ref": "docker.io/library/busybox:latest",
"pin": "sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb"
}
]
} Create another Dockerfile that will use this image: FROM crazymax/busybox:buildinfo
WORKDIR /src Build info of $ docker buildx build --metadata-file metadata.json --build-arg foo=bar --build-arg bar=foo .
$ cat metadata.json {
"containerimage.buildinfo": {
"frontend": "dockerfile.v0",
"attrs": {
"build-arg:bar": "foo",
"build-arg:foo": "bar",
"filename": "baseapp.Dockerfile"
},
"sources": [
{
"type": "docker-image",
"ref": "docker.io/crazymax/busybox:buildinfo",
"pin": "sha256:afa2baea8c14ae33d4430f42883836dab4770208c09d21706219daef3c044aa4"
}
],
"deps": {
"crazymax/busybox:buildinfo": {
"frontend": "dockerfile.v0",
"sources": [
{
"type": "docker-image",
"ref": "docker.io/library/busybox:latest",
"pin": "sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb"
}
]
}
}
}
} Here I use the original image ref as dep key ( |
6772a40
to
921cfb6
Compare
Deps map should not contain buildinfo for the sources, read from the config. The goal is not to gather all build sources recursively(and atm it is just one level of recursiveness anyway). Only for the buildinfo sent with inputs in docker/buildx#958 . The difference is that while for image sources we can get buildinfo from the image itself, for the inputs they don't exist anywhere. So if you rebuild from buildinfo you need to rebuild the deps as well and therefore need buildinfo for the deps. I'm not sure how this looks like for multi-arch builds as well. I think atm the platform would appear in these keys and I'm not sure if that is correct or not. Feels wrong if you get different buildinfo depending on if you built for a single arch or for the one arch inside of the multi-arch image. |
921cfb6
to
359ceeb
Compare
359ceeb
to
f2a7c0a
Compare
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
f2a7c0a
to
c8429c0
Compare
Yes was thinking it could be useful but that's out of scope agree and should be handled by others tooling. I removed that behavior.
I've added a test for multiplatform and deps https://github.com/moby/buildkit/pull/2654/files#diff-7df700366904727b0358fe2ed234172b34a8d68782c1ef1c255fb8379db79c9bR385. Excpected output for buildinfo: {
"frontend": "dockerfile.v0",
"attrs": {
"context:base::linux/amd64": "input:base::linux/amd64",
"context:base::linux/arm64": "input:base::linux/arm64"
},
"sources": [
{
"type": "docker-image",
"ref": "docker.io/library/alpine@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3",
"pin": "sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
},
{
"type": "docker-image",
"ref": "docker.io/library/busybox:latest",
"pin": "sha256:b69959407d21e8a062e0416bf13405bb2b71ed7a84dde4158ebafacfa06f5578"
}
],
"deps": {
"base:linux/amd64": {
"frontend": "dockerfile.v0",
"sources": [
{
"type": "docker-image",
"ref": "alpine",
"alias": "docker.io/library/alpine@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3",
"pin": "sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
]
},
"base:linux/arm64": {
"frontend": "dockerfile.v0",
"sources": [
{
"type": "docker-image",
"ref": "alpine",
"alias": "docker.io/library/alpine@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3",
"pin": "sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
]
}
}
} So yeah it's what you expected. We can discuss about that next week as well as bake keys. |
Is what I see from bake atm. Under Ideally, we can clean up the names like |
c8429c0
to
9989dd3
Compare
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
9989dd3
to
2661917
Compare
Now platforms not tied to the metadata key (eg {
"frontend": "dockerfile.v0",
"attrs": {
"context:base": "input:base"
},
"sources": [
{
"type": "docker-image",
"ref": "docker.io/library/alpine@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3",
"pin": "sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
},
{
"type": "docker-image",
"ref": "docker.io/library/busybox:latest",
"pin": "sha256:b69959407d21e8a062e0416bf13405bb2b71ed7a84dde4158ebafacfa06f5578"
}
],
"deps": {
"base": {
"frontend": "dockerfile.v0",
"sources": [
{
"type": "docker-image",
"ref": "alpine",
"alias": "docker.io/library/alpine@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3",
"pin": "sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
}
]
}
}
}
Yes it should be done on buildx. |
|
||
// if platform is defined, only decode dependencies for that platform | ||
if platform != "" && !strings.HasSuffix(k, "::"+platform) { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, we should do a follow-up that handles the contexts without suffixes as well for multi-platform cases.
follow-up #2476
Signed-off-by: CrazyMax crazy-max@users.noreply.github.com