Proposal: TRIGGER Dockerfile instruction

This is a proposal to generalize the ONBUILD Dockerfile instruction into a flexible TRIGGER mecanism.

Rational

ONBUILD is a very straightforward mecanism that is (ab)used the official and other popular base images:
https://registry.hub.docker.com/u/_/golang
https://registry.hub.docker.com/u/google/golang-runtime/
https://registry.hub.docker.com/u/_/node
https://registry.hub.docker.com/u/google/nodejs-runtime

It allows user to easily Dockerize their application, w/ very few instruction in their Dockerfile:

The ONBUILD instructions get automatically inserted from the parent image just after the FROM.

So if you have a base with:

ONBUILD ADD package.json /app/
ONBUILD RUN npm install
ONBUILD ADD . /app/

and a child image with

It will result into

FROM base
ADD package.json /app/
RUN npm install
ADD . /app/

However if you have a child image with:

FROM base
RUN apt-get install -yq fortunes

It will result into:

FROM base
ADD package.json /app/
RUN npm install
ADD . /app/
RUN apt-get install -yq fortunes

Causing the layer w/ apt-get install to be invalidated from the cache everytime you change a file in your context.

Proposal

The TRIGGER instruction allows you to trigger Dockerfile instructions from a parent image.

If a parent image define:

ONBUILD ADD package.json /app/
ONBUILD RUN npm install
ONBUILD ADD . /app/

A child image can decide where to trigger the ONBUILD instructions with:

FROM BASE
RUN apt-get install fortunes
TRIGGER ONBUILD
RUN fortune -m perl

Resulting into:

RUN apt-get install fortunes
ADD package.json /app/
RUN npm install
ADD . /app/
RUN fortune -m perl

The default would still be to TRIGGER ONBUILD just after FROM, if no other TRIGGER ONBUILD instructions is found in the Dockerfile.

Running TRIGGER ONBUILD twice should(?) be forbidden.

Appendix

(#maybe #later #oneday)

The mecanism could be then be extended to allow triggering any Dockerfile instructions annotated in the parent image.

See the over complicated example below:

Base:

@SECURE RUN apt-get update && apt-get install -yq bash
@NPM ADD package.json /app
@NPM RUN npm install
@BOWER ADD bower.json /app
@BOWER RUN bower install
@GULP RUN gulp test
@GULP RUN gulp build

Child:

FROM base IMPORT SECURE, NPM, BOWER, GULP
TRIGGER SECURE
RUN apt-get install fortunes
TRIGGER NPM
RUN curl some/file
TRIGGER BOWER
ADD . /app
TRIGGER GULP  

Result:

FROM base
RUN apt-get update && apt-get install -yq bash
RUN apt-get install fortunes
ADD package.json /app
RUN npm install
RUN curl some/file
ADD bower.json /app
RUN bower install
ADD . /app
RUN gulp test
RUN gulp build

Classical ONBUILD would then be a special case of the more general TRIGGER functionality and downstream image could opt out classical ONBUILD with an empty IMPORT.

IMPORT'ed instructions would br inserted at the corresponding TRIGGER location or after FROM if not triggered explicitly.

Changelog