use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.
the class BuildMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
if (skipBuild) {
return;
}
List<ImageConfiguration> resolvedImages = getResolvedImages();
if (resolvedImages.isEmpty()) {
// No Configuration found, so build one up dynamically.
if (imageName == null) {
/*
* Image name defaults to:
* `${project.groupId}/${project.artifactId}:${project.version}`
*/
imageName = project.getGroupId() + "/" + project.getArtifactId() + ":" + project.getVersion();
}
ImageConfiguration aDefaultImageConfig = ImageConfiguration.getDefaultImageConfiguration(imageName, project.getBasedir().getAbsolutePath());
processImageConfig(hub, aDefaultImageConfig);
return;
} else {
// Iterate over all the ImageConfigurations and process one by one
for (ImageConfiguration imageConfig : resolvedImages) {
processImageConfig(hub, imageConfig);
}
}
}
use of io.fabric8.maven.docker.service.ServiceHub in project fabric8-maven-plugin by fabric8io.
the class WatchMojo method customizeConfig.
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
Fabric8ServiceHub serviceHub = getFabric8ServiceHub();
GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:watch").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).artifactResolver(serviceHub.getArtifactResolverService()).build();
return GeneratorManager.generate(configs, ctx, false);
} catch (MojoExecutionException e) {
throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
}
}
use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.
the class JibBuildService method build.
public void build(String jibImageFormat, ImageConfiguration imageConfig, RegistryService.RegistryConfig registryConfig) throws MojoExecutionException {
try {
log.info("[[B]]JIB[[B]] image build started");
if (imageConfig.getBuildConfiguration().isDockerFileMode()) {
throw new MojoExecutionException("Dockerfile mode is not supported with JIB build strategy");
}
prependRegistry(imageConfig, mojoParameters.getProject().getProperties().getProperty(PUSH_REGISTRY));
BuildDirs buildDirs = new BuildDirs(imageConfig.getName(), mojoParameters);
final Credential pullRegistryCredential = getRegistryCredentials(registryConfig, false, imageConfig, log);
final JibContainerBuilder containerBuilder = containerFromImageConfiguration(jibImageFormat, imageConfig, pullRegistryCredential);
File dockerTarArchive = getAssemblyTarArchive(imageConfig, serviceHub, mojoParameters, log);
for (AssemblyConfiguration assemblyConfiguration : imageConfig.getBuildConfiguration().getAssemblyConfigurations()) {
// TODO: Improve Assembly Manager so that the effective assemblyFileEntries computed can be properly shared
// the call to DockerAssemblyManager.getInstance().createDockerTarArchive should not be necessary,
// files should be added using the AssemblyFileEntry list. DockerAssemblyManager, should provide
// a common way to achieve this so that both the tar builder and any other builder could get a hold of
// archive customizers, file entries, etc.
AssemblyFiles assemblyFiles = serviceHub.getDockerAssemblyManager().getAssemblyFiles(imageConfig.getName(), assemblyConfiguration, mojoParameters, log);
final Map<File, AssemblyFiles.Entry> files = assemblyFiles.getUpdatedEntriesAndRefresh().stream().collect(Collectors.toMap(AssemblyFiles.Entry::getDestFile, Function.identity(), (oldV, newV) -> newV));
JibServiceUtil.copyToContainer(containerBuilder, buildDirs.getOutputDirectory(), buildDirs.getOutputDirectory().getAbsolutePath(), files);
}
JibServiceUtil.buildContainer(containerBuilder, TarImage.at(dockerTarArchive.toPath()).named(imageConfig.getName()), log);
log.info(" %s successfully built", dockerTarArchive.getAbsolutePath());
} catch (Exception ex) {
throw new MojoExecutionException("Error when building JIB image", ex);
}
}
use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.
the class SaveMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub serviceHub) throws DockerAccessException, MojoExecutionException {
List<ImageConfiguration> images = getResolvedImages();
if (skipSaveFor(images)) {
return;
}
ImageConfiguration image = getImageToSave(images);
String imageName = image.getName();
String fileName = getFileName(imageName);
ensureSaveDir(fileName);
log.info("Saving image %s to %s", imageName, fileName);
if (!serviceHub.getQueryService().hasImage(imageName)) {
throw new MojoExecutionException("No image " + imageName + " exists");
}
long time = System.currentTimeMillis();
ArchiveCompression compression = ArchiveCompression.fromFileName(fileName);
serviceHub.getDockerAccess().saveImage(imageName, fileName, compression);
log.info("%s: Saved image to %s in %s", imageName, fileName, EnvUtil.formatDurationTill(time));
String classifier = getClassifier(image);
if (classifier != null) {
projectHelper.attachArtifact(project, compression.getFileSuffix(), classifier, new File(fileName));
}
}
use of io.fabric8.maven.docker.service.ServiceHub 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;
}
Aggregations