Support ONBUILD instruction in Dockerfiles by orzeh · Pull Request #393 · docker-java/docker-java
I have rewritten the logic that adds files to the build context: now it adds all files in Dockerfile parent directory, except those excluded by .dockerignore.
I have also added some tests that demonstrates the issue, which use ONBUILD in Dockerfile.
I also fixed small bug in .dockerignore test: exclude pattern was wrong according to the Dockerfile doc.
Łukasz Warchał added 2 commits
December 7, 2015 22:21
orzeh
mentioned this pull request
@orzeh Adding all files to the build context could be problematic if there are huge files. I really don't know how docker CLI handles this, but seems the builder inspects metadata of the base image (http://docs.docker.com/engine/reference/builder/#onbuild):
At the end of the build, a list of all triggers is stored in the image manifest, under the key OnBuild. They can be inspected with the docker inspect command.
Later the image may be used as a base for a new build, using the FROM instruction. As part of processing the FROM instruction, the downstream builder looks for ONBUILD triggers, and executes them in the same order they were registered. If any of the triggers fail, the FROM instruction is aborted which in turn causes the build to fail. If all triggers succeed, the FROM instruction completes and the build continues as usual.
@orzeh After thinking about again probably you're right. So uploading all files and ignore only those that matches patterns in .dockerignore. Seems our original implementation that adds only files mentioned in the Dockerfile was some kind of premature optimization then.
Any :) from my experience i always placing Dockerfile in clean directory to not have accidental uploads to build context.
Ok, now I get it.
I use ONBUILD when I have several Spring Boot microservices and I add them to the image as a exploded JAR to leverage Docker caching (see this blog post). Then I create base image with number of ONBUILD ADD ... instructions and just put FROM my-base-image in microservices Dockerfiles.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orzeh Could you explain this change please?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to .dockerignore doc:
the root of the context is considered to be both the working and the root directory
then pattern b excludes all files and directories that are named b in root directory of build context.
However, in this test the file named b is under directory a, so it should not be ignored. After my changes this tests fails.
Pattern */b works as expected (and described in the doc see */temp* example)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, now I got it. Thanks for explanation.
marcuslinke
changed the title
Fixes #219
Support ONBUILD instruction in Dockerfiles
@orzeh Thanks for contributing!
orzeh
mentioned this pull request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters