use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.
the class StartMojo method prepareStart.
// Prepare start like creating custom networks, auto pull images, map aliases and return the list of images
// to start in the correct order
private Queue<ImageConfiguration> prepareStart(ServiceHub hub, QueryService queryService, RunService runService, Set<String> imageAliases) throws DockerAccessException, MojoExecutionException {
final Queue<ImageConfiguration> imagesWaitingToStart = new ArrayDeque<>();
for (StartOrderResolver.Resolvable resolvable : runService.getImagesConfigsInOrder(queryService, getResolvedImages())) {
final ImageConfiguration imageConfig = (ImageConfiguration) resolvable;
// Still to check: How to work with linking, volumes, etc ....
// String imageName = new ImageName(imageConfig.getName()).getFullNameWithTag(registry);
RegistryService registryService = hub.getRegistryService();
pullImage(registryService, imageConfig, pullRegistry);
RunImageConfiguration runConfig = imageConfig.getRunConfiguration();
NetworkConfig config = runConfig.getNetworkingConfig();
List<String> bindMounts = extractBindMounts(runConfig.getVolumeConfiguration());
List<VolumeConfiguration> volumes = getVolumes();
if (!bindMounts.isEmpty() && volumes != null) {
runService.createVolumesAsPerVolumeBinds(hub, bindMounts, volumes);
}
if (autoCreateCustomNetworks && config.isCustomNetwork()) {
runService.createCustomNetworkIfNotExistant(config.getCustomNetwork());
}
imagesWaitingToStart.add(imageConfig);
updateAliasesSet(imageAliases, imageConfig.getAlias());
}
return imagesWaitingToStart;
}
use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.
the class CopyMojo method copyFromTemporaryContainers.
private void copyFromTemporaryContainers(DockerAccess dockerAccess, RunService runService, RegistryService registryService, ArchiveService archiveService, QueryService queryService, GavLabel gavLabel) throws IOException, MojoExecutionException {
List<ImageConfiguration> imageConfigurations = getResolvedImages();
for (ImageConfiguration imageConfiguration : imageConfigurations) {
CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
String imageName = imageConfiguration.getName();
if (isEmpty(copyConfiguration)) {
log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
continue;
}
try (ContainerRemover containerRemover = new ContainerRemover(log, runService, removeVolumes)) {
String containerId = createContainer(runService, registryService, imageConfiguration, gavLabel);
containerRemover.setContainerId(containerId);
log.debug("Created %s container from %s image", containerId, imageName);
copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
}
}
}
use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.
the class CopyMojo method copyFromStartedContainers.
private void copyFromStartedContainers(DockerAccess dockerAccess, RunService runService, ArchiveService archiveService, GavLabel gavLabel) throws IOException, MojoExecutionException {
List<ContainerDescriptor> containerDescriptors = runService.getContainers(gavLabel);
for (ContainerDescriptor containerDescriptor : containerDescriptors) {
ImageConfiguration imageConfiguration = containerDescriptor.getImageConfig();
CopyConfiguration copyConfiguration = imageConfiguration.getCopyConfiguration();
String imageName = imageConfiguration.getName();
if (isEmpty(copyConfiguration)) {
log.debug("Copy configuration is not defined for %s image, skipping coping", imageName);
continue;
}
String containerId = containerDescriptor.getContainerId();
log.debug("Found %s container of %s image started by start mojo", containerId, imageName);
copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
}
}
use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.
the class CopyMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub hub) throws IOException, MojoExecutionException {
DockerAccess dockerAccess = hub.getDockerAccess();
RunService runService = hub.getRunService();
ArchiveService archiveService = hub.getArchiveService();
QueryService queryService = hub.getQueryService();
GavLabel gavLabel = getGavLabel();
if (createContainers) {
RegistryService registryService = hub.getRegistryService();
log.debug("Copy mojo is invoked standalone, copying from new temporary containers");
copyFromTemporaryContainers(dockerAccess, runService, registryService, archiveService, queryService, gavLabel);
} else if (invokedTogetherWithDockerStart()) {
log.debug("Copy mojo is invoked together with start mojo, copying from containers created by start mojo");
copyFromStartedContainers(dockerAccess, runService, archiveService, gavLabel);
} else {
log.debug("Copy mojo is invoked standalone, copying from existing containers");
copyFromExistingContainers(dockerAccess, archiveService, queryService);
}
}
use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.
the class StopMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, IOException, ExecException {
QueryService queryService = hub.getQueryService();
RunService runService = hub.getRunService();
GavLabel gavLabel = getGavLabel();
if (!keepRunning) {
if (invokedTogetherWithDockerStart()) {
runService.stopStartedContainers(keepContainer, removeVolumes, autoCreateCustomNetworks, gavLabel);
} else {
stopContainers(queryService, runService, gavLabel);
}
}
// Switch off all logging
LogDispatcher dispatcher = getLogDispatcher(hub);
dispatcher.untrackAllContainerLogs();
}
Aggregations