Search in sources :

Example 1 with ArchiveService

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

the class OpenshiftBuildServiceTest method init.

@Before
public void init() throws Exception {
    final File dockerFile = new File(baseDir, "Docker.tar");
    dockerFile.getParentFile().mkdirs();
    dockerFile.createNewFile();
    imageStreamFile.delete();
    new Expectations() {

        {
            dockerServiceHub.getArchiveService();
            result = archiveService;
            archiveService.createDockerBuildArchive(withAny(ImageConfiguration.class.cast(null)), withAny(MojoParameters.class.cast(null)));
            result = dockerFile;
            minTimes = 0;
            project.getArtifact();
            result = "myapp";
            minTimes = 0;
            dockerMojoParameters.getProject();
            result = project;
            minTimes = 0;
        }
    };
    image = new ImageConfiguration.Builder().name(projectName).buildConfig(new BuildImageConfiguration.Builder().from(projectName).build()).build();
    defaultConfig = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-s2i-suffix2").openshiftBuildStrategy(OpenShiftBuildStrategy.s2i).dockerMojoParameters(dockerMojoParameters);
}
Also used : Expectations(mockit.Expectations) BuildService(io.fabric8.maven.core.service.BuildService) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Before(org.junit.Before)

Example 2 with ArchiveService

use of io.fabric8.maven.docker.service.ArchiveService 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);
        }
    }
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration)

Example 3 with ArchiveService

use of io.fabric8.maven.docker.service.ArchiveService 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);
    }
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration) ContainerDescriptor(io.fabric8.maven.docker.service.RunService.ContainerDescriptor)

Example 4 with ArchiveService

use of io.fabric8.maven.docker.service.ArchiveService 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);
    }
}
Also used : DockerAccess(io.fabric8.maven.docker.access.DockerAccess) RunService(io.fabric8.maven.docker.service.RunService) GavLabel(io.fabric8.maven.docker.util.GavLabel) ArchiveService(io.fabric8.maven.docker.service.ArchiveService) QueryService(io.fabric8.maven.docker.service.QueryService) RegistryService(io.fabric8.maven.docker.service.RegistryService)

Example 5 with ArchiveService

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

the class CopyMojo method copyFromExistingContainers.

private void copyFromExistingContainers(DockerAccess dockerAccess, ArchiveService archiveService, QueryService queryService) 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;
        }
        Collection<Container> containers = getContainersForImage(queryService, imageConfiguration);
        if (containers.isEmpty()) {
            log.warn("Found no containers of %s image", imageName);
            continue;
        }
        if (containers.size() > 1) {
            log.warn("Found more than one container of %s image", imageName);
        }
        for (Container container : containers) {
            String containerId = container.getId();
            log.debug("Found %s container of %s image", containerId, imageName);
            copy(dockerAccess, archiveService, containerId, imageName, copyConfiguration);
        }
    }
}
Also used : Container(io.fabric8.maven.docker.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) CopyConfiguration(io.fabric8.maven.docker.config.CopyConfiguration)

Aggregations

CopyConfiguration (io.fabric8.maven.docker.config.CopyConfiguration)4 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)3 File (java.io.File)2 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 BuildService (io.fabric8.maven.core.service.BuildService)1 DockerAccess (io.fabric8.maven.docker.access.DockerAccess)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1 Entry (io.fabric8.maven.docker.config.CopyConfiguration.Entry)1 Container (io.fabric8.maven.docker.model.Container)1 ArchiveService (io.fabric8.maven.docker.service.ArchiveService)1 QueryService (io.fabric8.maven.docker.service.QueryService)1 RegistryService (io.fabric8.maven.docker.service.RegistryService)1 RunService (io.fabric8.maven.docker.service.RunService)1 ContainerDescriptor (io.fabric8.maven.docker.service.RunService.ContainerDescriptor)1 GavLabel (io.fabric8.maven.docker.util.GavLabel)1 BuildBuilder (io.fabric8.openshift.api.model.BuildBuilder)1 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)1 ImageStreamBuilder (io.fabric8.openshift.api.model.ImageStreamBuilder)1 ImageStreamStatusBuilder (io.fabric8.openshift.api.model.ImageStreamStatusBuilder)1 NamedTagEventListBuilder (io.fabric8.openshift.api.model.NamedTagEventListBuilder)1