Search in sources :

Example 6 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class WatchService method createBuildWatchTask.

private Runnable createBuildWatchTask(final ImageWatcher watcher, final MojoParameters mojoParameters, final boolean doRestart, final BuildService.BuildContext buildContext) throws MojoExecutionException {
    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 MojoExecutionException("No files to watch found for " + imageConfig);
    }
    return new Runnable() {

        @Override
        public void run() {
            List<AssemblyFiles.Entry> entries = files.getUpdatedEntriesAndRefresh();
            if (entries != null && entries.size() > 0) {
                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));
                    if (doRestart) {
                        restartContainer(watcher);
                    }
                    callPostGoal(watcher);
                } catch (Exception e) {
                    log.error("%s: Error when rebuilding - %s", imageConfig.getDescription(), e);
                }
            }
        }
    };
}
Also used : AssemblyFiles(io.fabric8.maven.docker.assembly.AssemblyFiles) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) WatchImageConfiguration(io.fabric8.maven.docker.config.WatchImageConfiguration) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException) ExecException(io.fabric8.maven.docker.access.ExecException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 7 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class ConfigHelperTest method filter.

@Test
public void filter() throws Exception {
    List<ImageConfiguration> configs = Arrays.asList(new ImageConfiguration.Builder().name("test").build());
    CatchingLog logCatcher = new CatchingLog();
    List<ImageConfiguration> result = ConfigHelper.resolveImages(new AnsiLogger(logCatcher, true, true), configs, createResolver(), "bla", createCustomizer());
    assertEquals(0, result.size());
    assertTrue(resolverCalled);
    assertTrue(customizerCalled);
    assertTrue(logCatcher.getWarnMessage().contains("test"));
    assertTrue(logCatcher.getWarnMessage().contains("bla"));
}
Also used : AnsiLogger(io.fabric8.maven.docker.util.AnsiLogger) Test(org.junit.Test)

Example 8 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class PropertyConfigHandlerTest method testDockerFileDir.

@Test
public void testDockerFileDir() {
    String[] testData = new String[] { k(ConfigKey.NAME), "image", k(ConfigKey.DOCKER_FILE_DIR), "dir" };
    ImageConfiguration config = resolveExternalImageConfig(testData);
    assertNotNull(config.getBuildConfiguration());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Example 9 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class PropertyConfigHandlerTest method testRunCommandsFromPropertiesAndConfig.

@Test
public void testRunCommandsFromPropertiesAndConfig() {
    imageConfiguration = new ImageConfiguration.Builder().externalConfig(new HashMap<String, String>()).buildConfig(new BuildImageConfiguration.Builder().runCmds(Arrays.asList("some", "ignored", "value")).build()).build();
    makeExternalConfigUse(PropertyMode.Override);
    List<ImageConfiguration> configs = resolveImage(imageConfiguration, props("docker.from", "base", "docker.name", "demo", "docker.run.1", "propconf", "docker.run.2", "withrun", "docker.run.3", "used"));
    assertEquals(1, configs.size());
    BuildImageConfiguration buildConfig = configs.get(0).getBuildConfiguration();
    String[] runCommands = new ArrayList<>(buildConfig.getRunCmds()).toArray(new String[buildConfig.getRunCmds().size()]);
    assertArrayEquals(new String[] { "propconf", "withrun", "used" }, runCommands);
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Example 10 with ImageConfiguration

use of io.fabric8.maven.docker.config.ImageConfiguration in project docker-maven-plugin by fabric8io.

the class PropertyConfigHandlerTest method testFilterDefault.

@Test
public void testFilterDefault() {
    String[] testData = new String[] { k(ConfigKey.NAME), "image", k(ConfigKey.FROM), "base" };
    ImageConfiguration config = resolveExternalImageConfig(testData);
    assertEquals(DEFAULT_FILTER, config.getBuildConfiguration().getFilter());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AbstractConfigHandlerTest(io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)50 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)38 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)24 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 Test (org.junit.Test)13 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)10 File (java.io.File)9 IOException (java.io.IOException)9 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)8 ArrayList (java.util.ArrayList)8 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)7 Before (org.junit.Before)7 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)6 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)6 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)5 Expectations (mockit.Expectations)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 ExecException (io.fabric8.maven.docker.access.ExecException)4 WatchImageConfiguration (io.fabric8.maven.docker.config.WatchImageConfiguration)4