Search in sources :

Example 6 with ServiceHub

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Fabric8ServiceHub(io.fabric8.maven.core.service.Fabric8ServiceHub) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext)

Example 7 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class BuildMojo method buildAndTag.

protected void buildAndTag(ServiceHub hub, ImageConfiguration imageConfig) throws MojoExecutionException, DockerAccessException {
    EnvUtil.storeTimestamp(getBuildTimestampFile(), getBuildTimestamp());
    BuildService.BuildContext buildContext = getBuildContext();
    ImagePullManager pullManager = getImagePullManager(determinePullPolicy(imageConfig.getBuildConfiguration()), autoPull);
    BuildService buildService = hub.getBuildService();
    buildService.buildImage(imageConfig, pullManager, buildContext);
    if (!skipTag) {
        buildService.tagImage(imageConfig.getName(), imageConfig);
    }
}
Also used : BuildService(io.fabric8.maven.docker.service.BuildService) ImagePullManager(io.fabric8.maven.docker.service.ImagePullManager)

Example 8 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class LogsMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, DockerAccessException {
    QueryService queryService = hub.getQueryService();
    LogDispatcher logDispatcher = getLogDispatcher(hub);
    for (ImageConfiguration image : getResolvedImages()) {
        String imageName = image.getName();
        if (logAll) {
            for (Container container : queryService.getContainersForImage(imageName)) {
                doLogging(logDispatcher, image, container.getId());
            }
        } else {
            Container container = queryService.getLatestContainerForImage(imageName);
            if (container != null) {
                doLogging(logDispatcher, image, container.getId());
            }
        }
    }
    if (follow) {
        // Block forever ....
        waitForEver();
    }
}
Also used : Container(io.fabric8.maven.docker.model.Container) QueryService(io.fabric8.maven.docker.service.QueryService) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher)

Example 9 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class SourceMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
    MojoParameters params = createMojoParameters();
    List<ImageConfiguration> imageConfigs = new ArrayList<>();
    for (ImageConfiguration imageConfig : getResolvedImages()) {
        BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
        if (buildConfig != null) {
            if (buildConfig.skip()) {
                log.info("%s: Skipped creating source", imageConfig.getDescription());
            } else {
                imageConfigs.add(imageConfig);
            }
        }
    }
    if (sourceMode == BuildImageSelectMode.first && imageConfigs.size() > 0) {
        ImageConfiguration imageConfig = imageConfigs.get(0);
        File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
        projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(null), dockerTar);
    } else {
        for (ImageConfiguration imageConfig : imageConfigs) {
            File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
            String alias = imageConfig.getAlias();
            if (alias == null) {
                throw new IllegalArgumentException("Image " + imageConfig.getDescription() + " must have an 'alias' configured to be " + "used as a classifier for attaching a docker build tar as source to the maven build");
            }
            projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(alias), dockerTar);
        }
    }
}
Also used : MojoParameters(io.fabric8.maven.docker.util.MojoParameters) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 10 with ServiceHub

use of io.fabric8.maven.docker.service.ServiceHub in project docker-maven-plugin by fabric8io.

the class StartMojo method startImage.

private void startImage(final ImageConfiguration image, final ServiceHub hub, final ExecutorCompletionService<StartedContainer> startingContainers, final PortMapping.PropertyWriteHelper portMappingPropertyWriteHelper) {
    final RunService runService = hub.getRunService();
    final Properties projProperties = project.getProperties();
    final RunImageConfiguration runConfig = image.getRunConfiguration();
    final PortMapping portMapping = runService.createPortMapping(runConfig, projProperties);
    final LogDispatcher dispatcher = getLogDispatcher(hub);
    startingContainers.submit(new Callable<StartedContainer>() {

        @Override
        public StartedContainer call() throws Exception {
            final String containerId = runService.createAndStartContainer(image, portMapping, getPomLabel(), projProperties, project.getBasedir());
            // Update port-mapping writer
            portMappingPropertyWriteHelper.add(portMapping, runConfig.getPortPropertyFile());
            if (showLogs(image)) {
                dispatcher.trackContainerLog(containerId, serviceHubFactory.getLogOutputSpecFactory().createSpec(containerId, image));
            }
            // Wait if requested
            hub.getWaitService().wait(image, projProperties, containerId);
            WaitConfiguration waitConfig = runConfig.getWaitConfiguration();
            if (waitConfig != null && waitConfig.getExec() != null && waitConfig.getExec().getPostStart() != null) {
                try {
                    runService.execInContainer(containerId, waitConfig.getExec().getPostStart(), image);
                } catch (ExecException exp) {
                    if (waitConfig.getExec().isBreakOnError()) {
                        throw exp;
                    } else {
                        log.warn("Cannot run postStart: %s", exp.getMessage());
                    }
                }
            }
            return new StartedContainer(image, containerId);
        }
    });
}
Also used : LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher) ExecException(io.fabric8.maven.docker.access.ExecException) PortMapping(io.fabric8.maven.docker.access.PortMapping) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException) ExecException(io.fabric8.maven.docker.access.ExecException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)4 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)4 IOException (java.io.IOException)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 ExecException (io.fabric8.maven.docker.access.ExecException)2 PortMapping (io.fabric8.maven.docker.access.PortMapping)2 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)2 VolumeConfiguration (io.fabric8.maven.docker.config.VolumeConfiguration)2 BuildService (io.fabric8.maven.docker.service.BuildService)2 QueryService (io.fabric8.maven.docker.service.QueryService)2 ServiceHub (io.fabric8.maven.docker.service.ServiceHub)2 VolumeService (io.fabric8.maven.docker.service.VolumeService)2 File (java.io.File)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 Fabric8ServiceHub (io.fabric8.maven.core.service.Fabric8ServiceHub)1 DockerAccess (io.fabric8.maven.docker.access.DockerAccess)1 LogOutputSpecFactory (io.fabric8.maven.docker.log.LogOutputSpecFactory)1