private void buildDockerImage()

in plugins/docker/base-image/src/main/java/co/elastic/gradle/dockerbase/DockerBaseImageBuildTask.java [255:299]


    private void buildDockerImage() {
        DockerDaemonActions daemonActions = getObjectFactory().newInstance(DockerDaemonActions.class, this);
        DockerUtils dockerUtils = new DockerUtils(getExecOperations());
        try {
            UUID uuid = daemonActions.build();

            try (BufferedOutputStream createAtFileOut = new BufferedOutputStream(
                    Files.newOutputStream(RegularFileUtils.toPath(getCreatedAtFile())))
            ) {
                int imageInspect = dockerUtils.exec(spec -> {
                    spec.setWorkingDir(getWorkingDirectory());
                    spec.setStandardOutput(createAtFileOut);
                    spec.commandLine("docker", "image", "inspect", "--format", "{{.Created}}", uuid);
                    spec.setIgnoreExitValue(true);
                }).getExitValue();
                if (imageInspect != 0) {
                    throw new GradleException(
                            "Failed to inspect docker image, see the docker build log in the task output"
                    );
                }
            }

            final Path imageArchive = RegularFileUtils.toPath(getImageArchive());
            try (ZstdCompressorOutputStream compressedOut = new ZstdCompressorOutputStream(
                    new BufferedOutputStream(Files.newOutputStream(imageArchive)))) {
                ExecResult imageSave = dockerUtils.exec(spec -> {
                    spec.setStandardOutput(compressedOut);
                    spec.setCommandLine("docker", "save", uuid.toString());
                    spec.setIgnoreExitValue(true);
                });
                if (imageSave.getExitValue() != 0) {
                    throw new GradleException(
                            "Failed to save docker image, see the docker build log in the task output"
                    );
                }
            }

            dockerUtils.exec(spec -> {
                spec.commandLine("docker", "image", "rm", "-f", uuid);
                spec.setIgnoreExitValue(false);
            });
        } catch (IOException e) {
            throw new GradleException("Error building docker base image", e);
        }
    }