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;
}
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);
}
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"));
}
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;
}
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());
}
Aggregations