Search in sources :

Example 1 with RunImageConfiguration

use of org.eclipse.jkube.kit.config.image.RunImageConfiguration in project jkube by eclipse.

the class RunService method createAndStartContainer.

/**
 * Create and start a container with the given image configuration.
 * @param imageConfig image configuration holding the run information and the image name
 * @param portMapping container port mapping
 * @param gavLabel label to tag the started container with
 * @param baseDir base directory
 * @param properties properties to fill in with dynamically assigned ports
 * @param defaultContainerNamePattern pattern to use for naming containers. Can be null in which case a default pattern is used
 * @param buildTimestamp date which should be used as the timestamp when calculating container names
 * @return the container id
 *
 * @throws DockerAccessException if access to the docker backend fails
 */
public String createAndStartContainer(ImageConfiguration imageConfig, PortMapping portMapping, GavLabel gavLabel, Properties properties, File baseDir, String defaultContainerNamePattern, Date buildTimestamp) throws DockerAccessException {
    RunImageConfiguration runConfig = imageConfig.getRunConfiguration();
    String imageName = imageConfig.getName();
    Collection<Container> existingContainers = queryService.getContainersForImage(imageName, true);
    String containerName = ContainerNamingUtil.formatContainerName(imageConfig, defaultContainerNamePattern, buildTimestamp, existingContainers);
    ContainerCreateConfig config = createContainerConfig(imageName, runConfig, portMapping, gavLabel, properties, baseDir);
    String id = docker.createContainer(config, containerName);
    startContainer(imageConfig, id, gavLabel);
    if (portMapping.needsPropertiesUpdate()) {
        updateMappedPortsAndAddresses(id, portMapping);
    }
    return id;
}
Also used : Container(org.eclipse.jkube.kit.build.api.model.Container) ContainerCreateConfig(org.eclipse.jkube.kit.build.service.docker.access.ContainerCreateConfig) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration)

Example 2 with RunImageConfiguration

use of org.eclipse.jkube.kit.config.image.RunImageConfiguration in project jkube by eclipse.

the class PropertyConfigHandlerTest method testPortsFromConfigAndProperties.

@Test
public void testPortsFromConfigAndProperties() {
    imageConfiguration = ImageConfiguration.builder().external(new HashMap<>()).build(BuildConfiguration.builder().ports(Collections.singletonList("1234")).addCacheFrom("foo/bar:latest").build()).run(RunImageConfiguration.builder().ports(Collections.singletonList("jolokia.port:1234")).build()).build();
    makeExternalConfigUse(PropertyMode.Override);
    List<ImageConfiguration> configs = resolveImage(imageConfiguration, props("docker.name", "demo", "docker.ports.1", "9090", "docker.ports.2", "0.0.0.0:80:80", "docker.from", "busybox"));
    assertEquals(1, configs.size());
    RunImageConfiguration runConfig = configs.get(0).getRunConfiguration();
    List<String> portsAsList = runConfig.getPorts();
    String[] ports = new ArrayList<>(portsAsList).toArray(new String[portsAsList.size()]);
    assertArrayEquals(new String[] { "9090", "0.0.0.0:80:80", "jolokia.port:1234" }, ports);
    BuildConfiguration buildConfig = configs.get(0).getBuildConfiguration();
    ports = new ArrayList<>(buildConfig.getPorts()).toArray(new String[buildConfig.getPorts().size()]);
    assertArrayEquals(new String[] { "9090", "80", "1234" }, ports);
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration) ArrayList(java.util.ArrayList) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration) Test(org.junit.Test)

Example 3 with RunImageConfiguration

use of org.eclipse.jkube.kit.config.image.RunImageConfiguration in project jkube by eclipse.

the class ImageConfigurationTest method initAndValidateWithBuildAndRun.

@Test
public void initAndValidateWithBuildAndRun(@Mocked ConfigHelper.NameFormatter nameFormatter, @Mocked BuildConfiguration buildConfiguration, @Mocked RunImageConfiguration runImageConfiguration) {
    // Given
    final ImageConfiguration imageConfiguration = ImageConfiguration.builder().build(buildConfiguration).run(runImageConfiguration).build();
    // @formatter:off
    new Expectations() {

        {
            buildConfiguration.initAndValidate();
            result = "1.337";
            runImageConfiguration.initAndValidate();
            result = "13.37";
        }
    };
    // @formatter:on
    // When
    final String result = ConfigHelper.initAndValidate(nameFormatter, imageConfiguration);
    // Then
    assertThat(result, is("13.37"));
}
Also used : Expectations(mockit.Expectations) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration) Test(org.junit.Test)

Example 4 with RunImageConfiguration

use of org.eclipse.jkube.kit.config.image.RunImageConfiguration in project jkube by eclipse.

the class LogOutputSpecFactory method extractLogConfiguration.

private LogConfiguration extractLogConfiguration(ImageConfiguration imageConfiguration) {
    RunImageConfiguration runConfig = imageConfiguration.getRunConfiguration();
    LogConfiguration logConfig = null;
    if (runConfig != null) {
        logConfig = runConfig.getLog();
    }
    if (logConfig == null) {
        logConfig = LogConfiguration.DEFAULT;
    }
    return logConfig;
}
Also used : LogConfiguration(org.eclipse.jkube.kit.config.image.LogConfiguration) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration)

Example 5 with RunImageConfiguration

use of org.eclipse.jkube.kit.config.image.RunImageConfiguration in project jkube by eclipse.

the class PropertyConfigHandler method resolve.

@Override
public List<ImageConfiguration> resolve(ImageConfiguration fromConfig, JavaProject project) {
    Map<String, String> externalConfig = fromConfig.getExternalConfig();
    String prefix = getPrefix(externalConfig);
    Properties properties = JKubeProjectUtil.getPropertiesWithSystemOverrides(project);
    PropertyMode propertyMode = getMode(externalConfig);
    ValueProvider valueProvider = new ValueProvider(prefix, properties, propertyMode);
    RunImageConfiguration run = extractRunConfiguration(fromConfig, valueProvider);
    BuildConfiguration build = extractBuildConfiguration(fromConfig, valueProvider, project);
    WatchImageConfiguration watch = extractWatchConfig(fromConfig, valueProvider);
    String name = valueProvider.getString(NAME, fromConfig.getName());
    String alias = valueProvider.getString(ALIAS, fromConfig.getAlias());
    if (name == null) {
        throw new IllegalArgumentException(String.format("Mandatory property [%s] is not defined", NAME));
    }
    return Collections.singletonList(ImageConfiguration.builder().name(name).alias(alias).run(run).build(build).watch(watch).build());
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) WatchImageConfiguration(org.eclipse.jkube.kit.config.image.WatchImageConfiguration) Properties(java.util.Properties) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration)

Aggregations

RunImageConfiguration (org.eclipse.jkube.kit.config.image.RunImageConfiguration)5 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)2 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Expectations (mockit.Expectations)1 Container (org.eclipse.jkube.kit.build.api.model.Container)1 ContainerCreateConfig (org.eclipse.jkube.kit.build.service.docker.access.ContainerCreateConfig)1 LogConfiguration (org.eclipse.jkube.kit.config.image.LogConfiguration)1 WatchImageConfiguration (org.eclipse.jkube.kit.config.image.WatchImageConfiguration)1