-
Notifications
You must be signed in to change notification settings - Fork 642
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
Added 'contextDir' configuration option. Used to specify Docker build context #1189
Conversation
This is still wip, I haven't tested it properly and haven't updated docs yet. |
… context (if Dockerfile located externally to build context) Signed-off-by: Andrey Osipov <blaketsk@gmail.com>
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.
Except that the Docker file should not be copied into the contextDir but in a generated directory below target/ where we build up the tar archive for the Docker daemon, the PR looks good.
See my comments, too.
doc/changelog.md
Outdated
- Add support for auto-pulling multiple base image for multi stage builds (#1057) | ||
- Fix usage of credential helper that do not support 'version' command (#1159) | ||
|
||
Please note that `dockerFileDir` is now deprecated in favor of `contextDir` and it would be removed in 1.0.0. |
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.
... will be ..
doc/changelog.md
Outdated
- Add support for auto-pulling multiple base image for multi stage builds (#1057) | ||
- Fix usage of credential helper that do not support 'version' command (#1159) | ||
|
||
Please note that `dockerFileDir` is now deprecated in favor of `contextDir` and it would be removed in 1.0.0. | ||
It's still supported in this release but users are suggested to migrate to `contextDir` instead. |
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.
Maybe state also the difference, namely that contextDir
allows absolute paths to Dockerfile with dockerFile
while dockerFileDir
does not.
samples/dockerfile/pom.xml
Outdated
@@ -59,6 +59,7 @@ | |||
<build> | |||
<!-- filter>@</filter--> | |||
<dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir> |
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.
Please remove dockerFileDir in the sample as I guess its more confusing than helpful.
@@ -11,9 +11,10 @@ When using this mode, the Dockerfile is created on the fly with all instructions | |||
.External Dockerfile or Docker archive | |||
Alternatively an external Dockerfile template or Docker archive can be used. This mode is switched on by using one of these three configuration options within | |||
|
|||
* *dockerFileDir* specifies a directory containing a Dockerfile that will be used to create the image. The name of the Dockerfile is `Dockerfile` by default but can be also set with the option `dockerFile` (see below). | |||
* *dockerFile* specifies a specific Dockerfile path. The Docker build context directory is set to `dockerFileDir` if given. If not the directory by default is the directory in which the Dockerfile is stored. | |||
* *dockerFileDir* *(This option is deprecated, please use contextDir instead)* specifies a directory containing a Dockerfile that will be used to create the image. The name of the Dockerfile is `Dockerfile` by default but can be also set with the option `dockerFile` (see below). |
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.
just use: (deprecated, use contextDir)
that's could enough ;-)
* *dockerArchive* specifies a previously saved image archive to load directly. Such a tar archive can be created with `docker save`. If a `dockerArchive` is provided, no `dockerFile` or `dockerFileDir` must be given. | ||
* *contextDir* specifies docker build context if an external dockerfile is located outside of Docker build context. If not specified, Dockerfile's parent directory is used as build context. |
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.
exchange position of contextDir
and dockerFileDir
in list.
@@ -130,7 +130,9 @@ public File createDockerTarArchive(String imageName, final MojoParameters params | |||
archiveCustomizers.add(new ArchiverCustomizer() { | |||
@Override | |||
public TarArchiver customize(TarArchiver archiver) throws IOException { | |||
DefaultFileSet fileSet = DefaultFileSet.fileSet(dockerFile.getParentFile()); | |||
DefaultFileSet fileSet = DefaultFileSet.fileSet(buildConfig.getContextDir() != null |
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.
According to your change below, buildConfig.getContextDir()
can never be null.
throw new IllegalArgumentException("<dockerFile> can not be absolute path if <dockerFileDir> also set."); | ||
if(contextDir != null) { | ||
if(dockerFileDir != null) { | ||
log.warn("using contextDir as it has more precedence for Dockerfile"); |
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.
Precedence over what ? Suggestion: "Both contextDir (%s) and deprecated dockerFileDir (%s) are configured. Using contextDir." (with inserting the concrete values)
|
||
if (dFile.isAbsolute()) { | ||
try { | ||
Files.copy(dFile.toPath(), Paths.get(contextDir)); |
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.
I don't think that the dockerfile should be copied int the contextDir
as this is typically a source code controlled directory. Intead it should be copied into the build dir where the context is copied to for creating the tar archive to be send to the Docker daemon.
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.
Could you please tell me where are you creating tar archive? Is it here:
docker-maven-plugin/src/main/java/io/fabric8/maven/docker/assembly/DockerAssemblyManager.java
Lines 130 to 140 in dc82c82
archiveCustomizers.add(new ArchiverCustomizer() { | |
@Override | |
public TarArchiver customize(TarArchiver archiver) throws IOException { | |
DefaultFileSet fileSet = DefaultFileSet.fileSet(dockerFile.getParentFile()); | |
addDockerIncludesExcludesIfPresent(fileSet, params); | |
// Exclude non-interpolated dockerfile from source tree | |
// Interpolated Dockerfile is already added as it was created into the output directory when | |
// using dir dir mode | |
excludeDockerfile(fileSet, dockerFile); | |
// If the content is added as archive, then we need to add the Dockerfile from the builddir |
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.
It's here where the Dockerfile is copied to its target directory:
docker-maven-plugin/src/main/java/io/fabric8/maven/docker/assembly/DockerAssemblyManager.java
Lines 196 to 202 in dec36f1
private void interpolateDockerfile(File dockerFile, BuildDirs params, FixedStringSearchInterpolator interpolator) throws IOException { | |
File targetDockerfile = new File(params.getOutputDirectory(), dockerFile.getName()); | |
String dockerFileInterpolated = DockerFileUtil.interpolate(dockerFile, interpolator); | |
try (Writer writer = new FileWriter(targetDockerfile)) { | |
IOUtils.write(dockerFileInterpolated, writer); | |
} | |
} |
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.
okay, thanks
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.
to bo honest, I am still confused. Aren't we copying Dockerfile
here already into build directory? Could you please tell me also where is dockerFileDir
/contextDir
getting copied? do we need to copy Dockerfile
just inside build or inside the contextDir
?
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.
hey, we were not done with this comment? Is it okay to merge it without addressing it?
src/main/java/io/fabric8/maven/docker/config/BuildImageConfiguration.java
Show resolved
Hide resolved
df9c7e7
to
cdc9c5c
Compare
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.
cool, thanks ! Looks good to me.
This is the continuation of #995