Skip to content
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

Merged
merged 2 commits into from
Apr 7, 2019

Conversation

rohanKanojia
Copy link
Member

@rohanKanojia rohanKanojia commented Apr 6, 2019

This is the continuation of #995

@rohanKanojia
Copy link
Member Author

This is still wip, I haven't tested it properly and haven't updated docs yet.

@rohanKanojia rohanKanojia added the WIP Work in Progress label Apr 6, 2019
… context (if Dockerfile located externally to build context)

Signed-off-by: Andrey Osipov <blaketsk@gmail.com>
Copy link
Collaborator

@rhuss rhuss left a 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.
Copy link
Collaborator

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.
Copy link
Collaborator

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.

@@ -59,6 +59,7 @@
<build>
<!-- filter>@</filter-->
<dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
Copy link
Collaborator

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).
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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");
Copy link
Collaborator

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));
Copy link
Collaborator

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.

Copy link
Member Author

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:

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

Copy link
Collaborator

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:

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);
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, thanks

Copy link
Member Author

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?

Copy link
Member Author

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?

Copy link
Collaborator

@rhuss rhuss left a 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.

@rhuss rhuss merged commit 2ff5bd4 into fabric8io:master Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants