docker/docker — pull request #9774 by pwaller (2014-12-22 11:00:48+00:00)
Title: Proposal: Add basic build cancellation

Cancelling the build is a desirable function. For example, let's say one wanted
to hook up inotify to trigger a build/run cycle when code was edited. At the
moment if there were multiple changes in quick succession, you would end up
with many in-flight builds contending with each other.

This PR has been optimised for being the smallest useful change. It does not
represent the full changes needed to cancel in all circumstances yet. That
will come later, first I hope to disseminate some understanding of how to
achieve this.

Currently it only allows cancellation during the command running phase. If the
command is a `RUN` statement, the container is killed. Other statements are
not currently interrupted but instead the build is cancelled just before
the next statement.

Cancellation can be used by non-docker clients by cancelling the http request.
There is an example of how to do that here:

https://github.com/fsouza/go-dockerclient/pull/183

---

Add the capability to cancel the build by disconnecting the client.

This adds a `cancelled` channel which is used to signal that a build
should halt. The build is halted by sending a Kill signal and noticing
that the cancellation channel is closed.

This first pass implementation does not allow cancellation during a
pull, but that will come in a subsequent PR.

See also:
https://github.com/docker/docker/issues/3654
https://github.com/docker/docker/issues/6928

Next on my TODO list will be to implement the same thing in a similar style
for `docker pull`, if this PR is accepted. That change will automatically
make the pull phase of builds cancellable, too.

Docker-DCO-1.1-Signed-off-by: Peter Waller (github: pwaller)