Search in sources :

Example 1 with AssemblyFiles

use of org.eclipse.jkube.kit.build.api.assembly.AssemblyFiles in project jkube by eclipse.

the class WatchService method createCopyWatchTask.

private Runnable createCopyWatchTask(final ImageWatcher watcher, final JKubeConfiguration jKubeConfiguration) throws IOException {
    final ImageConfiguration imageConfig = watcher.getImageConfiguration();
    final AssemblyFiles files = archiveService.getAssemblyFiles(imageConfig, jKubeConfiguration);
    return () -> {
        List<AssemblyFileEntry> entries = files.getUpdatedEntriesAndRefresh();
        if (!entries.isEmpty()) {
            try {
                log.info("%s: Assembly changed. Copying changed files to container...", imageConfig.getDescription());
                File changedFilesArchive = archiveService.createChangedFilesArchive(entries, files.getAssemblyDirectory(), imageConfig.getName(), jKubeConfiguration);
                copyFilesToContainer(changedFilesArchive, watcher);
                callPostExec(watcher);
            } catch (IOException | WatchException e) {
                log.error("%s: Error when copying files to container %s: %s", imageConfig.getDescription(), watcher.getContainerId(), e.getMessage());
            }
        }
    };
}
Also used : AssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyFiles) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) WatchImageConfiguration(org.eclipse.jkube.kit.config.image.WatchImageConfiguration) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 2 with AssemblyFiles

use of org.eclipse.jkube.kit.build.api.assembly.AssemblyFiles in project jkube by eclipse.

the class WatchService method createBuildWatchTask.

Runnable createBuildWatchTask(final ImageWatcher watcher, final JKubeConfiguration mojoParameters, final boolean doRestart, final JKubeConfiguration buildContext) throws IOException {
    final ImageConfiguration imageConfig = watcher.getImageConfiguration();
    final AssemblyFiles files = archiveService.getAssemblyFiles(imageConfig, mojoParameters);
    if (files.isEmpty()) {
        log.error("No assembly files for %s. Are you sure you invoked together with the `package` goal?", imageConfig.getDescription());
        throw new IOException("No files to watch found for " + imageConfig);
    }
    return () -> {
        List<AssemblyFileEntry> entries = files.getUpdatedEntriesAndRefresh();
        if (entries != null && !entries.isEmpty()) {
            try {
                log.info("%s: Assembly changed. Rebuild ...", imageConfig.getDescription());
                if (watcher.getWatchContext().getImageCustomizer() != null) {
                    log.info("%s: Customizing the image ...", imageConfig.getDescription());
                    watcher.getWatchContext().getImageCustomizer().execute(imageConfig);
                }
                buildService.buildImage(imageConfig, null, buildContext);
                String name = imageConfig.getName();
                watcher.setImageId(queryService.getImageId(name));
                restartContainerAndCallPostGoal(watcher, doRestart);
            } catch (Exception e) {
                log.error("%s: Error when rebuilding - %s", imageConfig.getDescription(), e);
            }
        }
    };
}
Also used : AssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyFiles) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) WatchImageConfiguration(org.eclipse.jkube.kit.config.image.WatchImageConfiguration) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) IOException(java.io.IOException) WatchException(org.eclipse.jkube.kit.build.service.docker.watch.WatchException)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 AssemblyFiles (org.eclipse.jkube.kit.build.api.assembly.AssemblyFiles)2 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)2 RunImageConfiguration (org.eclipse.jkube.kit.config.image.RunImageConfiguration)2 WatchImageConfiguration (org.eclipse.jkube.kit.config.image.WatchImageConfiguration)2 File (java.io.File)1 IOException (java.io.IOException)1 WatchException (org.eclipse.jkube.kit.build.service.docker.watch.WatchException)1