moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit

Home Page:https://github.com/moby/moby/issues/34227

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support multiple exporters for build

tonistiigi opened this issue · comments

Eg. allow pushing and loading to local tarball with the same request.

moved from docker/buildx#316

hello @tonistiigi

I am looking on this and ready to help. Can you orient me please: I don't understand why you moved the issue to buildkit. I saw that the logic is bloqued by this return : https://github.com/docker/buildx/blob/f3111bcbef8ce7e3933711358419fa18294b3daf/build/build.go#L356

thank you again

@fahedouch The problem is that if you would remove this return in buildx it would just fail in the next lines because buildkit doesn't support this case yet. Eg. https://github.com/moby/buildkit/blob/master/client/solve.go#L119 and then the field currently used by API doesn't even take an array https://github.com/moby/buildkit/blob/master/client/solve.go#L204 .

any updates on this?

is there any workaround?
what about a command of tag and push like we had with docker?

in our case, what's happening is that when we wanted to push to another tag/output,
we have to use bake/build so that it will push to another output. but then, something invalidates the cache and some steps are being rebuilt. as a result, a push phase can take as much time as the build.

Nothing invalidates the cache for me so its really quick to export, I've created another step where I split into two more containers, one for export and one for interactive docker to use. That's the workaround.

Now in my docker file I have two extra lines like this:

FROM scratch AS file_to_export
COPY --from=os_img /file/to/export /

Then I just have the docker builds with the necessary outputs needed:

# --output=type=docker   -> interactive use, mostly to be able to use "docker run" command
# --output=type=registry -> a place where the image can be cached so that we can load it
# --output=type=local,dest=output -> save the entire docker image/file from docker to disk

and of course I tag the images differently too, and I use os_img with the docker export and the new file_to_export as the local file output.

@adminy
Please share the script you use and specify the output types.
I don't understand what is your workaround exactly.
Thanks

run: build
        # Interactive container
	docker buildx build $(FLAGS) --target silly_name_run --tag some_tag --output=type=docker --cache-from=type=registry,ref=$(PREFIX):build .
	docker run --privileged -p 8080:8080 -it some_tag /bin/bash
img: build
        # Output container
	docker buildx build $(FLAGS) --target silly_name_export -o type=local,dest=output --cache-from=type=registry,ref=$(PREFIX):build .
build: some other prequisites
        docker buildx build $(FLAGS) --target silly_build_$@ --output=type=registry --tag $(PREFIX):$@ --cache-from=type=registry,ref=$(PREFIX):$@ --cache-to=type=registry,ref=$(PREFIX):$@,mode=max .