use of io.fabric8.docker.api.model.Image in project docker-maven-plugin by fabric8io.
the class RunService method execInContainer.
/**
* Create and start a Exec container with the given image configuration.
* @param containerId container id to run exec command against
* @param command command to execute
* @param imageConfiguration configuration of the container's image
* @return the exec container id
*
* @throws DockerAccessException if access to the docker backend fails
*/
public String execInContainer(String containerId, String command, ImageConfiguration imageConfiguration) throws DockerAccessException, ExecException {
Arguments arguments = new Arguments();
arguments.setExec(Arrays.asList(EnvUtil.splitOnSpaceWithEscape(command)));
String execContainerId = docker.createExecContainer(containerId, arguments);
docker.startExecContainer(execContainerId, logConfig.createSpec(containerId, imageConfiguration));
ExecDetails execContainer = docker.getExecContainer(execContainerId);
Integer exitCode = execContainer.getExitCode();
if (exitCode != null && exitCode != 0) {
ContainerDetails container = docker.getContainer(containerId);
throw new ExecException(execContainer, container);
}
return execContainerId;
}
use of io.fabric8.docker.api.model.Image 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);
}
}
}
};
}
use of io.fabric8.docker.api.model.Image in project docker-maven-plugin by fabric8io.
the class DockerAccessIT method testCreateContainer.
private void testCreateContainer() throws DockerAccessException {
PortMapping portMapping = new PortMapping(Arrays.asList(new String[] { PORT + ":" + PORT }), new Properties());
ContainerHostConfig hostConfig = new ContainerHostConfig().portBindings(portMapping);
ContainerCreateConfig createConfig = new ContainerCreateConfig(IMAGE).command(new Arguments("ping google.com")).hostConfig(hostConfig);
containerId = dockerClient.createContainer(createConfig, CONTAINER_NAME);
assertNotNull(containerId);
String name = dockerClient.getContainer(containerId).getName();
assertEquals(CONTAINER_NAME, name);
}
use of io.fabric8.docker.api.model.Image in project docker-maven-plugin by fabric8io.
the class DockerAccessWinIT method testCreateContainer.
private void testCreateContainer() throws DockerAccessException {
PortMapping portMapping = new PortMapping(Arrays.asList(new String[] { PORT + ":" + PORT }), new Properties());
ContainerHostConfig hostConfig = new ContainerHostConfig().portBindings(portMapping);
ContainerCreateConfig createConfig = new ContainerCreateConfig(IMAGE).command(new Arguments("ping google.com")).hostConfig(hostConfig);
containerId = dockerClient.createContainer(createConfig, CONTAINER_NAME);
assertNotNull(containerId);
String name = dockerClient.getContainer(containerId).getName();
assertEquals(CONTAINER_NAME, name);
}
use of io.fabric8.docker.api.model.Image in project docker-maven-plugin by fabric8io.
the class DockerAssemblyConfigurationSourceTest method testOutputDirHasImage.
@Test
public void testOutputDirHasImage() {
String image = "image";
MojoParameters params = buildParameters(".", "src/docker", "output/docker");
DockerAssemblyConfigurationSource source = new DockerAssemblyConfigurationSource(params, new BuildDirs(image, params), assemblyConfig);
assertTrue(containsDir(image, source.getOutputDirectory()));
assertTrue(containsDir(image, source.getWorkingDirectory()));
assertTrue(containsDir(image, source.getTemporaryRootDirectory()));
}
Aggregations