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

Fix #1197: Unable to build dockerFile without pushing it to docker server (DockerInDocker) #1297

Merged
merged 1 commit into from
Jan 8, 2020

Conversation

rohanKanojia
Copy link
Member

Fix #1197

with docker.skip.build.image flag we can skip pushing created docker archive to docker daemon.
Peek 2019-11-21 20-29

@rohanKanojia
Copy link
Member Author

However, when I try to load image using this tarball. I get some error:

~/work/repos/dmp-demo-project : $ docker load --input ./target/docker/test-db/tmp/docker-build.tar                                                            
open /var/lib/docker/tmp/docker-import-295740741/repositories: no such file or directory  

Is this desired behavior?

@rhuss
Copy link
Collaborator

rhuss commented Nov 21, 2019

Is this desired behavior?

Yes, I think so. It's really that this tar is picked up e.g. by another build mechansim like Kaniko to build the real image. However, I think it would be important to implement -Ddocker.saveBuildArchive=target/docker-build.tar as well to copy over the tar to a different location so that it can be picked up from there without the need to dive into the target directory. Should be either an absolute path or, if relative, should be relative to the project directory.

@rhuss
Copy link
Collaborator

rhuss commented Nov 21, 2019

Actually thinking again, I think that a single argument should be sufficient:

buildArchiveOnly (property: docker.buildArchiveOnly) for creating only the archive with Dockerfile which needs to be post-processed to create an image. The value should point to the path where to create the archive. If no value is given, the archive is created below target/docker as usual but no image is created.

wdyt ?

@rohanKanojia
Copy link
Member Author

@rhuss : okay, let me do the changes as you asked.

@rohanKanojia
Copy link
Member Author

Here is what I interpreted:

  • Remove docker.skip.build.image
  • Add a new flag docker.buildArchiveOnly which would contain the path to where tarball should be saved/copied. I have one doubt here; If no value is given, the archive is created below target/docker as usual but no image is created. But I thought no value would be the case when we want to POST the tarball to docker daemon. Am I missing something here?

@rhuss
Copy link
Collaborator

rhuss commented Nov 21, 2019

I hope we can detect if the option is given but without value. I'm not 100% if this is possible. Ideally we should also interprete the special values of true and false.

So my suggestion would be:

  • -Ddocker.buildArchiveOnly=/path/to/archive will create the build tar with name /path/to/archive and then stop without actually building
  • -Ddocker.buildArchiveOnly, -Ddocker.buildArchiveOnly=true will just don't build the image (but don't copy over the archive to another place, just leaving it in target.
  • -Ddocker.buildArchiveOnly=false just build as usual. This is the default but might be useful if you want to override this field in sub-module pom.

@rohanKanojia wdyt ? I think this will nicely cover this feature with a single config option but still staying flexible and intuitive.

@rohanKanojia
Copy link
Member Author

cool 👍 , let me implement this in next update

@rohanKanojia
Copy link
Member Author

rohanKanojia commented Nov 21, 2019

Here is how it looks now:

  • Using docker.buildArchiveOnly=/new/path
    Peek 2019-11-22 02-11
  • Using docker.buildArchiveOnly=true
    Peek 2019-11-22 02-17
  • Using normal docker:build
    Peek 2019-11-22 02-19

@marcsaegesser
Copy link

I hadn't noticed that the discussion had moved over here. Sorry for delay responding.

I cloned this repo, built this branch and did some testing. So far things look good. I had to add -Ddocker.skip.tag=true when using -Ddocker.buildArchiveOnly or the build failed when trying to tag a non-existent image. Should docker.buildArchiveOnly imply docker.skip.tag?

I've updated one of my CI/CD pipelines to use this version of the plugin and then used Kaniko to create the Docker image in an environment that had no Docker daemon.

@rohanKanojia rohanKanojia requested a review from rhuss December 20, 2019 13:33
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.

looks good to me with one minor change request.

* @return tarball for docker image
* @throws MojoExecutionException in case any exception comes during building tarball
*/
public File buildArchive(ImageConfiguration imageConfiguration, BuildContext buildContext, String buildArchiveOnlyFlagOrBuildArchiveLocation)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make the last argument just a archivePath and if not-null, store the archive there ? The caller should then prepare that parameter based on the options given. That way this method becomes much more reusable and decoupled from its actual, Maven specific usage.

log.info("%s: Created %s in %s", imageConfiguration.getDescription(), dockerArchive.getName(), EnvUtil.formatDurationTill(time));

// Copy created tarball to directory if specified
if (buildArchiveOnlyFlagOrBuildArchiveLocation != null && !buildArchiveOnlyFlagOrBuildArchiveLocation.isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we extract that to a method ? Also, remember, when its empty its the same as false

@@ -71,7 +77,10 @@ protected void buildAndTag(ServiceHub hub, ImageConfiguration imageConfig)
ImagePullManager pullManager = getImagePullManager(determinePullPolicy(imageConfig.getBuildConfiguration()), autoPull);
BuildService buildService = hub.getBuildService();

buildService.buildImage(imageConfig, pullManager, buildContext);
File buildArchiveFile = buildService.buildArchive(imageConfig, buildContext, buildArchiveOnly);
Copy link
Collaborator

Choose a reason for hiding this comment

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

as mentioned below, the option should be already resolved here to the path (if any) for calling buildArchive

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.

Thanks a lot ! The last thing missing would be an update to the documentation, then we are ready to go.

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.

Thanks ! Some minor formatting issues, but I will fix that later.

let's merge it.

@rhuss rhuss merged commit 64aba10 into fabric8io:master Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to build dockerFile without pushing it to docker server (DockerInDocker)
3 participants